Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
d_flipflop.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  d_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 "d_flipflop.h"
19 #include "node.h"
20 #include "main.h"
21 
23 {
25  Description = QObject::tr("D flip flop with asynchron reset");
26 
27  Props.append(new Property("t", "0", false, QObject::tr("delay time")));
28 
29  Lines.append(new Line(-20,-20, 20,-20,QPen(Qt::darkBlue,2)));
30  Lines.append(new Line(-20, 20, 20, 20,QPen(Qt::darkBlue,2)));
31  Lines.append(new Line(-20,-20,-20, 20,QPen(Qt::darkBlue,2)));
32  Lines.append(new Line( 20,-20, 20, 20,QPen(Qt::darkBlue,2)));
33 
34  Lines.append(new Line(-30,-10,-20,-10,QPen(Qt::darkBlue,2)));
35  Lines.append(new Line(-30, 10,-20, 10,QPen(Qt::darkBlue,2)));
36  Lines.append(new Line( 30,-10, 20,-10,QPen(Qt::darkBlue,2)));
37  Lines.append(new Line( 0, 20, 0, 30,QPen(Qt::darkBlue,2)));
38 
39  Texts.append(new Text(-18,-21, "D", Qt::darkBlue, 12.0));
40  Texts.append(new Text( 6,-21, "Q", Qt::darkBlue, 12.0));
41  Texts.append(new Text( -4, 4, "R", Qt::darkBlue, 9.0));
42  Lines.append(new Line(-20, 6,-12, 10,QPen(Qt::darkBlue,0)));
43  Lines.append(new Line(-20, 14,-12, 10,QPen(Qt::darkBlue,0)));
44 
45  Ports.append(new Port(-30,-10)); // D
46  Ports.append(new Port(-30, 10)); // Clock
47  Ports.append(new Port( 30,-10)); // Q
48  Ports.append(new Port( 0, 30)); // Reset
49 
50  x1 = -30; y1 = -24;
51  x2 = 30; y2 = 30;
52  tx = x1+4;
53  ty = y2+4;
54  Model = "DFF";
55  Name = "Y";
56 }
57 
58 // -------------------------------------------------------
59 QString D_FlipFlop::vhdlCode(int NumPorts)
60 {
61  QString s = "";
62  if(NumPorts <= 0) { // no truth table simulation ?
63  QString td = Props.at(0)->Value; // delay time
64  if(!VHDL_Delay(td, Name)) return td; // time has not VHDL format
65  s += td;
66  }
67  s += ";\n";
68 
69  s = " " + Name + " : process (" +
70  Ports.at(0)->Connection->Name + ", " +
71  Ports.at(1)->Connection->Name + ")\n begin\n if (" +
72  Ports.at(3)->Connection->Name + "='1') then " +
73  Ports.at(2)->Connection->Name + " <= '0'" + s +" elsif (" +
74  Ports.at(1)->Connection->Name + "='1' and " +
75  Ports.at(1)->Connection->Name + "'event) then\n " +
76  Ports.at(2)->Connection->Name + " <= " +
77  Ports.at(0)->Connection->Name + s + " end if;\n end process;\n\n";
78  return s;
79 }
80 
81 // -------------------------------------------------------
82 QString D_FlipFlop::verilogCode(int NumPorts)
83 {
84  QString t = "";
85  if(NumPorts <= 0) { // no truth table simulation ?
86  QString td = Props.at(0)->Value; // delay time
87  if(!Verilog_Delay(td, Name)) return td; // time has not VHDL format
88  if(!td.isEmpty()) t = " " + td + ";\n";
89  }
90 
91  QString s = "";
92  QString q = Ports.at(2)->Connection->Name;
93  QString d = Ports.at(0)->Connection->Name;
94  QString r = Ports.at(3)->Connection->Name;
95  QString c = Ports.at(1)->Connection->Name;
96  QString v = "net_reg" + Name + q;
97 
98  s = "\n // " + Name + " D-flipflop\n" +
99  " assign " + q + " = " + v + ";\n" +
100  " reg " + v + " = 0;\n" +
101  " always @ (" + c + " or " + r + ") begin\n" + t +
102  " if (" + r + ") " + v + " <= 0;\n" +
103  " else if (~" + r + " && " + c + ") " + v + " <= " + d + ";\n" +
104  " end\n\n";
105  return s;
106 }
107 
108 // -------------------------------------------------------
110 {
111  return new D_FlipFlop();
112 }
113 
114 // -------------------------------------------------------
115 Element* D_FlipFlop::info(QString& Name, char* &BitmapFile, bool getNewOne)
116 {
117  Name = QObject::tr("D-FlipFlop");
118  BitmapFile = (char *) "dflipflop";
119 
120  if(getNewOne) return new D_FlipFlop();
121  return 0;
122 }
Q3PtrList< Line > Lines
Definition: component.h:67
QString verilogCode(int)
Definition: d_flipflop.cpp:82
int Type
Definition: element.h:152
int y1
Definition: element.h:153
bool VHDL_Delay(QString &td, const QString &Name)
Definition: main.cpp:493
static Element * info(QString &, char *&, bool getNewOne=false)
Definition: d_flipflop.cpp:115
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
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
Component * newOne()
Definition: d_flipflop.cpp:109
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: d_flipflop.cpp:59
int x2
Definition: element.h:153