Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
comp_2bit.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  comp_2bit
3  -----------
4  begin : December 2008
5  copyright : (C) 2008 by Mike Brinson
6  email : mbrin72043@yahoo.co.uk
7  ***************************************************************************/
8 
9 /*
10  * comp_2bit.cpp - device implementations for comp_2bit 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 "comp_2bit.h"
20 #include "node.h"
21 #include "main.h"
22 
24 {
25  Type = isComponent; // Analogue and digital component.
26  Description = QObject::tr ("2bit comparator verilog device");
27 
28  Props.append (new Property ("TR", "6", false,
29  QObject::tr ("transfer function high scaling factor")));
30  Props.append (new Property ("Delay", "1 ns", false,
31  QObject::tr ("output delay")
32  +" ("+QObject::tr ("s")+")"));
33 
34  createSymbol ();
35  tx = x1 + 19;
36  ty = y2 + 4;
37  Model = "comp_2bit";
38  Name = "Y";
39 }
40 
42 {
43  comp_2bit * p = new comp_2bit();
44  p->Props.getFirst()->Value = Props.getFirst()->Value;
45  p->recreate(0);
46  return p;
47 }
48 
49 Element * comp_2bit::info(QString& Name, char * &BitmapFile, bool getNewOne)
50 {
51  Name = QObject::tr("2Bit Comparator");
52  BitmapFile = (char *) "comp_2bit";
53 
54  if(getNewOne) return new comp_2bit();
55  return 0;
56 }
57 
59 {
60  Lines.append(new Line(-40, -50, 40,-50,QPen(Qt::darkBlue,2)));
61  Lines.append(new Line( 40, -50, 40, 60,QPen(Qt::darkBlue,2)));
62  Lines.append(new Line( 40, 60,-40, 60,QPen(Qt::darkBlue,2)));
63  Lines.append(new Line(-40, 60,-40, -50,QPen(Qt::darkBlue,2)));
64 
65  Lines.append(new Line(-60,-10,-40,-10,QPen(Qt::darkBlue,2))); // X0
66  Lines.append(new Line(-60, 10,-40, 10,QPen(Qt::darkBlue,2))); // X1
67  Lines.append(new Line(-60, 30,-40, 30,QPen(Qt::darkBlue,2))); // Y0
68  Lines.append(new Line(-60, 50,-40, 50,QPen(Qt::darkBlue,2))); // Y1
69  Lines.append(new Line( 40, 30, 60, 30,QPen(Qt::darkBlue,2))); // L
70  Lines.append(new Line( 40, 10, 60, 10,QPen(Qt::darkBlue,2))); // G
71  Lines.append(new Line( 40,-10, 60,-10,QPen(Qt::darkBlue,2))); // E
72 
73  Texts.append(new Text(-25,-45, "COMP", Qt::darkBlue, 12.0));
74 
75  Texts.append(new Text(-25,-20, "{", Qt::darkBlue, 16.0));
76  Texts.append(new Text(-15,-15, "X", Qt::darkBlue, 12.0));
77  Texts.append(new Text(-35,-23, "0", Qt::darkBlue, 12.0));
78  Texts.append(new Text(-35, -3, "1", Qt::darkBlue, 12.0));
79  Texts.append(new Text(-25, 22, "{", Qt::darkBlue, 16.0));
80  Texts.append(new Text(-15, 27, "Y", Qt::darkBlue, 12.0));
81  Texts.append(new Text(-35, 17, "0", Qt::darkBlue, 12.0));
82  Texts.append(new Text(-35, 37, "1", Qt::darkBlue, 12.0));
83  Texts.append(new Text( 5, 17, "X<Y", Qt::darkBlue, 12.0));
84  Texts.append(new Text( 5, -3, "X>Y", Qt::darkBlue, 12.0));
85  Texts.append(new Text( 5,-23, "X=Y", Qt::darkBlue, 12.0));
86 
87  Ports.append(new Port(-60,-10)); // X0
88  Ports.append(new Port(-60, 10)); // X1
89  Ports.append(new Port(-60, 30)); // Y0
90  Ports.append(new Port(-60, 50)); // Y1
91  Ports.append(new Port( 60, 30)); // L
92  Ports.append(new Port( 60, 10)); // G
93  Ports.append(new Port( 60,-10)); // E
94 
95  x1 = -60; y1 = -54;
96  x2 = 60; y2 = 64;
97 }
98 
99 QString comp_2bit::vhdlCode( int )
100 {
101  QString s="";
102 
103  QString td = Props.at(1)->Value; // delay time
104  if(!VHDL_Delay(td, Name)) return td; // time has not VHDL format
105  td += ";\n";
106 
107  QString X0 = Ports.at(0)->Connection->Name;
108  QString X1 = Ports.at(1)->Connection->Name;
109  QString Y0 = Ports.at(2)->Connection->Name;
110  QString Y1 = Ports.at(3)->Connection->Name;
111  QString L = Ports.at(4)->Connection->Name;
112  QString G = Ports.at(5)->Connection->Name;
113  QString E = Ports.at(6)->Connection->Name;
114 
115  s = "\n "+Name+":process ("+X0+", "+X1+", "+Y0+", "+Y1+")\n"+
116  " begin\n"+
117  " "+L+" <= ((not "+X1+") and "+Y1+") or (not ("+X1+" xor "+Y1+") and (not ("+X0+") and "+Y0+"))"+td+
118  " "+G+" <= ("+X1+" and (not "+Y1+"))"+" or (not ("+X1+" xor "+Y1+") and ("+X0+" and (not "+Y0+")))"+td+
119  " "+E+" <= (not ("+X1+" xor "+Y1+")) and (not ("+X0+" xor "+Y0+"))"+td+
120  " end process;\n";
121  return s;
122 }
123 
125 {
126  QString l="";
127 
128  QString td = Props.at(1)->Value; // delay time
129  if(!Verilog_Delay(td, Name)) return td; // time does not have VHDL format
130 
131  QString X0 = Ports.at(0)->Connection->Name;
132  QString X1 = Ports.at(1)->Connection->Name;
133  QString Y0 = Ports.at(2)->Connection->Name;
134  QString Y1 = Ports.at(3)->Connection->Name;
135  QString L = Ports.at(4)->Connection->Name;
136  QString G = Ports.at(5)->Connection->Name;
137  QString E = Ports.at(6)->Connection->Name;
138 
139  QString LR = "L_reg" + Name + L;
140  QString GR = "G_reg" + Name + G;
141  QString ER = "E_reg" + Name + E;
142 
143  l = "\n // "+Name+" 2bit comparator\n"+
144  " assign "+L+" = "+LR+";\n"+
145  " reg "+LR+" = 0;\n"+
146  " assign "+G+" = "+GR+";\n"+
147  " reg "+GR+" = 0;\n"+
148  " assign "+E+" = "+ER+";\n"+
149  " reg "+ER+" = 0;\n"+
150  " always @ ("+X0+" or "+X1+" or "+Y0+" or "+Y1+")\n"+
151  " begin\n"+
152  " "+LR+" <="+td+" ((~"+X1+") && "+Y1+") || (~("+X1+" ^ "+Y1+") && (~("+X0+") && "+Y0+"));\n"+
153  " "+GR+" <="+td+" ("+X1+" && (~"+Y1+"))"+" || (~("+X1+" ^ "+Y1+") && ("+X0+" && (~"+Y0+")));\n"+
154  " "+ER+" <="+td+" (~("+X1+" ^ "+Y1+")) && (~("+X0+" ^ "+Y0+"));\n"+
155  " end\n";
156 
157  return l;
158 }
QString verilogCode(int)
Definition: comp_2bit.cpp:124
Q3PtrList< Line > Lines
Definition: component.h:67
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
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
QString vhdlCode(int)
Definition: comp_2bit.cpp:99
Q3PtrList< Property > Props
Definition: component.h:72
static Element * info(QString &, char *&, bool getNewOne=false)
Definition: comp_2bit.cpp:49
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
void createSymbol()
Definition: comp_2bit.cpp:58
QString Model
Definition: component.h:80
QString Description
Definition: component.h:81
#define isComponent
Definition: element.h:110
Component * newOne()
Definition: comp_2bit.cpp:41
int x2
Definition: element.h:153
virtual void recreate(Schematic *)
Definition: component.h:39