Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
jk_flipflop.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  jk_flipflop.cpp
3  -----------------
4  begin : Fri Jan 06 2006
5  copyright : (C) 2006 by Michael Margraf
6  email : michael.margraf@alumni.tu-berlin.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 #include <QtGui>
18 #include <stdlib.h>
19 
20 #include "jk_flipflop.h"
21 #include "node.h"
22 #include "main.h"
23 
25 {
27  Description = QObject::tr("JK flip flop with asynchron set and reset");
28 
29  Props.append(new Property("t", "0", false, QObject::tr("delay time")));
30 
31  Lines.append(new Line(-20,-30, 20,-30,QPen(Qt::darkBlue,2)));
32  Lines.append(new Line(-20, 30, 20, 30,QPen(Qt::darkBlue,2)));
33  Lines.append(new Line(-20,-30,-20, 30,QPen(Qt::darkBlue,2)));
34  Lines.append(new Line( 20,-30, 20, 30,QPen(Qt::darkBlue,2)));
35 
36  Lines.append(new Line(-30,-20,-20,-20,QPen(Qt::darkBlue,2)));
37  Lines.append(new Line(-30, 20,-20, 20,QPen(Qt::darkBlue,2)));
38  Lines.append(new Line( 30,-20, 20,-20,QPen(Qt::darkBlue,2)));
39  Lines.append(new Line( 30, 20, 20, 20,QPen(Qt::darkBlue,2)));
40  Lines.append(new Line(-30, 0,-20, 0,QPen(Qt::darkBlue,2)));
41  Lines.append(new Line( 0,-30, 0,-40,QPen(Qt::darkBlue,2)));
42  Lines.append(new Line( 0, 30, 0, 40,QPen(Qt::darkBlue,2)));
43 
44  Texts.append(new Text( -4,-29, "S", Qt::darkBlue, 9.0));
45  Texts.append(new Text( -4, 14, "R", Qt::darkBlue, 9.0));
46  Texts.append(new Text(-18,-31, "J", Qt::darkBlue, 12.0));
47  Texts.append(new Text(-18, 8, "K", Qt::darkBlue, 12.0));
48  Texts.append(new Text( 6,-31, "Q", Qt::darkBlue, 12.0));
49  Texts.append(new Text( 6, 8, "Q", Qt::darkBlue, 12.0));
50  Texts.current()->over=true;
51  Lines.append(new Line(-20, -4,-12, 0,QPen(Qt::darkBlue,0)));
52  Lines.append(new Line(-20, 4,-12, 0,QPen(Qt::darkBlue,0)));
53 
54  Ports.append(new Port(-30,-20)); // J
55  Ports.append(new Port(-30, 20)); // K
56  Ports.append(new Port( 30,-20)); // Q
57  Ports.append(new Port( 30, 20)); // nQ
58  Ports.append(new Port(-30, 0)); // Clock
59  Ports.append(new Port( 0,-40)); // set
60  Ports.append(new Port( 0, 40)); // reset
61 
62  x1 = -30; y1 = -40;
63  x2 = 30; y2 = 40;
64  tx = x1+4;
65  ty = y2+4;
66  Model = "JKFF";
67  Name = "Y";
68 }
69 
70 // -------------------------------------------------------
71 QString JK_FlipFlop::vhdlCode(int NumPorts)
72 {
73  QString s = "";
74  if(NumPorts <= 0) { // no truth table simulation ?
75  QString td = Props.at(0)->Value; // delay time
76  if(!VHDL_Delay(td, Name)) return td; // time has not VHDL format
77  s += td;
78  }
79  s += ";\n";
80 
81  s = " " + Name + " : process (" +
82  Ports.at(5)->Connection->Name + ", " +
83  Ports.at(6)->Connection->Name + ", " +
84  Ports.at(4)->Connection->Name + ")\n begin\n if (" +
85  Ports.at(6)->Connection->Name + "='1') then " +
86  Ports.at(2)->Connection->Name + " <= '0'" + s +" elsif (" +
87  Ports.at(5)->Connection->Name + "='1') then " +
88  Ports.at(2)->Connection->Name + " <= '1'" + s +" elsif (" +
89  Ports.at(4)->Connection->Name + "='1' and " +
90  Ports.at(4)->Connection->Name + "'event) then\n " +
91  Ports.at(2)->Connection->Name + " <= (" +
92  Ports.at(0)->Connection->Name + " and not " +
93  Ports.at(2)->Connection->Name + ") or (not " +
94  Ports.at(1)->Connection->Name + " and " +
95  Ports.at(2)->Connection->Name + ")" + s +
96  " end if;\n end process;\n " +
97  Ports.at(3)->Connection->Name + " <= not " +
98  Ports.at(2)->Connection->Name + ";\n\n";
99  return s;
100 }
101 
102 // -------------------------------------------------------
103 QString JK_FlipFlop::verilogCode(int NumPorts)
104 {
105  QString t = "";
106  if(NumPorts <= 0) { // no truth table simulation ?
107  QString td = Props.at(0)->Value; // delay time
108  if(!Verilog_Delay(td, Name)) return td; // time has not VHDL format
109  if(!td.isEmpty()) t = " " + td + ";\n";
110  }
111 
112  QString l = "";
113 
114  QString s = Ports.at(5)->Connection->Name;
115  QString r = Ports.at(6)->Connection->Name;
116  QString j = Ports.at(0)->Connection->Name;
117  QString k = Ports.at(1)->Connection->Name;
118  QString q = Ports.at(2)->Connection->Name;
119  QString b = Ports.at(3)->Connection->Name;
120  QString c = Ports.at(4)->Connection->Name;
121  QString v = "net_reg" + Name + q;
122 
123  l = "\n // " + Name + " JK-flipflop\n" +
124  " assign " + q + " = " + v + ";\n" +
125  " assign " + b + " = ~" + q + ";\n" +
126  " reg " + v + " = 0;\n" +
127  " always @ (" + c + " or " + r + " or " + s + ") begin\n" + t +
128  " if (" + r + ") " + v + " <= 0;\n" +
129  " else if (" + s + ") " + v + " <= 1;\n" +
130  " else if (" + c + ")\n" +
131  " " + v + " <= (" + j + " && ~" + q + ") || (~" +
132  k + " && " + q + ");\n" +
133  " end\n\n";
134  return l;
135 }
136 
137 // -------------------------------------------------------
139 {
140  return new JK_FlipFlop();
141 }
142 
143 // -------------------------------------------------------
144 Element* JK_FlipFlop::info(QString& Name, char* &BitmapFile, bool getNewOne)
145 {
146  Name = QObject::tr("JK-FlipFlop");
147  BitmapFile = (char *) "jkflipflop";
148 
149  if(getNewOne) return new JK_FlipFlop();
150  return 0;
151 }
Q3PtrList< Line > Lines
Definition: component.h:67
Component * newOne()
int Type
Definition: element.h:152
int y1
Definition: element.h:153
bool VHDL_Delay(QString &td, const QString &Name)
Definition: main.cpp:493
int tx
Definition: component.h:78
int y2
Definition: element.h:153
Definition: element.h:72
int x1
Definition: element.h:153
#define isDigitalComponent
Definition: element.h:113
QString vhdlCode(int)
Definition: jk_flipflop.cpp:71
bool Verilog_Delay(QString &td, const QString &Name)
Definition: main.cpp:555
Definitions and declarations for the main application.
int ty
Definition: component.h:78
Q3PtrList< Property > Props
Definition: component.h:72
Definition: element.h:82
Definition: element.h:48
Superclass of all schematic drawing elements.
Definition: element.h:142
QString verilogCode(int)
Q3PtrList< Port > Ports
Definition: component.h:70
QString Name
Definition: component.h:80
Q3PtrList< Text > Texts
Definition: component.h:71
QString Model
Definition: component.h:80
QString Description
Definition: component.h:81
static Element * info(QString &, char *&, bool getNewOne=false)
int x2
Definition: element.h:153