Qucs-GUI
0.0.19
|
00001 /*************************************************************************** 00002 rs_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 "rs_flipflop.h" 00018 #include "node.h" 00019 #include "misc.h" 00020 00021 RS_FlipFlop::RS_FlipFlop() 00022 { 00023 Type = isDigitalComponent; 00024 Description = QObject::tr("RS flip flop"); 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( 30, 10, 20, 10,QPen(Qt::darkBlue,2))); 00037 00038 Texts.append(new Text(-18,-21, "R", Qt::darkBlue, 12.0)); 00039 Texts.append(new Text(-18, -1, "S", Qt::darkBlue, 12.0)); 00040 Texts.append(new Text( 6,-21, "Q", Qt::darkBlue, 12.0)); 00041 Texts.append(new Text( 6, -1, "Q", Qt::darkBlue, 12.0)); 00042 Texts.last()->over=true; 00043 00044 Ports.append(new Port(-30,-10)); // R 00045 Ports.append(new Port(-30, 10)); // S 00046 Ports.append(new Port( 30,-10)); // Q 00047 Ports.append(new Port( 30, 10)); // nQ 00048 00049 x1 = -30; y1 = -24; 00050 x2 = 30; y2 = 24; 00051 tx = x1+4; 00052 ty = y2+4; 00053 Model = "RSFF"; 00054 Name = "Y"; 00055 } 00056 00057 // ------------------------------------------------------- 00058 QString RS_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 = " " + 00069 Ports.at(2)->Connection->Name + " <= " + 00070 Ports.at(0)->Connection->Name + " nor " + 00071 Ports.at(3)->Connection->Name + s + " " + 00072 Ports.at(3)->Connection->Name + " <= " + 00073 Ports.at(1)->Connection->Name + " nor " + 00074 Ports.at(2)->Connection->Name + s + '\n'; 00075 return s; 00076 } 00077 00078 // ------------------------------------------------------- 00079 QString RS_FlipFlop::verilogCode(int NumPorts) 00080 { 00081 QString t = ""; 00082 if(NumPorts <= 0) { // no truth table simulation ? 00083 QString td = Props.at(0)->Value; // delay time 00084 if(!misc::Verilog_Delay(td, Name)) return td; // time has not VHDL format 00085 t = td; 00086 } 00087 t += " "; 00088 00089 QString l = ""; 00090 00091 QString s = Ports.at(1)->Connection->Name; 00092 QString r = Ports.at(0)->Connection->Name; 00093 QString q = Ports.at(2)->Connection->Name; 00094 QString b = Ports.at(3)->Connection->Name; 00095 00096 l = "\n // " + Name + " RS-flipflop\n" + 00097 " assign" + t + q + " = ~(" + r + " | " + b + ");\n" + 00098 " assign" + t + b + " = ~(" + s + " | " + q + ");\n\n"; 00099 return l; 00100 } 00101 00102 // ------------------------------------------------------- 00103 Component* RS_FlipFlop::newOne() 00104 { 00105 return new RS_FlipFlop(); 00106 } 00107 00108 // ------------------------------------------------------- 00109 Element* RS_FlipFlop::info(QString& Name, char* &BitmapFile, bool getNewOne) 00110 { 00111 Name = QObject::tr("RS-FlipFlop"); 00112 BitmapFile = (char *) "rsflipflop"; 00113 00114 if(getNewOne) return new RS_FlipFlop(); 00115 return 0; 00116 }