Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/digi_source.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                                digi_source.cpp
00003                               -----------------
00004     begin                : Oct 3 2005
00005     copyright            : (C) 2005 by Michael Margraf
00006     email                : michael.margraf@alumni.tu-berlin.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 #include "digi_source.h"
00018 #include "node.h"
00019 #include "misc.h"
00020 
00021 
00022 Digi_Source::Digi_Source()
00023 {
00024   Type = isComponent;   // both analog and digital
00025   Description = QObject::tr("digital source");
00026 
00027   Lines.append(new Line(-10,  0,  0,  0,QPen(Qt::darkGreen,2)));
00028   Lines.append(new Line(-20,-10,-10,  0,QPen(Qt::darkGreen,2)));
00029   Lines.append(new Line(-20, 10,-10,  0,QPen(Qt::darkGreen,2)));
00030   Lines.append(new Line(-35,-10,-20,-10,QPen(Qt::darkGreen,2)));
00031   Lines.append(new Line(-35, 10,-20, 10,QPen(Qt::darkGreen,2)));
00032   Lines.append(new Line(-35,-10,-35, 10,QPen(Qt::darkGreen,2)));
00033 
00034   Lines.append(new Line(-32, 5,-28, 5,QPen(Qt::darkGreen,2)));
00035   Lines.append(new Line(-28,-5,-24,-5,QPen(Qt::darkGreen,2)));
00036   Lines.append(new Line(-24, 5,-20, 5,QPen(Qt::darkGreen,2)));
00037   Lines.append(new Line(-28,-5,-28, 5,QPen(Qt::darkGreen,2)));
00038   Lines.append(new Line(-24,-5,-24, 5,QPen(Qt::darkGreen,2)));
00039 
00040   Ports.append(new Port(  0,  0));
00041 
00042   x1 = -39; y1 = -14;
00043   x2 =   0; y2 =  14;
00044 
00045   tx = x1+4;
00046   ty = y2+2;
00047   Model = "DigiSource";
00048   Name  = "S";
00049 
00050   // This property must stay in this order !
00051   Props.append(new Property("Num", "1", true,
00052     QObject::tr("number of the port")));
00053   Props.append(new Property("init", "low", false,
00054     QObject::tr("initial output value")+" [low, high]"));
00055   Props.append(new Property("times", "1ns; 1ns", false,
00056     QObject::tr("list of times for changing output value")));
00057   Props.append(new Property("V", "1 V", false,
00058     QObject::tr("voltage of high level")));
00059 }
00060 
00061 // -------------------------------------------------------
00062 Digi_Source::~Digi_Source()
00063 {
00064 }
00065 
00066 // -------------------------------------------------------
00067 Component* Digi_Source::newOne()
00068 {
00069   return new Digi_Source();
00070 }
00071 
00072 // -------------------------------------------------------
00073 Element* Digi_Source::info(QString& Name, char* &BitmapFile, bool getNewOne)
00074 {
00075   Name = QObject::tr("digital source");
00076   BitmapFile = (char *) "digi_source";
00077 
00078   if(getNewOne)  return new Digi_Source();
00079   return 0;
00080 }
00081 
00082 // -------------------------------------------------------
00083 QString Digi_Source::netlist()
00084 {
00085   QString s = Model+":"+Name;
00086 
00087   // output node names
00088   s += " "+Ports.first()->Connection->Name;
00089   
00090   // output all properties
00091   Props.first();   // first property not needed
00092   Property *pp = Props.next();
00093   s += " "+pp->Name+"=\""+pp->Value+"\"";
00094   pp = Props.next();
00095   s += " "+pp->Name+"=\"["+pp->Value+"]\"";
00096   pp = Props.next();
00097   s += " "+pp->Name+"=\""+pp->Value+"\"\n";
00098 
00099   return s;
00100 }
00101 
00102 // -------------------------------------------------------
00103 QString Digi_Source::vhdlCode(int NumPorts)
00104 {
00105   QString s, t;
00106   QString Out("    " + Ports.first()->Connection->Name + " <= '");
00107 
00108   s  = "\n  " + Name + ":process\n  begin\n";
00109 
00110   int z = 0;
00111   char State;
00112   if(NumPorts <= 0) {  // time table simulation ?
00113     if(Props.at(0)->Value == "low")
00114       State = '0';
00115     else
00116       State = '1';
00117 
00118     t = Props.at(2)->Value.section(';',z,z).trimmed();
00119     while(!t.isEmpty()) {
00120       s += Out + State + "';";    // next value for signal
00121 
00122       if(!misc::VHDL_Delay(t, Name))
00123         return t;    // time has not VHDL format
00124 
00125       s += t.replace("after","wait for") + ";\n";
00126       State ^= 1;
00127       z++;
00128       t = Props.at(2)->Value.section(';',z,z).trimmed();
00129     }
00130   }
00131   else {  // truth table simulation
00132     State = '0';
00133     int Num = Props.at(0)->Value.toInt() - 1;
00134     
00135     s += Out + State + "';";    // first value for signal
00136     s += "  wait for "+QString::number(1 << Num)+" ns;\n";
00137     State ^= 1;
00138     s += Out + State + "';";    // next value for signal
00139     s += "  wait for "+QString::number(1 << Num)+" ns;\n";
00140   }
00141 
00142   s += "  end process;\n";
00143   return s;
00144 }
00145 
00146 // -------------------------------------------------------
00147 QString Digi_Source::verilogCode(int NumPorts)
00148 {
00149   QString s, t, n, r;
00150 
00151   n = Ports.first()->Connection->Name;
00152   r = "net_src" + Name + n;
00153   s = "\n  // " + Name + " digital source\n";
00154   s += "  assign " + n + " = " + r + ";\n";
00155   s += "  reg    " + r + ";\n";
00156 
00157   int z = 0;
00158   char State;
00159   if(NumPorts <= 0) {  // time table simulation ?
00160     if(Props.at(1)->Value == "low")
00161       State = '0';
00162     else
00163       State = '1';
00164     s += "  always begin\n";
00165 
00166     t = Props.next()->Value.section(';',z,z).trimmed();
00167     while(!t.isEmpty()) {
00168       if(!misc::Verilog_Delay(t, Name))
00169         return t;    // time has not VHDL format
00170       s += "    " + r + " = " + State + ";\n";
00171       s += "   " + t + ";\n";
00172       State ^= 1;
00173       z++;
00174       t = Props.current()->Value.section(';',z,z).trimmed();
00175     }
00176   }
00177   else {  // truth table simulation
00178     int Num = Props.getFirst()->Value.toInt() - 1;    
00179     s += "  always begin\n";
00180     s += "    " + r + " = 0;\n";
00181     s += "    #"+ QString::number(1 << Num) + ";\n";
00182     s += "    " + r + " = !" + r + ";\n";
00183     s += "    #"+ QString::number(1 << Num) + ";\n";
00184   }
00185 
00186   s += "  end\n";
00187   return s;
00188 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines