Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/mux4to1.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                               mux4to1
00003                              ---------
00004     begin                : December 2008
00005     copyright            : (C) 2008 by Mike Brinson
00006     email                : mbrin72043@yahoo.co.uk
00007  ***************************************************************************/
00008 
00009 /*
00010  * mux4to1.cpp - device implementations for mux4to1 module
00011  *
00012  * This is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 2, or (at your option)
00015  * any later version.
00016  * 
00017  */
00018 #include "mux4to1.h"
00019 #include "node.h"
00020 #include "misc.h"
00021 
00022 mux4to1::mux4to1()
00023 {
00024   Type = isComponent; // Analogue and digital component.
00025   Description = QObject::tr ("4to1 multiplexer verilog device");
00026 
00027   Props.append (new Property ("TR", "6", false,
00028     QObject::tr ("transfer function high scaling factor")));
00029   Props.append (new Property ("Delay", "1 ns", false,
00030     QObject::tr ("output delay")
00031     +" ("+QObject::tr ("s")+")"));
00032  
00033   createSymbol ();
00034   tx = x1 + 19;
00035   ty = y2 + 4;
00036   Model = "mux4to1";
00037   Name  = "Y";
00038 }
00039 
00040 Component * mux4to1::newOne()
00041 {
00042   mux4to1 * p = new mux4to1();
00043   p->Props.getFirst()->Value = Props.getFirst()->Value; 
00044   p->recreate(0); 
00045   return p;
00046 }
00047 
00048 Element * mux4to1::info(QString& Name, char * &BitmapFile, bool getNewOne)
00049 {
00050   Name = QObject::tr("4to1 Mux");
00051   BitmapFile = (char *) "mux4to1";
00052 
00053   if(getNewOne) return new mux4to1();
00054   return 0;
00055 }
00056 
00057 void mux4to1::createSymbol()
00058 {
00059   Lines.append(new Line(-30, -80, 30,-80,QPen(Qt::darkBlue,2)));
00060   Lines.append(new Line( 30, -80, 30, 100,QPen(Qt::darkBlue,2)));
00061   Lines.append(new Line( 30,  100,-30, 100,QPen(Qt::darkBlue,2)));
00062   Lines.append(new Line(-30, 100,-30, -80,QPen(Qt::darkBlue,2)));
00063 
00064   Lines.append(new Line(-50,-40,-40,-40,QPen(Qt::darkBlue,2)));
00065   Lines.append(new Line(-50,-20,-30, -20,QPen(Qt::darkBlue,2)));
00066   Lines.append(new Line(-50, 0, -30, 0,QPen(Qt::darkBlue,2)));
00067   Lines.append(new Line(-50, 30, -30, 30,QPen(Qt::darkBlue,2)));
00068   Lines.append(new Line(-50, 50,-30, 50,QPen(Qt::darkBlue,2)));
00069   Lines.append(new Line(-50, 70, -30, 70,QPen(Qt::darkBlue,2)));
00070   Lines.append(new Line(-50, 90, -30, 90,QPen(Qt::darkBlue,2)));
00071 
00072   Lines.append(new Line( 30, 10, 50, 10,QPen(Qt::darkBlue,2)));
00073 
00074   Arcs.append(new Arc( -40, -45, 10, 10, 0, 16*360, QPen(Qt::darkBlue,2)));
00075  
00076   Texts.append(new Text(-17,-75, "MUX", Qt::darkBlue, 12.0));
00077 
00078   Texts.append(new Text(-25,-53, "En", Qt::darkBlue, 12.0));
00079   Texts.append(new Text(-14,-23, "G", Qt::darkBlue, 12.0));
00080   Texts.append(new Text(-1, -28, "}", Qt::darkBlue, 16.0));
00081   Texts.append(new Text( 12,-30, "0", Qt::darkBlue, 12.0));
00082   Texts.append(new Text( 12,-10, "3", Qt::darkBlue, 12.0));
00083 
00084   Texts.append(new Text(-25,-31, "0", Qt::darkBlue, 12.0));
00085   Texts.append(new Text(-25,-11, "1", Qt::darkBlue, 12.0));
00086 
00087   Texts.append(new Text(-25, 17, "0", Qt::darkBlue, 12.0));
00088   Texts.append(new Text(-25, 37, "1", Qt::darkBlue, 12.0));
00089   Texts.append(new Text(-25, 57, "2", Qt::darkBlue, 12.0));
00090   Texts.append(new Text(-25, 77, "3", Qt::darkBlue, 12.0));
00091 
00092   Lines.append(new Line(11, -8, 23, -8, QPen(Qt::darkBlue,2)));
00093 
00094   Ports.append(new Port(-50,-40));  // En
00095   Ports.append(new Port(-50,-20));  // A
00096   Ports.append(new Port(-50,  0));  // B
00097   Ports.append(new Port(-50, 30));  // D0
00098   Ports.append(new Port(-50, 50));  // D1
00099   Ports.append(new Port(-50, 70));  // D2
00100   Ports.append(new Port(-50, 90));  // D3
00101   Ports.append(new Port( 50, 10));  // Y
00102 
00103   x1 = -50; y1 = -84;
00104   x2 =  50; y2 =  104;
00105 }
00106 
00107 QString mux4to1::vhdlCode( int )
00108 {
00109   QString s="";
00110 
00111   QString td = Props.at(1)->Value;     // delay time
00112   if(!misc::VHDL_Delay(td, Name)) return td; // time has not VHDL format
00113   td += ";\n";
00114 
00115   QString En = Ports.at(0)->Connection->Name;
00116   QString A  = Ports.at(1)->Connection->Name;
00117   QString B  = Ports.at(2)->Connection->Name;
00118   QString D0 = Ports.at(3)->Connection->Name;
00119   QString D1 = Ports.at(4)->Connection->Name;
00120   QString D2 = Ports.at(5)->Connection->Name;
00121   QString D3 = Ports.at(6)->Connection->Name;
00122   QString y  = Ports.at(7)->Connection->Name;
00123 
00124   s = "\n  " + Name + ":process (" + En + ", " +  A + ", " + B + ", " +
00125                               D0 + ", " +  D1 + ", " + D2 + ", " + D3 + ")\n"  +
00126      "  begin\n    " +
00127      y + " <= " +  "(not " + En + ") and ((" + D3 + " and " + B + " and " +  A + ") or\n" + 
00128          "                 (" + D2 + " and " + B + " and not " + A + ") or\n" +
00129          "                 (" + D1 + " and not " + B + " and " + A + ") or\n" +
00130          "                 (" + D0 + " and not " + B + " and not " + A + ")" + ")" + td +
00131      "  end process;\n";
00132   return s;
00133 }
00134 
00135 QString mux4to1::verilogCode( int )
00136 {
00137   QString td = Props.at(1)->Value;        // delay time
00138   if(!misc::Verilog_Delay(td, Name)) return td; // time does not have VHDL format
00139   
00140   QString l = "";
00141 
00142   QString En = Ports.at(0)->Connection->Name;
00143   QString A  = Ports.at(1)->Connection->Name;
00144   QString B  = Ports.at(2)->Connection->Name;
00145   QString D0 = Ports.at(3)->Connection->Name;
00146   QString D1 = Ports.at(4)->Connection->Name;
00147   QString D2 = Ports.at(5)->Connection->Name;
00148   QString D3 = Ports.at(6)->Connection->Name;
00149   QString y  = Ports.at(7)->Connection->Name;
00150 
00151   QString v = "net_reg" + Name + y;
00152   
00153   l = "\n  // " + Name + " 4to1 mux\n" +
00154       "  assign  " + y + " = " + v + ";\n" +
00155       "  reg     " + v + " = 0;\n" +
00156       "  always @ (" + En + " or " + A + " or " + B + " or " 
00157                      + D0 + " or " + D1 +  " or " + D2 + " or " + D0 + ")\n" +
00158       "    " + v + " <=" + td + " (" + D3 + " && " + B + " && " + A  +")" + " ||\n" +
00159       "                         (" + D2 + " && " + B + " && ~"+ A  +")" + " ||\n" +
00160       "                         (" + D1 + " && ~"+ B + " && " + A  +")" + " ||\n" +
00161       "                         (" + D0 + " && ~"+ B + " && ~"+ A  +");\n";
00162 
00163   return l;
00164 }
00165 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines