Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/dmux2to4.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                               dmux2to4
00003                              ----------
00004     begin                : December 2008
00005     copyright            : (C) 2008 by Mike Brinson
00006     email                : mbrin72043@yahoo.co.uk
00007  ***************************************************************************/
00008 
00009 /*
00010  * dmux2to4.cpp - device implementations for dmux2to4 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 "dmux2to4.h"
00019 #include "node.h"
00020 #include "misc.h"
00021 
00022 dmux2to4::dmux2to4()
00023 {
00024   Type = isComponent; // Analogue and digital component.
00025   Description = QObject::tr ("2to4 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 = "dmux2to4";
00037   Name  = "Y";
00038 }
00039 
00040 Component * dmux2to4::newOne()
00041 {
00042   dmux2to4 * p = new dmux2to4();
00043   p->Props.getFirst()->Value = Props.getFirst()->Value; 
00044   p->recreate(0); 
00045   return p;
00046 }
00047 
00048 Element * dmux2to4::info(QString& Name, char * &BitmapFile, bool getNewOne)
00049 {
00050   Name = QObject::tr("2to4 Demux");
00051   BitmapFile = (char *) "dmux2to4";
00052 
00053   if(getNewOne) return new dmux2to4();
00054   return 0;
00055 }
00056 
00057 void dmux2to4::createSymbol()
00058 {
00059   Lines.append(new Line(-30, -90, 30,-90,QPen(Qt::darkBlue,2)));
00060   Lines.append(new Line( 30, -90, 30, 20,QPen(Qt::darkBlue,2)));
00061   Lines.append(new Line( 30,  20,-30, 20,QPen(Qt::darkBlue,2)));
00062   Lines.append(new Line(-30,  20,-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( 30, 10, 50, 10,QPen(Qt::darkBlue,2)));  // Y3
00068   Lines.append(new Line( 30,-10, 50,-10,QPen(Qt::darkBlue,2)));  // Y2
00069   Lines.append(new Line( 30,-30, 50,-30,QPen(Qt::darkBlue,2)));  // Y1
00070   Lines.append(new Line( 30,-50, 50,-50,QPen(Qt::darkBlue,2)));  // Y0
00071 
00072   Arcs.append(new Arc( -40, -55, 10, 10, 0, 16*360, QPen(Qt::darkBlue,2)));
00073  
00074   Texts.append(new Text(-25,-85, "DMUX", Qt::darkBlue, 12.0));
00075 
00076   Texts.append(new Text(-28,-63, "En",Qt::darkBlue, 12.0));
00077   Texts.append(new Text(-20,-33, "G", Qt::darkBlue, 12.0));
00078   Texts.append(new Text(-8, -38, "}", Qt::darkBlue, 16.0));
00079   Texts.append(new Text( 2, -40, "0", Qt::darkBlue, 12.0));
00080   Texts.append(new Text( 2, -20, "3", Qt::darkBlue, 12.0));
00081 
00082   Texts.append(new Text(-28,-43, "0", Qt::darkBlue, 12.0));
00083   Texts.append(new Text(-28,-23, "1", Qt::darkBlue, 12.0));
00084 
00085   Texts.append(new Text( 15,-63, "0", Qt::darkBlue, 12.0));
00086   Texts.append(new Text( 15,-43, "1", Qt::darkBlue, 12.0));
00087   Texts.append(new Text( 15,-23, "2", Qt::darkBlue, 12.0));
00088   Texts.append(new Text( 15, -3, "3", Qt::darkBlue, 12.0));
00089 
00090   Lines.append(new Line(0, -18, 12, -18, QPen(Qt::darkBlue,2)));
00091 
00092   Ports.append(new Port(-50,-50));  // En
00093   Ports.append(new Port(-50,-30));  // A
00094   Ports.append(new Port(-50,-10));  // B
00095   Ports.append(new Port( 50, 10));  // Y3
00096   Ports.append(new Port( 50,-10));  // Y2
00097   Ports.append(new Port( 50,-30));  // Y1
00098   Ports.append(new Port( 50,-50));  // Y0
00099 
00100   x1 = -50; y1 = -94;
00101   x2 =  50; y2 =  24;
00102 }
00103 
00104 QString dmux2to4::vhdlCode( int )
00105 {
00106   QString s="";
00107 
00108   QString td = Props.at(1)->Value;     // delay time
00109   if(!misc::VHDL_Delay(td, Name)) return td; // time has not VHDL format
00110   td += ";\n";
00111 
00112   QString En = Ports.at(0)->Connection->Name;
00113   QString A  = Ports.at(1)->Connection->Name;
00114   QString B  = Ports.at(2)->Connection->Name;
00115   QString Y3 = Ports.at(3)->Connection->Name;
00116   QString Y2 = Ports.at(4)->Connection->Name;
00117   QString Y1 = Ports.at(5)->Connection->Name;
00118   QString Y0 = Ports.at(6)->Connection->Name;
00119 
00120   s = "\n  "+Name+":process ("+En+", "+A+", "+B+")\n"+
00121       "  begin\n" +
00122       "    "+Y0+" <= "+"(not "+En+") and (not "+B+") and (not "+A+")"+td+ 
00123       "    "+Y1+" <= "+"(not "+En+") and (not "+B+") and "+A+td+
00124       "    "+Y2+" <= "+"(not "+En+") and "+B+" and (not "+A+")"+td+
00125       "    "+Y3+" <= "+"(not "+En+") and "+B+" and "+A+td+  
00126       "  end process;\n" ;
00127   return s;
00128 }
00129 
00130 QString dmux2to4::verilogCode( int )
00131 {
00132   QString td = Props.at(1)->Value;        // delay time
00133   if(!misc::Verilog_Delay(td, Name)) return td; // time does not have VHDL format
00134 
00135   QString l = "";
00136 
00137   QString En = Ports.at(0)->Connection->Name;
00138   QString A  = Ports.at(1)->Connection->Name;
00139   QString B  = Ports.at(2)->Connection->Name;
00140   QString Y3 = Ports.at(3)->Connection->Name;
00141   QString Y2 = Ports.at(4)->Connection->Name;
00142   QString Y1 = Ports.at(5)->Connection->Name;
00143   QString Y0 = Ports.at(6)->Connection->Name;
00144 
00145   QString Y3R = "net_reg" + Name + Y3;
00146   QString Y2R = "net_reg" + Name + Y2;
00147   QString Y1R = "net_reg" + Name + Y1;
00148   QString Y0R = "net_reg" + Name + Y0;
00149   
00150   l = "\n  // " + Name + " 2to4 demux\n" +
00151       "  assign  " + Y0 + " = " + Y0R + ";\n" +
00152       "  reg     " + Y0R + " = 0;\n" +
00153       "  assign  " + Y1 + " = " + Y1R + ";\n" +
00154       "  reg     " + Y1R + " = 0;\n" +
00155       "  assign  " + Y2 + " = " + Y2R + ";\n" +
00156       "  reg     " + Y2R + " = 0;\n" +
00157       "  assign  " + Y3 + " = " + Y3R + ";\n" +
00158       "  reg     " + Y3R + " = 0;\n" +
00159 
00160       "  always @ ("+En+" or "+A+" or "+B+")\n" +
00161       "  begin\n"+
00162       "    "+Y0R+" <="+td+" (~"+En+") && (~"+B+") && (~"+A+")"+";\n" +
00163       "    "+Y1R+" <="+td+" (~"+En+") && (~"+B+") && ("+A+")"+";\n" +
00164       "    "+Y2R+" <="+td+" (~"+En+") && ("+B+") && (~"+A+")"+";\n" +
00165       "    "+Y3R+" <="+td+" (~"+En+") && ("+B+") && ("+A+")"+";\n" +
00166       "  end\n" ;
00167 
00168   return l;
00169 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines