Qucs-GUI
0.0.19
|
00001 /*************************************************************************** 00002 d_flipflop.cpp 00003 ---------------- 00004 begin : Fri Jan 06 2006 00005 copyright : (C) 2006 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 "d_flipflop.h" 00018 #include "node.h" 00019 #include "misc.h" 00020 00021 D_FlipFlop::D_FlipFlop() 00022 { 00023 Type = isDigitalComponent; 00024 Description = QObject::tr("D flip flop with asynchron reset"); 00025 00026 Props.append(new Property("t", "0", false, QObject::tr("delay time"))); 00027 00028 Lines.append(new Line(-20,-20, 20,-20,QPen(Qt::darkBlue,2))); 00029 Lines.append(new Line(-20, 20, 20, 20,QPen(Qt::darkBlue,2))); 00030 Lines.append(new Line(-20,-20,-20, 20,QPen(Qt::darkBlue,2))); 00031 Lines.append(new Line( 20,-20, 20, 20,QPen(Qt::darkBlue,2))); 00032 00033 Lines.append(new Line(-30,-10,-20,-10,QPen(Qt::darkBlue,2))); 00034 Lines.append(new Line(-30, 10,-20, 10,QPen(Qt::darkBlue,2))); 00035 Lines.append(new Line( 30,-10, 20,-10,QPen(Qt::darkBlue,2))); 00036 Lines.append(new Line( 0, 20, 0, 30,QPen(Qt::darkBlue,2))); 00037 00038 Texts.append(new Text(-18,-21, "D", Qt::darkBlue, 12.0)); 00039 Texts.append(new Text( 6,-21, "Q", Qt::darkBlue, 12.0)); 00040 Texts.append(new Text( -4, 4, "R", Qt::darkBlue, 9.0)); 00041 Lines.append(new Line(-20, 6,-12, 10,QPen(Qt::darkBlue,0))); 00042 Lines.append(new Line(-20, 14,-12, 10,QPen(Qt::darkBlue,0))); 00043 00044 Ports.append(new Port(-30,-10)); // D 00045 Ports.append(new Port(-30, 10)); // Clock 00046 Ports.append(new Port( 30,-10)); // Q 00047 Ports.append(new Port( 0, 30)); // Reset 00048 00049 x1 = -30; y1 = -24; 00050 x2 = 30; y2 = 30; 00051 tx = x1+4; 00052 ty = y2+4; 00053 Model = "DFF"; 00054 Name = "Y"; 00055 } 00056 00057 // ------------------------------------------------------- 00058 QString D_FlipFlop::vhdlCode(int NumPorts) 00059 { 00060 QString s = ""; 00061 if(NumPorts <= 0) { // no truth table simulation ? 00062 QString td = Props.at(0)->Value; // delay time 00063 if(!misc::VHDL_Delay(td, Name)) return td; // time has not VHDL format 00064 s += td; 00065 } 00066 s += ";\n"; 00067 00068 s = " " + Name + " : process (" + 00069 Ports.at(0)->Connection->Name + ", " + 00070 Ports.at(1)->Connection->Name + ")\n begin\n if (" + 00071 Ports.at(3)->Connection->Name + "='1') then " + 00072 Ports.at(2)->Connection->Name + " <= '0'" + s +" elsif (" + 00073 Ports.at(1)->Connection->Name + "='1' and " + 00074 Ports.at(1)->Connection->Name + "'event) then\n " + 00075 Ports.at(2)->Connection->Name + " <= " + 00076 Ports.at(0)->Connection->Name + s + " end if;\n end process;\n\n"; 00077 return s; 00078 } 00079 00080 // ------------------------------------------------------- 00081 QString D_FlipFlop::verilogCode(int NumPorts) 00082 { 00083 QString t = ""; 00084 if(NumPorts <= 0) { // no truth table simulation ? 00085 QString td = Props.at(0)->Value; // delay time 00086 if(!misc::Verilog_Delay(td, Name)) return td; // time has not VHDL format 00087 if(!td.isEmpty()) t = " " + td + ";\n"; 00088 } 00089 00090 QString s = ""; 00091 QString q = Ports.at(2)->Connection->Name; 00092 QString d = Ports.at(0)->Connection->Name; 00093 QString r = Ports.at(3)->Connection->Name; 00094 QString c = Ports.at(1)->Connection->Name; 00095 QString v = "net_reg" + Name + q; 00096 00097 s = "\n // " + Name + " D-flipflop\n" + 00098 " assign " + q + " = " + v + ";\n" + 00099 " reg " + v + " = 0;\n" + 00100 " always @ (" + c + " or " + r + ") begin\n" + t + 00101 " if (" + r + ") " + v + " <= 0;\n" + 00102 " else if (~" + r + " && " + c + ") " + v + " <= " + d + ";\n" + 00103 " end\n\n"; 00104 return s; 00105 } 00106 00107 // ------------------------------------------------------- 00108 Component* D_FlipFlop::newOne() 00109 { 00110 return new D_FlipFlop(); 00111 } 00112 00113 // ------------------------------------------------------- 00114 Element* D_FlipFlop::info(QString& Name, char* &BitmapFile, bool getNewOne) 00115 { 00116 Name = QObject::tr("D-FlipFlop"); 00117 BitmapFile = (char *) "dflipflop"; 00118 00119 if(getNewOne) return new D_FlipFlop(); 00120 return 0; 00121 }