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