Qucs-GUI
0.0.19
|
00001 /*************************************************************************** 00002 jk_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 <stdlib.h> 00018 00019 #include "jk_flipflop.h" 00020 #include "node.h" 00021 #include "misc.h" 00022 00023 JK_FlipFlop::JK_FlipFlop() 00024 { 00025 Type = isDigitalComponent; 00026 Description = QObject::tr("JK flip flop with asynchron set and reset"); 00027 00028 Props.append(new Property("t", "0", false, QObject::tr("delay time"))); 00029 00030 Lines.append(new Line(-20,-30, 20,-30,QPen(Qt::darkBlue,2))); 00031 Lines.append(new Line(-20, 30, 20, 30,QPen(Qt::darkBlue,2))); 00032 Lines.append(new Line(-20,-30,-20, 30,QPen(Qt::darkBlue,2))); 00033 Lines.append(new Line( 20,-30, 20, 30,QPen(Qt::darkBlue,2))); 00034 00035 Lines.append(new Line(-30,-20,-20,-20,QPen(Qt::darkBlue,2))); 00036 Lines.append(new Line(-30, 20,-20, 20,QPen(Qt::darkBlue,2))); 00037 Lines.append(new Line( 30,-20, 20,-20,QPen(Qt::darkBlue,2))); 00038 Lines.append(new Line( 30, 20, 20, 20,QPen(Qt::darkBlue,2))); 00039 Lines.append(new Line(-30, 0,-20, 0,QPen(Qt::darkBlue,2))); 00040 Lines.append(new Line( 0,-30, 0,-40,QPen(Qt::darkBlue,2))); 00041 Lines.append(new Line( 0, 30, 0, 40,QPen(Qt::darkBlue,2))); 00042 00043 Texts.append(new Text( -4,-29, "S", Qt::darkBlue, 9.0)); 00044 Texts.append(new Text( -4, 14, "R", Qt::darkBlue, 9.0)); 00045 Texts.append(new Text(-18,-31, "J", Qt::darkBlue, 12.0)); 00046 Texts.append(new Text(-18, 8, "K", Qt::darkBlue, 12.0)); 00047 Texts.append(new Text( 6,-31, "Q", Qt::darkBlue, 12.0)); 00048 Texts.append(new Text( 6, 8, "Q", Qt::darkBlue, 12.0)); 00049 Texts.last()->over=true; 00050 Lines.append(new Line(-20, -4,-12, 0,QPen(Qt::darkBlue,0))); 00051 Lines.append(new Line(-20, 4,-12, 0,QPen(Qt::darkBlue,0))); 00052 00053 Ports.append(new Port(-30,-20)); // J 00054 Ports.append(new Port(-30, 20)); // K 00055 Ports.append(new Port( 30,-20)); // Q 00056 Ports.append(new Port( 30, 20)); // nQ 00057 Ports.append(new Port(-30, 0)); // Clock 00058 Ports.append(new Port( 0,-40)); // set 00059 Ports.append(new Port( 0, 40)); // reset 00060 00061 x1 = -30; y1 = -40; 00062 x2 = 30; y2 = 40; 00063 tx = x1+4; 00064 ty = y2+4; 00065 Model = "JKFF"; 00066 Name = "Y"; 00067 } 00068 00069 // ------------------------------------------------------- 00070 QString JK_FlipFlop::vhdlCode(int NumPorts) 00071 { 00072 QString s = ""; 00073 if(NumPorts <= 0) { // no truth table simulation ? 00074 QString td = Props.at(0)->Value; // delay time 00075 if(!misc::VHDL_Delay(td, Name)) return td; // time has not VHDL format 00076 s += td; 00077 } 00078 s += ";\n"; 00079 00080 s = " " + Name + " : process (" + 00081 Ports.at(5)->Connection->Name + ", " + 00082 Ports.at(6)->Connection->Name + ", " + 00083 Ports.at(4)->Connection->Name + ")\n begin\n if (" + 00084 Ports.at(6)->Connection->Name + "='1') then " + 00085 Ports.at(2)->Connection->Name + " <= '0'" + s +" elsif (" + 00086 Ports.at(5)->Connection->Name + "='1') then " + 00087 Ports.at(2)->Connection->Name + " <= '1'" + s +" elsif (" + 00088 Ports.at(4)->Connection->Name + "='1' and " + 00089 Ports.at(4)->Connection->Name + "'event) then\n " + 00090 Ports.at(2)->Connection->Name + " <= (" + 00091 Ports.at(0)->Connection->Name + " and not " + 00092 Ports.at(2)->Connection->Name + ") or (not " + 00093 Ports.at(1)->Connection->Name + " and " + 00094 Ports.at(2)->Connection->Name + ")" + s + 00095 " end if;\n end process;\n " + 00096 Ports.at(3)->Connection->Name + " <= not " + 00097 Ports.at(2)->Connection->Name + ";\n\n"; 00098 return s; 00099 } 00100 00101 // ------------------------------------------------------- 00102 QString JK_FlipFlop::verilogCode(int NumPorts) 00103 { 00104 QString t = ""; 00105 if(NumPorts <= 0) { // no truth table simulation ? 00106 QString td = Props.at(0)->Value; // delay time 00107 if(!misc::Verilog_Delay(td, Name)) return td; // time has not VHDL format 00108 if(!td.isEmpty()) t = " " + td + ";\n"; 00109 } 00110 00111 QString l = ""; 00112 00113 QString s = Ports.at(5)->Connection->Name; 00114 QString r = Ports.at(6)->Connection->Name; 00115 QString j = Ports.at(0)->Connection->Name; 00116 QString k = Ports.at(1)->Connection->Name; 00117 QString q = Ports.at(2)->Connection->Name; 00118 QString b = Ports.at(3)->Connection->Name; 00119 QString c = Ports.at(4)->Connection->Name; 00120 QString v = "net_reg" + Name + q; 00121 00122 l = "\n // " + Name + " JK-flipflop\n" + 00123 " assign " + q + " = " + v + ";\n" + 00124 " assign " + b + " = ~" + q + ";\n" + 00125 " reg " + v + " = 0;\n" + 00126 " always @ (" + c + " or " + r + " or " + s + ") begin\n" + t + 00127 " if (" + r + ") " + v + " <= 0;\n" + 00128 " else if (" + s + ") " + v + " <= 1;\n" + 00129 " else if (" + c + ")\n" + 00130 " " + v + " <= (" + j + " && ~" + q + ") || (~" + 00131 k + " && " + q + ");\n" + 00132 " end\n\n"; 00133 return l; 00134 } 00135 00136 // ------------------------------------------------------- 00137 Component* JK_FlipFlop::newOne() 00138 { 00139 return new JK_FlipFlop(); 00140 } 00141 00142 // ------------------------------------------------------- 00143 Element* JK_FlipFlop::info(QString& Name, char* &BitmapFile, bool getNewOne) 00144 { 00145 Name = QObject::tr("JK-FlipFlop"); 00146 BitmapFile = (char *) "jkflipflop"; 00147 00148 if(getNewOne) return new JK_FlipFlop(); 00149 return 0; 00150 }