Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tff_SR.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tff_SR
3  --------
4  begin : January 2009
5  copyright : (C) 2008 by Mike Brinson
6  email : mbrin72043@yahoo.co.uk
7  ***************************************************************************/
8 
9 /*
10  * tff_SR.cpp - device implementations for tff_SR module
11  *
12  * This is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2, or (at your option)
15  * any later version.
16  *
17  */
18 #include <QtGui>
19 #include "tff_SR.h"
20 #include "node.h"
21 #include "main.h"
22 
24 {
25  Type = isComponent; // Analogue and digital component.
26  Description = QObject::tr ("T flip flop with set and reset verilog device");
27 
28  Props.append (new Property ("TR_H", "6", false,
29  QObject::tr ("cross coupled gate transfer function high scaling factor")));
30  Props.append (new Property ("TR_L", "5", false,
31  QObject::tr ("cross coupled gate transfer function low scaling factor")));
32  Props.append (new Property ("Delay", "1 ns", false,
33  QObject::tr ("cross coupled gate delay")
34  +" ("+QObject::tr ("s")+")"));
35 
36  createSymbol ();
37  tx = x1 + 4;
38  ty = y2 + 4;
39  Model = "tff_SR";
40  Name = "Y";
41 }
42 
44 {
45  tff_SR * p = new tff_SR();
46  p->Props.getFirst()->Value = Props.getFirst()->Value;
47  p->recreate(0);
48  return p;
49 }
50 
51 Element * tff_SR::info(QString& Name, char * &BitmapFile, bool getNewOne)
52 {
53  Name = QObject::tr("T-FlipFlop w/ SR");
54  BitmapFile = (char *) "tff_SR";
55 
56  if(getNewOne) return new tff_SR();
57  return 0;
58 }
59 
61 {
62  // put in here symbol drawing code and terminal definitions
63  Lines.append(new Line(-30, -40, 30,-40,QPen(Qt::darkBlue,2)));
64  Lines.append(new Line( 30, -40, 30, 40,QPen(Qt::darkBlue,2)));
65  Lines.append(new Line( 30, 40,-30, 40,QPen(Qt::darkBlue,2)));
66  Lines.append(new Line(-30, 40,-30,-40,QPen(Qt::darkBlue,2)));
67 
68  Lines.append(new Line(-50,-20,-30,-20,QPen(Qt::darkBlue,2)));
69  Lines.append(new Line(-50, 20,-30, 20,QPen(Qt::darkBlue,2)));
70  Lines.append(new Line( 30, 20, 50, 20,QPen(Qt::darkBlue,2)));
71  Lines.append(new Line( 30,-20, 50,-20,QPen(Qt::darkBlue,2)));
72 
73  Lines.append(new Line( -30, 10,-20, 20,QPen(Qt::darkBlue,2)));
74  Lines.append(new Line( -30, 30,-20, 20,QPen(Qt::darkBlue,2)));
75 
76  Lines.append(new Line( 0, -50, 0,-60,QPen(Qt::darkBlue,2)));
77  Lines.append(new Line( 0, 50, 0, 60,QPen(Qt::darkBlue,2)));
78 
79  Arcs.append(new Arc( -5, -50, 10, 10, 0, 16*360, QPen(Qt::darkBlue,2)));
80  Arcs.append(new Arc( -5, 40, 10, 10, 0, 16*360, QPen(Qt::darkBlue,2)));
81 
82  Texts.append(new Text(-25,-32, "T", Qt::darkBlue, 12.0));
83  Texts.append(new Text( 11,-32, "Q", Qt::darkBlue, 12.0));
84  Texts.append(new Text( -5,-39, "S", Qt::darkBlue, 12.0));
85  Texts.append(new Text( 11, 7, "Q", Qt::darkBlue, 12.0));
86  Texts.current()->over=true;
87  Texts.append(new Text( -5, 17, "R", Qt::darkBlue, 12.0));
88 
89  Ports.append(new Port( 0,-60)); // S
90  Ports.append(new Port(-50,-20)); // T
91  Ports.append(new Port(-50, 20)); // CLK
92  Ports.append(new Port( 0, 60)); // R
93  Ports.append(new Port( 50, 20)); // QB
94  Ports.append(new Port( 50,-20)); // Q
95 
96  x1 = -50; y1 = -60;
97  x2 = 50; y2 = 60;
98 }
99 
100 QString tff_SR::vhdlCode( int )
101 {
102  QString s="";
103 
104  QString td = Props.at(2)->Value; // delay time
105  if(!VHDL_Delay(td, Name)) return td; // time has not VHDL format
106  td += ";\n";
107 
108  QString S = Ports.at(0)->Connection->Name;
109  QString T = Ports.at(1)->Connection->Name;
110  QString CLK = Ports.at(2)->Connection->Name;
111  QString R = Ports.at(3)->Connection->Name;
112  QString QB = Ports.at(4)->Connection->Name;
113  QString Q = Ports.at(5)->Connection->Name;
114 
115  s = "\n "+Name+" : process ("+S+", "+CLK+", "+R+") is\n"+
116  " variable state : std_logic;\n"+
117  " begin\n" +
118  " if ("+S+" = '0') then\n"+
119  " state := '1';\n"+
120  " elsif ("+R+" = '0') then\n"+
121  " state := '0';\n"+
122  " elsif ("+CLK+" = '1' and "+CLK+"'event) then\n"+
123  " if ("+T+" = '1') then state := not state;\n"+
124  " end if;\n"+
125  " end if;\n"+
126  " "+Q+" <= state"+td+
127  " "+QB+" <= not state"+td+
128  " end process;\n";
129  return s;
130 }
131 
132 QString tff_SR::verilogCode( int )
133 {
134  QString td = Props.at(2)->Value; // delay time
135  if(!Verilog_Delay(td, Name)) return td; // time does not have VHDL format
136 
137  QString l = "";
138 
139  QString S = Ports.at(0)->Connection->Name;
140  QString T = Ports.at(1)->Connection->Name;
141  QString CLK = Ports.at(2)->Connection->Name;
142  QString R = Ports.at(3)->Connection->Name;
143  QString QB = Ports.at(4)->Connection->Name;
144  QString Q = Ports.at(5)->Connection->Name;
145 
146  QString QR = "Q_reg" + Name + Q;
147  QString QBR = "QB_reg" + Name + QB;
148  QString ST = "Q_state" + Name;
149 
150  l = "\n // "+Name+" t flip flop with set and reset\n"+
151  " assign "+Q+" = "+QR+";\n"+
152  " reg "+QR+" = 0;\n"+
153  " assign "+QB+" = "+QBR+";\n"+
154  " reg "+QBR+" = 1;\n"+
155  " reg "+ST+" = 0;\n"+
156  " always @ (posedge "+CLK+")\n"+
157  " begin\n"+
158  " if ("+T+" == 1 && "+R+" == 1 && "+S+" == 1)\n"+
159  " begin\n"+
160  " "+ST+" = ~"+ST+";\n"+
161  " "+QR+" <="+td+" "+ST+";\n"+
162  " "+QBR+" <="+td+" ~"+ST+";\n"+
163  " end\n"+
164  " end\n"+
165  " always @ ("+R+")\n"+
166  " begin\n"+
167  " if ("+R+" == 0) "+ST+" = 0;\n"+
168  " "+QR+" <="+td+" "+ST+";\n"+
169  " "+QBR+" <="+td+" ~"+ST+";\n"+
170  " end\n"+
171  " always @ ("+S+")\n"+
172  " begin if ("+S+" == 0) "+ST+" = 1;\n"+
173  " "+QR+" <="+td+" "+ST+";\n"+
174  " "+QBR+" <="+td+" ~"+ST+";\n"+
175  " end\n";
176  return l;
177 }
Q3PtrList< Line > Lines
Definition: component.h:67
int Type
Definition: element.h:152
Definition: element.h:55
int y1
Definition: element.h:153
bool VHDL_Delay(QString &td, const QString &Name)
Definition: main.cpp:493
Q3PtrList< struct Arc > Arcs
Definition: component.h:68
int tx
Definition: component.h:78
int y2
Definition: element.h:153
Definition: element.h:72
int x1
Definition: element.h:153
void createSymbol()
Definition: tff_SR.cpp:60
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
Definition: tff_SR.h:16
Q3PtrList< Property > Props
Definition: component.h:72
tff_SR()
Definition: tff_SR.cpp:23
Definition: element.h:82
Definition: element.h:48
Superclass of all schematic drawing elements.
Definition: element.h:142
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
QString vhdlCode(int)
Definition: tff_SR.cpp:100
#define isComponent
Definition: element.h:110
QString verilogCode(int)
Definition: tff_SR.cpp:132
static Element * info(QString &, char *&, bool getNewOne=false)
Definition: tff_SR.cpp:51
Component * newOne()
Definition: tff_SR.cpp:43
int x2
Definition: element.h:153
virtual void recreate(Schematic *)
Definition: component.h:39