Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/dmux3to8.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                               dmux3to8
00003                              ----------
00004     begin                : December 2008
00005     copyright            : (C) 2008 by Mike Brinson
00006     email                : mbrin72043@yahoo.co.uk
00007  ***************************************************************************/
00008 
00009 /*
00010  * dmux3to8.cpp - device implementations for dmux3to8 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 "dmux3to8.h"
00019 #include "node.h"
00020 #include "misc.h"
00021 
00022 
00023 dmux3to8::dmux3to8()
00024 {
00025   Type = isComponent; // Analogue and digital component.
00026   Description = QObject::tr ("3to8 demultiplexer verilog device");
00027 
00028   Props.append (new Property ("TR", "6", false,
00029     QObject::tr ("transfer function high scaling factor")));
00030   Props.append (new Property ("Delay", "1 ns", false,
00031     QObject::tr ("output delay")
00032     +" ("+QObject::tr ("s")+")"));
00033 
00034   createSymbol ();
00035   tx = x1 + 19;
00036   ty = y2 + 4;
00037   Model = "dmux3to8";
00038   Name  = "Y";
00039 }
00040 
00041 Component * dmux3to8::newOne()
00042 {
00043   dmux3to8 * p = new dmux3to8();
00044   p->Props.getFirst()->Value = Props.getFirst()->Value; 
00045   p->recreate(0); 
00046   return p;
00047 }
00048 
00049 Element * dmux3to8::info(QString& Name, char * &BitmapFile, bool getNewOne)
00050 {
00051   Name = QObject::tr("3to8 Demux");
00052   BitmapFile = (char *) "dmux3to8";
00053 
00054   if(getNewOne) return new dmux3to8();
00055   return 0;
00056 }
00057 
00058 void dmux3to8::createSymbol()
00059 {
00060   Lines.append(new Line(-30, -90, 30,-90,QPen(Qt::darkBlue,2)));
00061   Lines.append(new Line( 30, -90, 30, 100,QPen(Qt::darkBlue,2)));
00062   Lines.append(new Line( 30,  100,-30, 100,QPen(Qt::darkBlue,2)));
00063   Lines.append(new Line(-30,  100,-30, -90,QPen(Qt::darkBlue,2)));
00064 
00065   Lines.append(new Line(-50,-50,-40,-50,QPen(Qt::darkBlue,2)));  // EN
00066   Lines.append(new Line(-50,-30,-30,-30,QPen(Qt::darkBlue,2)));  // A
00067   Lines.append(new Line(-50,-10,-30,-10,QPen(Qt::darkBlue,2)));  // B
00068   Lines.append(new Line(-50, 10,-30, 10,QPen(Qt::darkBlue,2)));  // C
00069 
00070   Lines.append(new Line( 30, 90, 50, 90,QPen(Qt::darkBlue,2)));  // Y7
00071   Lines.append(new Line( 30, 70, 50, 70,QPen(Qt::darkBlue,2)));  // Y6
00072   Lines.append(new Line( 30, 50, 50, 50,QPen(Qt::darkBlue,2)));  // Y5
00073   Lines.append(new Line( 30, 30, 50, 30,QPen(Qt::darkBlue,2)));  // Y4
00074   Lines.append(new Line( 30, 10, 50, 10,QPen(Qt::darkBlue,2)));  // Y3
00075   Lines.append(new Line( 30,-10, 50,-10,QPen(Qt::darkBlue,2)));  // Y2
00076   Lines.append(new Line( 30,-30, 50,-30,QPen(Qt::darkBlue,2)));  // Y1
00077   Lines.append(new Line( 30,-50, 50,-50,QPen(Qt::darkBlue,2)));  // Y0
00078 
00079   Arcs.append(new Arc( -40, -55, 10, 10, 0, 16*360, QPen(Qt::darkBlue,2)));
00080  
00081   Texts.append(new Text(-25,-85, "DMUX", Qt::darkBlue, 12.0));
00082 
00083   Texts.append(new Text(-25,-63, "En", Qt::darkBlue, 12.0));
00084   Texts.append(new Text(-20,-25, "G", Qt::darkBlue, 12.0));
00085   Texts.append(new Text(-8, -30, "}", Qt::darkBlue, 16.0));
00086   Texts.append(new Text( 2, -32, "0", Qt::darkBlue, 12.0));
00087   Texts.append(new Text( 2, -13, "7", Qt::darkBlue, 12.0));
00088 
00089   Texts.append(new Text(-25,-43, "0", Qt::darkBlue, 12.0));
00090   Texts.append(new Text(-25, -3, "2", Qt::darkBlue, 12.0));
00091 
00092   Texts.append(new Text( 15,-63, "0", Qt::darkBlue, 12.0));
00093   Texts.append(new Text( 15,-43, "1", Qt::darkBlue, 12.0));
00094   Texts.append(new Text( 15,-23, "2", Qt::darkBlue, 12.0));
00095   Texts.append(new Text( 15, -3, "3", Qt::darkBlue, 12.0));
00096   Texts.append(new Text( 15, 17, "4", Qt::darkBlue, 12.0));
00097   Texts.append(new Text( 15, 37, "5", Qt::darkBlue, 12.0));
00098   Texts.append(new Text( 15, 57, "6", Qt::darkBlue, 12.0));
00099   Texts.append(new Text( 15, 77, "7", Qt::darkBlue, 12.0));
00100 
00101   Lines.append(new Line(0, -11, 12, -11, QPen(Qt::darkBlue,2)));
00102 
00103   Ports.append(new Port(-50,-50));  // En
00104   Ports.append(new Port(-50,-30));  // A
00105   Ports.append(new Port(-50,-10));  // B
00106   Ports.append(new Port(-50, 10));  // C
00107   Ports.append(new Port( 50, 90));  // Y7
00108   Ports.append(new Port( 50, 70));  // Y6
00109   Ports.append(new Port( 50, 50));  // Y5
00110   Ports.append(new Port( 50, 30));  // Y4
00111   Ports.append(new Port( 50, 10));  // Y3
00112   Ports.append(new Port( 50,-10));  // Y2
00113   Ports.append(new Port( 50,-30));  // Y1
00114   Ports.append(new Port( 50,-50));  // Y0
00115 
00116   x1 = -50; y1 = -94;
00117   x2 =  50; y2 = 104;
00118 }
00119 
00120 QString dmux3to8::vhdlCode( int )
00121 {
00122   QString s="";
00123 
00124   QString td = Props.at(1)->Value;     // delay time
00125   if(!misc::VHDL_Delay(td, Name)) return td; // time has not VHDL format
00126   td += ";\n";
00127 
00128   QString En = Ports.at(0)->Connection->Name;
00129   QString A  = Ports.at(1)->Connection->Name;
00130   QString B  = Ports.at(2)->Connection->Name;
00131   QString C  = Ports.at(3)->Connection->Name;
00132   QString Y7 = Ports.at(4)->Connection->Name;
00133   QString Y6 = Ports.at(5)->Connection->Name;
00134   QString Y5 = Ports.at(6)->Connection->Name;
00135   QString Y4 = Ports.at(7)->Connection->Name;
00136   QString Y3 = Ports.at(8)->Connection->Name;
00137   QString Y2 = Ports.at(9)->Connection->Name;
00138   QString Y1 = Ports.at(10)->Connection->Name;
00139   QString Y0 = Ports.at(11)->Connection->Name;
00140 
00141   s = "\n  "+Name+":process ("+En+", "+A+", "+B+", "+C+")\n"+
00142       "  begin\n" +
00143       "    "+Y0+" <= "+"(not "+En+") and (not "+C+") and (not "+B+") and (not "+A+")"+td+
00144       "    "+Y1+" <= "+"(not "+En+") and (not "+C+") and (not "+B+") and "+A+td+
00145       "    "+Y2+" <= "+"(not "+En+") and (not "+C+") and "+B+" and (not "+A+")"+td+
00146       "    "+Y3+" <= "+"(not "+En+") and (not "+C+") and "+B+" and "+A+td+
00147       "    "+Y4+" <= "+"(not "+En+") and "+C+" and (not "+B+") and (not "+A+")"+td+
00148       "    "+Y5+" <= "+"(not "+En+") and "+C+" and (not "+B+") and "+A+td+
00149       "    "+Y6+" <= "+"(not "+En+") and "+C+" and "+B+" and (not "+A+")"+td+
00150       "    "+Y7+" <= "+"(not "+En+") and "+C+" and "+B+" and "+A+td+
00151       "  end process;\n";
00152   return s;
00153 }
00154 
00155 QString dmux3to8::verilogCode( int )
00156 {
00157   QString td = Props.at(1)->Value;        // delay time
00158   if(!misc::Verilog_Delay(td, Name)) return td; // time does not have VHDL format
00159   
00160   QString l = "";
00161 
00162   QString En = Ports.at(0)->Connection->Name;
00163   QString A  = Ports.at(1)->Connection->Name;
00164   QString B  = Ports.at(2)->Connection->Name;
00165   QString C  = Ports.at(3)->Connection->Name;
00166   QString Y7 = Ports.at(4)->Connection->Name;
00167   QString Y6 = Ports.at(5)->Connection->Name;
00168   QString Y5 = Ports.at(6)->Connection->Name;
00169   QString Y4 = Ports.at(7)->Connection->Name;
00170   QString Y3 = Ports.at(8)->Connection->Name;
00171   QString Y2 = Ports.at(9)->Connection->Name;
00172   QString Y1 = Ports.at(10)->Connection->Name;
00173   QString Y0 = Ports.at(11)->Connection->Name;
00174 
00175   QString Y7R = "net_reg" + Name + Y7;
00176   QString Y6R = "net_reg" + Name + Y6;
00177   QString Y5R = "net_reg" + Name + Y5;
00178   QString Y4R = "net_reg" + Name + Y4;  
00179   QString Y3R = "net_reg" + Name + Y3;
00180   QString Y2R = "net_reg" + Name + Y2;
00181   QString Y1R = "net_reg" + Name + Y1;
00182   QString Y0R = "net_reg" + Name + Y0;
00183 
00184   l = "\n  // " + Name + " 3to8 demux\n" +
00185       "  assign  " + Y0 + " = " + Y0R + ";\n" +
00186       "  reg     " + Y0R + " = 0;\n" +
00187       "  assign  " + Y1 + " = " + Y1R + ";\n" +
00188       "  reg     " + Y1R + " = 0;\n" +
00189       "  assign  " + Y2 + " = " + Y2R + ";\n" +
00190       "  reg     " + Y2R + " = 0;\n" +
00191       "  assign  " + Y3 + " = " + Y3R + ";\n" +
00192       "  reg     " + Y3R + " = 0;\n" +
00193       "  assign  " + Y4 + " = " + Y4R + ";\n" +
00194       "  reg     " + Y4R + " = 0;\n" +
00195       "  assign  " + Y5 + " = " + Y5R + ";\n" +
00196       "  reg     " + Y5R + " = 0;\n" +
00197       "  assign  " + Y6 + " = " + Y6R + ";\n" +
00198       "  reg     " + Y6R + " = 0;\n" +
00199       "  assign  " + Y7 + " = " + Y7R + ";\n" +
00200       "  reg     " + Y7R + " = 0;\n" +
00201 
00202 
00203       "  always @ ("+En+" or "+A+" or "+B+" or "+C+")\n" +
00204       "  begin\n"+
00205       "    "+Y0R+" <="+td+" (~"+En+") && (~"+C+") && (~"+B+") && (~"+A+");\n"+ 
00206       "    "+Y1R+" <="+td+" (~"+En+") && (~"+C+") && (~"+B+") && "+A+";\n"+
00207       "    "+Y2R+" <="+td+" (~"+En+") && (~"+C+") && "+B+" && (~"+A+");\n"+
00208       "    "+Y3R+" <="+td+" (~"+En+") && (~"+C+") && "+B+" && "+A+";\n"+  
00209       "    "+Y4R+" <="+td+" (~"+En+") && "+C+" && (~"+B+") && (~"+A+");\n"+ 
00210       "    "+Y5R+" <="+td+" (~"+En+") && "+C+" && (~"+B+") && "+A+";\n"+
00211       "    "+Y6R+" <="+td+" (~"+En+") && "+C+" && "+B+" && (~"+A+");\n"+
00212       "    "+Y7R+" <="+td+" (~"+En+") && "+C+" && "+B+" && "+A+";\n"+
00213       "  end\n";
00214 
00215   return l;
00216 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines