My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dmux3to8.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  dmux3to8
3  ----------
4  begin : December 2008
5  copyright : (C) 2008 by Mike Brinson
6  email : mbrin72043@yahoo.co.uk
7  ***************************************************************************/
8 
9 /*
10  * dmux3to8.cpp - device implementations for dmux3to8 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 "dmux3to8.h"
20 #include "node.h"
21 #include "main.h"
22 
23 
25 {
26  Type = isComponent; // Analogue and digital component.
27  Description = QObject::tr ("3to8 demultiplexer verilog device");
28 
29  Props.append (new Property ("TR", "6", false,
30  QObject::tr ("transfer function high scaling factor")));
31  Props.append (new Property ("Delay", "1 ns", false,
32  QObject::tr ("output delay")
33  +" ("+QObject::tr ("s")+")"));
34 
35  createSymbol ();
36  tx = x1 + 19;
37  ty = y2 + 4;
38  Model = "dmux3to8";
39  Name = "Y";
40 }
41 
43 {
44  dmux3to8 * p = new dmux3to8();
45  p->Props.getFirst()->Value = Props.getFirst()->Value;
46  p->recreate(0);
47  return p;
48 }
49 
50 Element * dmux3to8::info(QString& Name, char * &BitmapFile, bool getNewOne)
51 {
52  Name = QObject::tr("3to8 Demux");
53  BitmapFile = (char *) "dmux3to8";
54 
55  if(getNewOne) return new dmux3to8();
56  return 0;
57 }
58 
60 {
61  Lines.append(new Line(-30, -90, 30,-90,QPen(QPen::darkBlue,2)));
62  Lines.append(new Line( 30, -90, 30, 100,QPen(QPen::darkBlue,2)));
63  Lines.append(new Line( 30, 100,-30, 100,QPen(QPen::darkBlue,2)));
64  Lines.append(new Line(-30, 100,-30, -90,QPen(QPen::darkBlue,2)));
65 
66  Lines.append(new Line(-50,-50,-40,-50,QPen(QPen::darkBlue,2))); // EN
67  Lines.append(new Line(-50,-30,-30,-30,QPen(QPen::darkBlue,2))); // A
68  Lines.append(new Line(-50,-10,-30,-10,QPen(QPen::darkBlue,2))); // B
69  Lines.append(new Line(-50, 10,-30, 10,QPen(QPen::darkBlue,2))); // C
70 
71  Lines.append(new Line( 30, 90, 50, 90,QPen(QPen::darkBlue,2))); // Y7
72  Lines.append(new Line( 30, 70, 50, 70,QPen(QPen::darkBlue,2))); // Y6
73  Lines.append(new Line( 30, 50, 50, 50,QPen(QPen::darkBlue,2))); // Y5
74  Lines.append(new Line( 30, 30, 50, 30,QPen(QPen::darkBlue,2))); // Y4
75  Lines.append(new Line( 30, 10, 50, 10,QPen(QPen::darkBlue,2))); // Y3
76  Lines.append(new Line( 30,-10, 50,-10,QPen(QPen::darkBlue,2))); // Y2
77  Lines.append(new Line( 30,-30, 50,-30,QPen(QPen::darkBlue,2))); // Y1
78  Lines.append(new Line( 30,-50, 50,-50,QPen(QPen::darkBlue,2))); // Y0
79 
80  Arcs.append(new Arc( -40, -55, 10, 10, 0, 16*360, QPen(QPen::darkBlue,2)));
81 
82  Texts.append(new Text(-25,-85, "DMUX", QPen::darkBlue, 12.0));
83 
84  Texts.append(new Text(-25,-63, "En", QPen::darkBlue, 12.0));
85  Texts.append(new Text(-20,-25, "G", QPen::darkBlue, 12.0));
86  Texts.append(new Text(-8, -30, "}", QPen::darkBlue, 16.0));
87  Texts.append(new Text( 2, -32, "0", QPen::darkBlue, 12.0));
88  Texts.append(new Text( 2, -13, "7", QPen::darkBlue, 12.0));
89 
90  Texts.append(new Text(-25,-43, "0", QPen::darkBlue, 12.0));
91  Texts.append(new Text(-25, -3, "2", QPen::darkBlue, 12.0));
92 
93  Texts.append(new Text( 15,-63, "0", QPen::darkBlue, 12.0));
94  Texts.append(new Text( 15,-43, "1", QPen::darkBlue, 12.0));
95  Texts.append(new Text( 15,-23, "2", QPen::darkBlue, 12.0));
96  Texts.append(new Text( 15, -3, "3", QPen::darkBlue, 12.0));
97  Texts.append(new Text( 15, 17, "4", QPen::darkBlue, 12.0));
98  Texts.append(new Text( 15, 37, "5", QPen::darkBlue, 12.0));
99  Texts.append(new Text( 15, 57, "6", QPen::darkBlue, 12.0));
100  Texts.append(new Text( 15, 77, "7", QPen::darkBlue, 12.0));
101 
102  Lines.append(new Line(0, -11, 12, -11, QPen(QPen::darkBlue,2)));
103 
104  Ports.append(new Port(-50,-50)); // En
105  Ports.append(new Port(-50,-30)); // A
106  Ports.append(new Port(-50,-10)); // B
107  Ports.append(new Port(-50, 10)); // C
108  Ports.append(new Port( 50, 90)); // Y7
109  Ports.append(new Port( 50, 70)); // Y6
110  Ports.append(new Port( 50, 50)); // Y5
111  Ports.append(new Port( 50, 30)); // Y4
112  Ports.append(new Port( 50, 10)); // Y3
113  Ports.append(new Port( 50,-10)); // Y2
114  Ports.append(new Port( 50,-30)); // Y1
115  Ports.append(new Port( 50,-50)); // Y0
116 
117  x1 = -50; y1 = -94;
118  x2 = 50; y2 = 104;
119 }
120 
121 QString dmux3to8::vhdlCode( int )
122 {
123  QString s="";
124 
125  QString td = Props.at(1)->Value; // delay time
126  if(!VHDL_Delay(td, Name)) return td; // time has not VHDL format
127  td += ";\n";
128 
129  QString En = Ports.at(0)->Connection->Name;
130  QString A = Ports.at(1)->Connection->Name;
131  QString B = Ports.at(2)->Connection->Name;
132  QString C = Ports.at(3)->Connection->Name;
133  QString Y7 = Ports.at(4)->Connection->Name;
134  QString Y6 = Ports.at(5)->Connection->Name;
135  QString Y5 = Ports.at(6)->Connection->Name;
136  QString Y4 = Ports.at(7)->Connection->Name;
137  QString Y3 = Ports.at(8)->Connection->Name;
138  QString Y2 = Ports.at(9)->Connection->Name;
139  QString Y1 = Ports.at(10)->Connection->Name;
140  QString Y0 = Ports.at(11)->Connection->Name;
141 
142  s = "\n "+Name+":process ("+En+", "+A+", "+B+", "+C+")\n"+
143  " begin\n" +
144  " "+Y0+" <= "+"(not "+En+") and (not "+C+") and (not "+B+") and (not "+A+")"+td+
145  " "+Y1+" <= "+"(not "+En+") and (not "+C+") and (not "+B+") and "+A+td+
146  " "+Y2+" <= "+"(not "+En+") and (not "+C+") and "+B+" and (not "+A+")"+td+
147  " "+Y3+" <= "+"(not "+En+") and (not "+C+") and "+B+" and "+A+td+
148  " "+Y4+" <= "+"(not "+En+") and "+C+" and (not "+B+") and (not "+A+")"+td+
149  " "+Y5+" <= "+"(not "+En+") and "+C+" and (not "+B+") and "+A+td+
150  " "+Y6+" <= "+"(not "+En+") and "+C+" and "+B+" and (not "+A+")"+td+
151  " "+Y7+" <= "+"(not "+En+") and "+C+" and "+B+" and "+A+td+
152  " end process;\n";
153  return s;
154 }
155 
156 QString dmux3to8::verilogCode( int )
157 {
158  QString td = Props.at(1)->Value; // delay time
159  if(!Verilog_Delay(td, Name)) return td; // time does not have VHDL format
160 
161  QString l = "";
162 
163  QString En = Ports.at(0)->Connection->Name;
164  QString A = Ports.at(1)->Connection->Name;
165  QString B = Ports.at(2)->Connection->Name;
166  QString C = Ports.at(3)->Connection->Name;
167  QString Y7 = Ports.at(4)->Connection->Name;
168  QString Y6 = Ports.at(5)->Connection->Name;
169  QString Y5 = Ports.at(6)->Connection->Name;
170  QString Y4 = Ports.at(7)->Connection->Name;
171  QString Y3 = Ports.at(8)->Connection->Name;
172  QString Y2 = Ports.at(9)->Connection->Name;
173  QString Y1 = Ports.at(10)->Connection->Name;
174  QString Y0 = Ports.at(11)->Connection->Name;
175 
176  QString Y7R = "net_reg" + Name + Y7;
177  QString Y6R = "net_reg" + Name + Y6;
178  QString Y5R = "net_reg" + Name + Y5;
179  QString Y4R = "net_reg" + Name + Y4;
180  QString Y3R = "net_reg" + Name + Y3;
181  QString Y2R = "net_reg" + Name + Y2;
182  QString Y1R = "net_reg" + Name + Y1;
183  QString Y0R = "net_reg" + Name + Y0;
184 
185  l = "\n // " + Name + " 3to8 demux\n" +
186  " assign " + Y0 + " = " + Y0R + ";\n" +
187  " reg " + Y0R + " = 0;\n" +
188  " assign " + Y1 + " = " + Y1R + ";\n" +
189  " reg " + Y1R + " = 0;\n" +
190  " assign " + Y2 + " = " + Y2R + ";\n" +
191  " reg " + Y2R + " = 0;\n" +
192  " assign " + Y3 + " = " + Y3R + ";\n" +
193  " reg " + Y3R + " = 0;\n" +
194  " assign " + Y4 + " = " + Y4R + ";\n" +
195  " reg " + Y4R + " = 0;\n" +
196  " assign " + Y5 + " = " + Y5R + ";\n" +
197  " reg " + Y5R + " = 0;\n" +
198  " assign " + Y6 + " = " + Y6R + ";\n" +
199  " reg " + Y6R + " = 0;\n" +
200  " assign " + Y7 + " = " + Y7R + ";\n" +
201  " reg " + Y7R + " = 0;\n" +
202 
203 
204  " always @ ("+En+" or "+A+" or "+B+" or "+C+")\n" +
205  " begin\n"+
206  " "+Y0R+" <="+td+" (~"+En+") && (~"+C+") && (~"+B+") && (~"+A+");\n"+
207  " "+Y1R+" <="+td+" (~"+En+") && (~"+C+") && (~"+B+") && "+A+";\n"+
208  " "+Y2R+" <="+td+" (~"+En+") && (~"+C+") && "+B+" && (~"+A+");\n"+
209  " "+Y3R+" <="+td+" (~"+En+") && (~"+C+") && "+B+" && "+A+";\n"+
210  " "+Y4R+" <="+td+" (~"+En+") && "+C+" && (~"+B+") && (~"+A+");\n"+
211  " "+Y5R+" <="+td+" (~"+En+") && "+C+" && (~"+B+") && "+A+";\n"+
212  " "+Y6R+" <="+td+" (~"+En+") && "+C+" && "+B+" && (~"+A+");\n"+
213  " "+Y7R+" <="+td+" (~"+En+") && "+C+" && "+B+" && "+A+";\n"+
214  " end\n";
215 
216  return l;
217 }