My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
greytobinary4bit.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  greytobinary4bit
3  -------------------
4  begin : December 2008
5  copyright : (C) 2008 by Mike Brinson
6  email : mbrin72043@yahoo.co.uk
7  ***************************************************************************/
8 
9 /*
10  * greytobinary4bit.cpp - device implementations for greytobinary4bit 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 
19 #include "greytobinary4bit.h"
20 #include "node.h"
21 #include "main.h"
22 
24 {
25  Type = isComponent; // Analogue and digital component.
26  Description = QObject::tr ("4bit grey to binary converter verilog device");
27 
28  Props.append (new Property ("TR", "6", false,
29  QObject::tr ("transfer function 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 = "greytobinary4bit";
38  Name = "Y";
39 }
40 
42 {
44  p->Props.getFirst()->Value = Props.getFirst()->Value;
45  p->recreate(0);
46  return p;
47 }
48 
49 Element * greytobinary4bit::info(QString& Name, char * &BitmapFile, bool getNewOne)
50 {
51  Name = QObject::tr("4Bit Grey2Bin");
52  BitmapFile = (char *) "greytobinary4bit";
53 
54  if(getNewOne) return new greytobinary4bit();
55  return 0;
56 }
57 
59 {
60  Lines.append(new Line(-30, -60, 30,-60,QPen(QPen::darkBlue,2)));
61  Lines.append(new Line( 30, -60, 30, 40,QPen(QPen::darkBlue,2)));
62  Lines.append(new Line( 30, 40,-30, 40,QPen(QPen::darkBlue,2)));
63  Lines.append(new Line(-30, 40,-30, -60,QPen(QPen::darkBlue,2)));
64 
65  Lines.append(new Line(-50,-30,-30,-30,QPen(QPen::darkBlue,2))); // G0
66  Lines.append(new Line(-50,-10,-30,-10,QPen(QPen::darkBlue,2))); // G1
67  Lines.append(new Line(-50, 10,-30, 10,QPen(QPen::darkBlue,2))); // G2
68  Lines.append(new Line(-50, 30,-30, 30,QPen(QPen::darkBlue,2))); // G3
69 
70  Lines.append(new Line( 30, 30, 50, 30,QPen(QPen::darkBlue,2))); // B3
71  Lines.append(new Line( 30, 10, 50, 10,QPen(QPen::darkBlue,2))); // B2
72  Lines.append(new Line( 30,-10, 50,-10,QPen(QPen::darkBlue,2))); // B1
73  Lines.append(new Line( 30,-30, 50,-30,QPen(QPen::darkBlue,2))); // B0
74 
75  Texts.append(new Text(-16,-59, "G", QPen::darkBlue, 12.0));
76  Texts.append(new Text( -2,-59, "/", QPen::darkBlue, 12.0));
77  Texts.append(new Text( 5,-59, "B", QPen::darkBlue, 12.0));
78 
79  Texts.append(new Text(-25,-43, "0", QPen::darkBlue, 12.0));
80  Texts.append(new Text(-25,-23, "1", QPen::darkBlue, 12.0));
81  Texts.append(new Text(-25, -3, "2", QPen::darkBlue, 12.0));
82  Texts.append(new Text(-25, 17, "3", QPen::darkBlue, 12.0));
83 
84  Texts.append(new Text( 15,-43, "0", QPen::darkBlue, 12.0));
85  Texts.append(new Text( 15,-23, "1", QPen::darkBlue, 12.0));
86  Texts.append(new Text( 15, -3, "2", QPen::darkBlue, 12.0));
87  Texts.append(new Text( 15, 17, "3", QPen::darkBlue, 12.0));
88 
89  Ports.append(new Port(-50,-30)); // G0
90  Ports.append(new Port(-50,-10)); // G1
91  Ports.append(new Port(-50, 10)); // G2
92  Ports.append(new Port(-50, 30)); // G3
93 
94  Ports.append(new Port( 50, 30)); // B3
95  Ports.append(new Port( 50, 10)); // B2
96  Ports.append(new Port( 50,-10)); // B1
97  Ports.append(new Port( 50,-30)); // B0
98 
99  x1 = -50; y1 = -64;
100  x2 = 50; y2 = 44;
101 }
102 
104 {
105  QString s="";
106 
107  QString td = Props.at(1)->Value; // delay time
108  if(!VHDL_Delay(td, Name)) return td; // time has not VHDL format
109  td += ";\n";
110 
111  QString G0 = Ports.at(0)->Connection->Name;
112  QString G1 = Ports.at(1)->Connection->Name;
113  QString G2 = Ports.at(2)->Connection->Name;
114  QString G3 = Ports.at(3)->Connection->Name;
115  QString B3 = Ports.at(4)->Connection->Name;
116  QString B2 = Ports.at(5)->Connection->Name;
117  QString B1 = Ports.at(6)->Connection->Name;
118  QString B0 = Ports.at(7)->Connection->Name;
119 
120  s = "\n " + Name + ":process ("+G0+", "+G1+", "+G2+", "+G3+")\n"+
121  " begin\n"+
122  " "+B3+" <= "+G3+td+
123  " "+B2+" <= "+G3+" xor "+G2+td+
124  " "+B1+" <= "+G3+" xor "+G2+" xor "+G1+td+
125  " "+B0+" <= "+G3+" xor "+G2+" xor "+G1+" xor "+G0+td+
126  " end process;\n";
127  return s;
128 }
129 
131 {
132  QString td = Props.at(1)->Value; // delay time
133  if(!Verilog_Delay(td, Name)) return td; // time does not have VHDL format
134 
135  QString G0 = Ports.at(0)->Connection->Name;
136  QString G1 = Ports.at(1)->Connection->Name;
137  QString G2 = Ports.at(2)->Connection->Name;
138  QString G3 = Ports.at(3)->Connection->Name;
139  QString B3 = Ports.at(4)->Connection->Name;
140  QString B2 = Ports.at(5)->Connection->Name;
141  QString B1 = Ports.at(6)->Connection->Name;
142  QString B0 = Ports.at(7)->Connection->Name;
143 
144  QString l = "";
145 
146  QString B0R = "net_reg" + Name + B0;
147  QString B1R = "net_reg" + Name + B1;
148  QString B2R = "net_reg" + Name + B2;
149  QString B3R = "net_reg" + Name + B3;
150 
151  l = "\n // " + Name + " 4bit grey to binary\n" +
152  " assign " + B0 + " = " + B0R + ";\n" +
153  " reg " + B0R + " = 0;\n" +
154  " assign " + B1 + " = " + B1R + ";\n" +
155  " reg " + B1R + " = 0;\n" +
156  " assign " + B2 + " = " + B2R + ";\n" +
157  " reg " + B2R + " = 0;\n" +
158  " assign " + B3 + " = " + B3R + ";\n" +
159  " reg " + B3R + " = 0;\n" +
160  " always @ ("+G0+" or "+G1+" or "+G2+" or "+G3+")\n" +
161  " begin\n"+
162  " "+B3R+" <="+td+" "+G3+";\n"+
163  " "+B2R+" <="+td+" "+G3+" ^ "+G2+";\n"+
164  " "+B1R+" <="+td+" "+G3+" ^ "+G2+" ^ "+G1+";\n"+
165  " "+B0R+" <="+td+" "+G3+" ^ "+G2+" ^ "+G1+" ^ "+G0+";\n"+
166  " end\n";
167  return l;
168 }
169