Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/dmux4to16.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                               dmux4to16
00003                              -----------
00004     begin                : December 2008
00005     copyright            : (C) 2008 by Mike Brinson
00006     email                : mbrin72043@yahoo.co.uk
00007  ***************************************************************************/
00008 
00009 /*
00010  * dmux4to16.cpp - device implementations for dmux4to16 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 "dmux4to16.h"
00019 #include "node.h"
00020 #include "misc.h"
00021 
00022 dmux4to16::dmux4to16()
00023 {
00024   Type = isComponent; // Analogue and digital component.
00025   Description = QObject::tr ("4to16 demultiplexer 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 = "dmux4to16";
00037   Name  = "Y";
00038 }
00039 
00040 Component * dmux4to16::newOne()
00041 {
00042   dmux4to16 * p = new dmux4to16();
00043   p->Props.getFirst()->Value = Props.getFirst()->Value; 
00044   p->recreate(0); 
00045   return p;
00046 }
00047 
00048 Element * dmux4to16::info(QString& Name, char * &BitmapFile, bool getNewOne)
00049 {
00050   Name = QObject::tr("4to16 Demux");
00051   BitmapFile = (char *) "dmux4to16";
00052 
00053   if(getNewOne) return new dmux4to16();
00054   return 0;
00055 }
00056 
00057 void dmux4to16::createSymbol()
00058 {
00059   Lines.append(new Line(-30, -90, 30,-90,QPen(Qt::darkBlue,2)));
00060   Lines.append(new Line( 30, -90, 30, 110,QPen(Qt::darkBlue,2)));
00061   Lines.append(new Line( 30,  110,-30, 110,QPen(Qt::darkBlue,2)));
00062   Lines.append(new Line(-30,  110,-30, -90,QPen(Qt::darkBlue,2)));
00063 
00064   Lines.append(new Line(-50,-50,-40,-50,QPen(Qt::darkBlue,2)));  // EN
00065   Lines.append(new Line(-50,-30,-30,-30,QPen(Qt::darkBlue,2)));  // A
00066   Lines.append(new Line(-50,-10,-30,-10,QPen(Qt::darkBlue,2)));  // B
00067   Lines.append(new Line(-50, 10,-30, 10,QPen(Qt::darkBlue,2)));  // C
00068   Lines.append(new Line(-50, 30,-30, 30,QPen(Qt::darkBlue,2)));  // D
00069 
00070   Lines.append(new Line( 30, 100, 50,100,QPen(Qt::darkBlue,2)));  // Y15
00071   Lines.append(new Line( 30,  90, 50, 90,QPen(Qt::darkBlue,2)));  // Y14
00072   Lines.append(new Line( 30,  80, 50, 80,QPen(Qt::darkBlue,2)));  // Y13
00073   Lines.append(new Line( 30,  70, 50, 70,QPen(Qt::darkBlue,2)));  // Y12
00074   Lines.append(new Line( 30,  60, 50, 60,QPen(Qt::darkBlue,2)));  // Y11
00075   Lines.append(new Line( 30,  50, 50, 50,QPen(Qt::darkBlue,2)));  // Y10
00076   Lines.append(new Line( 30,  40, 50, 40,QPen(Qt::darkBlue,2)));  // Y9
00077   Lines.append(new Line( 30,  30, 50, 30,QPen(Qt::darkBlue,2)));  // Y8
00078   Lines.append(new Line( 30,  20, 50, 20,QPen(Qt::darkBlue,2)));  // Y7
00079   Lines.append(new Line( 30,  10, 50, 10,QPen(Qt::darkBlue,2)));  // Y6
00080   Lines.append(new Line( 30,   0, 50,  0,QPen(Qt::darkBlue,2)));  // Y5
00081   Lines.append(new Line( 30, -10, 50,-10,QPen(Qt::darkBlue,2)));  // Y4
00082   Lines.append(new Line( 30, -20, 50,-20,QPen(Qt::darkBlue,2)));  // Y3
00083   Lines.append(new Line( 30, -30, 50,-30,QPen(Qt::darkBlue,2)));  // Y2
00084   Lines.append(new Line( 30, -40, 50,-40,QPen(Qt::darkBlue,2)));  // Y1
00085   Lines.append(new Line( 30, -50, 50,-50,QPen(Qt::darkBlue,2)));  // Y0
00086 
00087   Arcs.append(new Arc( -40, -55, 10, 10, 0, 16*360, QPen(Qt::darkBlue,2)));
00088  
00089   Texts.append(new Text(-25,-85, "DMUX", Qt::darkBlue, 12.0));
00090 
00091   Texts.append(new Text(-25,-63, "En", Qt::darkBlue, 12.0));
00092   Texts.append(new Text(-26,-15, "G", Qt::darkBlue, 12.0));
00093   Texts.append(new Text(-13,-20, "}", Qt::darkBlue, 16.0));
00094   Texts.append(new Text( -5,-20, "0", Qt::darkBlue, 12.0));
00095   Texts.append(new Text( -8,  0, "15", Qt::darkBlue, 12.0));
00096 
00097   Texts.append(new Text(-25,-43, "0", Qt::darkBlue, 12.0));
00098   Texts.append(new Text(-25, 17, "3", Qt::darkBlue, 12.0));
00099 
00100   Texts.append(new Text( 15,-59, "0", Qt::darkBlue, 9.0));
00101   Texts.append(new Text( 15,-49, "1", Qt::darkBlue, 9.0));
00102   Texts.append(new Text( 15,-39, "2", Qt::darkBlue, 9.0));
00103   Texts.append(new Text( 15,-29, "3", Qt::darkBlue, 9.0));
00104   Texts.append(new Text( 15,-19, "4", Qt::darkBlue, 9.0));
00105   Texts.append(new Text( 15, -9, "5", Qt::darkBlue, 9.0));
00106   Texts.append(new Text( 15,  1, "6", Qt::darkBlue, 9.0));
00107   Texts.append(new Text( 15, 11, "7", Qt::darkBlue, 9.0));
00108   Texts.append(new Text( 15, 21, "8", Qt::darkBlue, 9.0));
00109   Texts.append(new Text( 15, 31, "9", Qt::darkBlue, 9.0));
00110   Texts.append(new Text(  8, 41, "10", Qt::darkBlue, 9.0));
00111   Texts.append(new Text(  8, 51, "11", Qt::darkBlue, 9.0));
00112   Texts.append(new Text(  8, 61, "12", Qt::darkBlue, 9.0));
00113   Texts.append(new Text(  8, 71, "13", Qt::darkBlue, 9.0));
00114   Texts.append(new Text(  8, 81, "14", Qt::darkBlue, 9.0));
00115   Texts.append(new Text(  8, 91, "15", Qt::darkBlue, 9.0));
00116 
00117   Lines.append(new Line(-6,  2, 9,  2, QPen(Qt::darkBlue,2)));
00118 
00119   Ports.append(new Port(-50,-50));  // En
00120   Ports.append(new Port(-50,-30));  // A
00121   Ports.append(new Port(-50,-10));  // B
00122   Ports.append(new Port(-50, 10));  // C
00123   Ports.append(new Port(-50, 30));  // D
00124   Ports.append(new Port( 50,100));  // Y15
00125   Ports.append(new Port( 50, 90));  // Y14
00126   Ports.append(new Port( 50, 80));  // Y13
00127   Ports.append(new Port( 50, 70));  // Y12
00128   Ports.append(new Port( 50, 60));  // Y11
00129   Ports.append(new Port( 50, 50));  // Y10
00130   Ports.append(new Port( 50, 40));  // Y9
00131   Ports.append(new Port( 50, 30));  // Y8
00132   Ports.append(new Port( 50, 20));  // Y7
00133   Ports.append(new Port( 50, 10));  // Y6
00134   Ports.append(new Port( 50,  0));  // Y5
00135   Ports.append(new Port( 50,-10));  // Y4
00136   Ports.append(new Port( 50,-20));  // Y3
00137   Ports.append(new Port( 50,-30));  // Y2
00138   Ports.append(new Port( 50,-40));  // Y1
00139   Ports.append(new Port( 50,-50));  // Y0
00140 
00141   x1 = -50; y1 = -94;
00142   x2 =  50; y2 = 114;
00143 }
00144 
00145 QString dmux4to16::vhdlCode( int )
00146 {
00147   QString s="";
00148 
00149   QString td = Props.at(1)->Value;     // delay time
00150   if(!misc::VHDL_Delay(td, Name)) return td; // time has not VHDL format
00151   td += ";\n";
00152 
00153   QString En = Ports.at(0)->Connection->Name;
00154   QString A  = Ports.at(1)->Connection->Name;
00155   QString B  = Ports.at(2)->Connection->Name;
00156   QString C  = Ports.at(3)->Connection->Name;
00157   QString D  = Ports.at(4)->Connection->Name;
00158   QString Y15 = Ports.at(5)->Connection->Name;
00159   QString Y14 = Ports.at(6)->Connection->Name;
00160   QString Y13 = Ports.at(7)->Connection->Name;
00161   QString Y12 = Ports.at(8)->Connection->Name;
00162   QString Y11 = Ports.at(9)->Connection->Name;
00163   QString Y10 = Ports.at(10)->Connection->Name;
00164   QString Y9 = Ports.at(11)->Connection->Name;
00165   QString Y8 = Ports.at(12)->Connection->Name;
00166   QString Y7 = Ports.at(13)->Connection->Name;
00167   QString Y6 = Ports.at(14)->Connection->Name;
00168   QString Y5 = Ports.at(15)->Connection->Name;
00169   QString Y4 = Ports.at(16)->Connection->Name;
00170   QString Y3 = Ports.at(17)->Connection->Name;
00171   QString Y2 = Ports.at(18)->Connection->Name;
00172   QString Y1 = Ports.at(19)->Connection->Name;
00173   QString Y0 = Ports.at(20)->Connection->Name;
00174 
00175   s = "\n  "+Name+":process ("+En+", "+A+", "+B+", "+C+", "+D+")\n"+
00176       "  begin\n" +
00177       "    "+Y0+" <= "+"(not "+En+") and (not "+D+") and (not "+C+") and (not "+B+") and (not "+A+")"+td+ 
00178       "    "+Y1+" <= "+"(not "+En+") and (not "+D+") and (not "+C+") and (not "+B+") and "+A+td+
00179       "    "+Y2+" <= "+"(not "+En+") and (not "+D+") and (not "+C+") and "+B+" and (not "+A+")"+td+
00180       "    "+Y3+" <= "+"(not "+En+") and (not "+D+") and (not "+C+") and "+B+" and "+A+td+  
00181       "    "+Y4+" <= "+"(not "+En+") and (not "+D+") and "+C+" and (not "+B+") and (not "+A+")"+td+ 
00182       "    "+Y5+" <= "+"(not "+En+") and (not "+D+") and "+C+" and (not "+B+") and "+A+td+
00183       "    "+Y6+" <= "+"(not "+En+") and (not "+D+") and "+C+" and "+B+" and (not "+A+")"+td+
00184       "    "+Y7+" <= "+"(not "+En+") and (not "+D+") and "+C+" and "+B+" and "+A+td+  
00185       "    "+Y8+" <= "+"(not "+En+") and "+D+" and (not "+C+") and (not "+B+") and (not "+A+")"+td+ 
00186       "    "+Y9+" <= "+"(not "+En+") and "+D+" and (not "+C+") and (not "+B+") and "+A+td+
00187       "    "+Y10+" <= "+"(not "+En+") and "+D+" and (not "+C+") and "+B+" and (not "+A+")"+td+
00188       "    "+Y11+" <= "+"(not "+En+") and "+D+" and (not "+C+") and "+B+" and "+A+td+  
00189       "    "+Y12+" <= "+"(not "+En+") and "+D+" and "+C+" and (not "+B+") and (not "+A+")"+td+ 
00190       "    "+Y13+" <= "+"(not "+En+") and "+D+" and "+C+" and (not "+B+") and "+A+td+
00191       "    "+Y14+" <= "+"(not "+En+") and "+D+" and "+C+" and "+B+" and (not "+A+")"+td+
00192       "    "+Y15+" <= "+"(not "+En+") and "+D+" and "+C+" and "+B+" and "+A+td+
00193          
00194       "  end process;\n";
00195   return s;
00196 }
00197 
00198 QString dmux4to16::verilogCode( int )
00199 {
00200   QString td = Props.at(1)->Value;        // delay time
00201   if(!misc::Verilog_Delay(td, Name)) return td; // time does not have VHDL format
00202   
00203   QString l = "";
00204 
00205   QString En = Ports.at(0)->Connection->Name;
00206   QString A  = Ports.at(1)->Connection->Name;
00207   QString B  = Ports.at(2)->Connection->Name;
00208   QString C  = Ports.at(3)->Connection->Name;
00209   QString D  = Ports.at(4)->Connection->Name;
00210   QString Y15 = Ports.at(5)->Connection->Name;
00211   QString Y14 = Ports.at(6)->Connection->Name;
00212   QString Y13 = Ports.at(7)->Connection->Name;
00213   QString Y12 = Ports.at(8)->Connection->Name;
00214   QString Y11 = Ports.at(9)->Connection->Name;
00215   QString Y10 = Ports.at(10)->Connection->Name;
00216   QString Y9 = Ports.at(11)->Connection->Name;
00217   QString Y8 = Ports.at(12)->Connection->Name;
00218   QString Y7 = Ports.at(13)->Connection->Name;
00219   QString Y6 = Ports.at(14)->Connection->Name;
00220   QString Y5 = Ports.at(15)->Connection->Name;
00221   QString Y4 = Ports.at(16)->Connection->Name;
00222   QString Y3 = Ports.at(17)->Connection->Name;
00223   QString Y2 = Ports.at(18)->Connection->Name;
00224   QString Y1 = Ports.at(19)->Connection->Name;
00225   QString Y0 = Ports.at(20)->Connection->Name;
00226 
00227   QString Y15R = "net_reg" + Name + Y15;
00228   QString Y14R = "net_reg" + Name + Y14;
00229   QString Y13R = "net_reg" + Name + Y13;
00230   QString Y12R = "net_reg" + Name + Y12;  
00231   QString Y11R = "net_reg" + Name + Y11;
00232   QString Y10R = "net_reg" + Name + Y10;
00233   QString Y9R = "net_reg" + Name + Y9;
00234   QString Y8R = "net_reg" + Name + Y8;
00235   QString Y7R = "net_reg" + Name + Y7;
00236   QString Y6R = "net_reg" + Name + Y6;
00237   QString Y5R = "net_reg" + Name + Y5;
00238   QString Y4R = "net_reg" + Name + Y4;  
00239   QString Y3R = "net_reg" + Name + Y3;
00240   QString Y2R = "net_reg" + Name + Y2;
00241   QString Y1R = "net_reg" + Name + Y1;
00242   QString Y0R = "net_reg" + Name + Y0;
00243 
00244   l = "\n  // " + Name + " 4to16 demux\n" +
00245       "  assign  " + Y0 + " = " + Y0R + ";\n" +
00246       "  reg     " + Y0R + " = 0;\n" +
00247       "  assign  " + Y1 + " = " + Y1R + ";\n" +
00248       "  reg     " + Y1R + " = 0;\n" +
00249       "  assign  " + Y2 + " = " + Y2R + ";\n" +
00250       "  reg     " + Y2R + " = 0;\n" +
00251       "  assign  " + Y3 + " = " + Y3R + ";\n" +
00252       "  reg     " + Y3R + " = 0;\n" +
00253       "  assign  " + Y4 + " = " + Y4R + ";\n" +
00254       "  reg     " + Y4R + " = 0;\n" +
00255       "  assign  " + Y5 + " = " + Y5R + ";\n" +
00256       "  reg     " + Y5R + " = 0;\n" +
00257       "  assign  " + Y6 + " = " + Y6R + ";\n" +
00258       "  reg     " + Y6R + " = 0;\n" +
00259       "  assign  " + Y7 + " = " + Y7R + ";\n" +
00260       "  reg     " + Y7R + " = 0;\n" +
00261       "  assign  " + Y8 + " = " + Y8R + ";\n" +
00262       "  reg     " + Y8R + " = 0;\n" +
00263       "  assign  " + Y9 + " = " + Y9R + ";\n" +
00264       "  reg     " + Y9R + " = 0;\n" +
00265       "  assign  " + Y10 + " = " + Y10R + ";\n" +
00266       "  reg     " + Y10R + " = 0;\n" +
00267       "  assign  " + Y11 + " = " + Y11R + ";\n" +
00268       "  reg     " + Y11R + " = 0;\n" +
00269       "  assign  " + Y12 + " = " + Y12R + ";\n" +
00270       "  reg     " + Y12R + " = 0;\n" +
00271       "  assign  " + Y13 + " = " + Y13R + ";\n" +
00272       "  reg     " + Y13R + " = 0;\n" +
00273       "  assign  " + Y14 + " = " + Y14R + ";\n" +
00274       "  reg     " + Y14R + " = 0;\n" +
00275       "  assign  " + Y15 + " = " + Y15R + ";\n" +
00276       "  reg     " + Y15R + " = 0;\n" +
00277 
00278       "  always @ ("+En+" or "+A+" or "+B+" or "+C+" or "+D+")\n" +
00279       "  begin\n"+
00280       "    "+Y0R+" <="+td+" (~"+En+") && (~"+D+") && (~"+C+") && (~"+B+" ) && (~"+A+");\n"+ 
00281       "    "+Y1R+" <="+td+" (~"+En+") && (~"+D+") && (~"+C+") && (~"+B+" ) && "+A+";\n"+
00282       "    "+Y2R+" <="+td+" (~"+En+") && (~"+D+") && (~"+C+") && "+B+" && (~"+A+");\n"+
00283       "    "+Y3R+" <="+td+" (~"+En+") && (~"+D+") && (~"+C+") && "+B+" && "+A+";\n"+  
00284       "    "+Y4R+" <="+td+" (~"+En+") && (~"+D+") && "+C+" && (~"+B+" ) && (~"+A+");\n"+ 
00285       "    "+Y5R+" <="+td+" (~"+En+") && (~"+D+") && "+C+" && (~"+B+" ) && "+A+";\n"+
00286       "    "+Y6R+" <="+td+" (~"+En+") && (~"+D+") && "+C+" && "+B+" && ( ~"+A+");\n"+
00287       "    "+Y7R+" <="+td+" (~"+En+") && (~"+D+") && "+C+" && "+B+" && "+A+";\n"+ 
00288       "    "+Y8R+" <="+td+" (~"+En+") && "+D+" && (~"+C+") && ( ~"+B+") && (~"+A+");\n"+ 
00289       "    "+Y9R+" <="+td+" (~"+En+") && "+D+" && (~"+C+") && ( ~"+B+") && "+A+";\n"+
00290       "    "+Y10R+" <="+td+" (~"+En+") && "+D+" && (~"+C+") && "+B+" && (~"+A+");\n"+
00291       "    "+Y11R+" <="+td+" (~"+En+") && "+D+" && (~"+C+") && "+B+" && "+A+";\n"+  
00292       "    "+Y12R+" <="+td+" (~"+En+") && "+D+" && "+C+" && (~"+B+") && (~"+A+");\n"+ 
00293       "    "+Y13R+" <="+td+" (~"+En+") && "+D+" && "+C+" && (~"+B+") && "+A+";\n"+
00294       "    "+Y14R+" <="+td+" (~"+En+") && "+D+" && "+C+" && "+B+" && (~"+A+");\n"+
00295       "    "+Y15R+" <="+td+" (~"+En+") && "+D+" && "+C+" && "+B+" && "+A+";\n"+ 
00296             
00297       "  end\n";
00298 
00299   return l;
00300 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines