My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dmux4to16.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  dmux4to16
3  -----------
4  begin : December 2008
5  copyright : (C) 2008 by Mike Brinson
6  email : mbrin72043@yahoo.co.uk
7  ***************************************************************************/
8 
9 /*
10  * dmux4to16.cpp - device implementations for dmux4to16 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 "dmux4to16.h"
20 #include "node.h"
21 #include "main.h"
22 
24 {
25  Type = isComponent; // Analogue and digital component.
26  Description = QObject::tr ("4to16 demultiplexer 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 = "dmux4to16";
38  Name = "Y";
39 }
40 
42 {
43  dmux4to16 * p = new dmux4to16();
44  p->Props.getFirst()->Value = Props.getFirst()->Value;
45  p->recreate(0);
46  return p;
47 }
48 
49 Element * dmux4to16::info(QString& Name, char * &BitmapFile, bool getNewOne)
50 {
51  Name = QObject::tr("4to16 Demux");
52  BitmapFile = (char *) "dmux4to16";
53 
54  if(getNewOne) return new dmux4to16();
55  return 0;
56 }
57 
59 {
60  Lines.append(new Line(-30, -90, 30,-90,QPen(QPen::darkBlue,2)));
61  Lines.append(new Line( 30, -90, 30, 110,QPen(QPen::darkBlue,2)));
62  Lines.append(new Line( 30, 110,-30, 110,QPen(QPen::darkBlue,2)));
63  Lines.append(new Line(-30, 110,-30, -90,QPen(QPen::darkBlue,2)));
64 
65  Lines.append(new Line(-50,-50,-40,-50,QPen(QPen::darkBlue,2))); // EN
66  Lines.append(new Line(-50,-30,-30,-30,QPen(QPen::darkBlue,2))); // A
67  Lines.append(new Line(-50,-10,-30,-10,QPen(QPen::darkBlue,2))); // B
68  Lines.append(new Line(-50, 10,-30, 10,QPen(QPen::darkBlue,2))); // C
69  Lines.append(new Line(-50, 30,-30, 30,QPen(QPen::darkBlue,2))); // D
70 
71  Lines.append(new Line( 30, 100, 50,100,QPen(QPen::darkBlue,2))); // Y15
72  Lines.append(new Line( 30, 90, 50, 90,QPen(QPen::darkBlue,2))); // Y14
73  Lines.append(new Line( 30, 80, 50, 80,QPen(QPen::darkBlue,2))); // Y13
74  Lines.append(new Line( 30, 70, 50, 70,QPen(QPen::darkBlue,2))); // Y12
75  Lines.append(new Line( 30, 60, 50, 60,QPen(QPen::darkBlue,2))); // Y11
76  Lines.append(new Line( 30, 50, 50, 50,QPen(QPen::darkBlue,2))); // Y10
77  Lines.append(new Line( 30, 40, 50, 40,QPen(QPen::darkBlue,2))); // Y9
78  Lines.append(new Line( 30, 30, 50, 30,QPen(QPen::darkBlue,2))); // Y8
79  Lines.append(new Line( 30, 20, 50, 20,QPen(QPen::darkBlue,2))); // Y7
80  Lines.append(new Line( 30, 10, 50, 10,QPen(QPen::darkBlue,2))); // Y6
81  Lines.append(new Line( 30, 0, 50, 0,QPen(QPen::darkBlue,2))); // Y5
82  Lines.append(new Line( 30, -10, 50,-10,QPen(QPen::darkBlue,2))); // Y4
83  Lines.append(new Line( 30, -20, 50,-20,QPen(QPen::darkBlue,2))); // Y3
84  Lines.append(new Line( 30, -30, 50,-30,QPen(QPen::darkBlue,2))); // Y2
85  Lines.append(new Line( 30, -40, 50,-40,QPen(QPen::darkBlue,2))); // Y1
86  Lines.append(new Line( 30, -50, 50,-50,QPen(QPen::darkBlue,2))); // Y0
87 
88  Arcs.append(new Arc( -40, -55, 10, 10, 0, 16*360, QPen(QPen::darkBlue,2)));
89 
90  Texts.append(new Text(-25,-85, "DMUX", QPen::darkBlue, 12.0));
91 
92  Texts.append(new Text(-25,-63, "En", QPen::darkBlue, 12.0));
93  Texts.append(new Text(-26,-15, "G", QPen::darkBlue, 12.0));
94  Texts.append(new Text(-13,-20, "}", QPen::darkBlue, 16.0));
95  Texts.append(new Text( -5,-20, "0", QPen::darkBlue, 12.0));
96  Texts.append(new Text( -8, 0, "15", QPen::darkBlue, 12.0));
97 
98  Texts.append(new Text(-25,-43, "0", QPen::darkBlue, 12.0));
99  Texts.append(new Text(-25, 17, "3", QPen::darkBlue, 12.0));
100 
101  Texts.append(new Text( 15,-59, "0", QPen::darkBlue, 9.0));
102  Texts.append(new Text( 15,-49, "1", QPen::darkBlue, 9.0));
103  Texts.append(new Text( 15,-39, "2", QPen::darkBlue, 9.0));
104  Texts.append(new Text( 15,-29, "3", QPen::darkBlue, 9.0));
105  Texts.append(new Text( 15,-19, "4", QPen::darkBlue, 9.0));
106  Texts.append(new Text( 15, -9, "5", QPen::darkBlue, 9.0));
107  Texts.append(new Text( 15, 1, "6", QPen::darkBlue, 9.0));
108  Texts.append(new Text( 15, 11, "7", QPen::darkBlue, 9.0));
109  Texts.append(new Text( 15, 21, "8", QPen::darkBlue, 9.0));
110  Texts.append(new Text( 15, 31, "9", QPen::darkBlue, 9.0));
111  Texts.append(new Text( 8, 41, "10", QPen::darkBlue, 9.0));
112  Texts.append(new Text( 8, 51, "11", QPen::darkBlue, 9.0));
113  Texts.append(new Text( 8, 61, "12", QPen::darkBlue, 9.0));
114  Texts.append(new Text( 8, 71, "13", QPen::darkBlue, 9.0));
115  Texts.append(new Text( 8, 81, "14", QPen::darkBlue, 9.0));
116  Texts.append(new Text( 8, 91, "15", QPen::darkBlue, 9.0));
117 
118  Lines.append(new Line(-6, 2, 9, 2, QPen(QPen::darkBlue,2)));
119 
120  Ports.append(new Port(-50,-50)); // En
121  Ports.append(new Port(-50,-30)); // A
122  Ports.append(new Port(-50,-10)); // B
123  Ports.append(new Port(-50, 10)); // C
124  Ports.append(new Port(-50, 30)); // D
125  Ports.append(new Port( 50,100)); // Y15
126  Ports.append(new Port( 50, 90)); // Y14
127  Ports.append(new Port( 50, 80)); // Y13
128  Ports.append(new Port( 50, 70)); // Y12
129  Ports.append(new Port( 50, 60)); // Y11
130  Ports.append(new Port( 50, 50)); // Y10
131  Ports.append(new Port( 50, 40)); // Y9
132  Ports.append(new Port( 50, 30)); // Y8
133  Ports.append(new Port( 50, 20)); // Y7
134  Ports.append(new Port( 50, 10)); // Y6
135  Ports.append(new Port( 50, 0)); // Y5
136  Ports.append(new Port( 50,-10)); // Y4
137  Ports.append(new Port( 50,-20)); // Y3
138  Ports.append(new Port( 50,-30)); // Y2
139  Ports.append(new Port( 50,-40)); // Y1
140  Ports.append(new Port( 50,-50)); // Y0
141 
142  x1 = -50; y1 = -94;
143  x2 = 50; y2 = 114;
144 }
145 
146 QString dmux4to16::vhdlCode( int )
147 {
148  QString s="";
149 
150  QString td = Props.at(1)->Value; // delay time
151  if(!VHDL_Delay(td, Name)) return td; // time has not VHDL format
152  td += ";\n";
153 
154  QString En = Ports.at(0)->Connection->Name;
155  QString A = Ports.at(1)->Connection->Name;
156  QString B = Ports.at(2)->Connection->Name;
157  QString C = Ports.at(3)->Connection->Name;
158  QString D = Ports.at(4)->Connection->Name;
159  QString Y15 = Ports.at(5)->Connection->Name;
160  QString Y14 = Ports.at(6)->Connection->Name;
161  QString Y13 = Ports.at(7)->Connection->Name;
162  QString Y12 = Ports.at(8)->Connection->Name;
163  QString Y11 = Ports.at(9)->Connection->Name;
164  QString Y10 = Ports.at(10)->Connection->Name;
165  QString Y9 = Ports.at(11)->Connection->Name;
166  QString Y8 = Ports.at(12)->Connection->Name;
167  QString Y7 = Ports.at(13)->Connection->Name;
168  QString Y6 = Ports.at(14)->Connection->Name;
169  QString Y5 = Ports.at(15)->Connection->Name;
170  QString Y4 = Ports.at(16)->Connection->Name;
171  QString Y3 = Ports.at(17)->Connection->Name;
172  QString Y2 = Ports.at(18)->Connection->Name;
173  QString Y1 = Ports.at(19)->Connection->Name;
174  QString Y0 = Ports.at(20)->Connection->Name;
175 
176  s = "\n "+Name+":process ("+En+", "+A+", "+B+", "+C+", "+D+")\n"+
177  " begin\n" +
178  " "+Y0+" <= "+"(not "+En+") and (not "+D+") and (not "+C+") and (not "+B+") and (not "+A+")"+td+
179  " "+Y1+" <= "+"(not "+En+") and (not "+D+") and (not "+C+") and (not "+B+") and "+A+td+
180  " "+Y2+" <= "+"(not "+En+") and (not "+D+") and (not "+C+") and "+B+" and (not "+A+")"+td+
181  " "+Y3+" <= "+"(not "+En+") and (not "+D+") and (not "+C+") and "+B+" and "+A+td+
182  " "+Y4+" <= "+"(not "+En+") and (not "+D+") and "+C+" and (not "+B+") and (not "+A+")"+td+
183  " "+Y5+" <= "+"(not "+En+") and (not "+D+") and "+C+" and (not "+B+") and "+A+td+
184  " "+Y6+" <= "+"(not "+En+") and (not "+D+") and "+C+" and "+B+" and (not "+A+")"+td+
185  " "+Y7+" <= "+"(not "+En+") and (not "+D+") and "+C+" and "+B+" and "+A+td+
186  " "+Y8+" <= "+"(not "+En+") and "+D+" and (not "+C+") and (not "+B+") and (not "+A+")"+td+
187  " "+Y9+" <= "+"(not "+En+") and "+D+" and (not "+C+") and (not "+B+") and "+A+td+
188  " "+Y10+" <= "+"(not "+En+") and "+D+" and (not "+C+") and "+B+" and (not "+A+")"+td+
189  " "+Y11+" <= "+"(not "+En+") and "+D+" and (not "+C+") and "+B+" and "+A+td+
190  " "+Y12+" <= "+"(not "+En+") and "+D+" and "+C+" and (not "+B+") and (not "+A+")"+td+
191  " "+Y13+" <= "+"(not "+En+") and "+D+" and "+C+" and (not "+B+") and "+A+td+
192  " "+Y14+" <= "+"(not "+En+") and "+D+" and "+C+" and "+B+" and (not "+A+")"+td+
193  " "+Y15+" <= "+"(not "+En+") and "+D+" and "+C+" and "+B+" and "+A+td+
194 
195  " end process;\n";
196  return s;
197 }
198 
200 {
201  QString td = Props.at(1)->Value; // delay time
202  if(!Verilog_Delay(td, Name)) return td; // time does not have VHDL format
203 
204  QString l = "";
205 
206  QString En = Ports.at(0)->Connection->Name;
207  QString A = Ports.at(1)->Connection->Name;
208  QString B = Ports.at(2)->Connection->Name;
209  QString C = Ports.at(3)->Connection->Name;
210  QString D = Ports.at(4)->Connection->Name;
211  QString Y15 = Ports.at(5)->Connection->Name;
212  QString Y14 = Ports.at(6)->Connection->Name;
213  QString Y13 = Ports.at(7)->Connection->Name;
214  QString Y12 = Ports.at(8)->Connection->Name;
215  QString Y11 = Ports.at(9)->Connection->Name;
216  QString Y10 = Ports.at(10)->Connection->Name;
217  QString Y9 = Ports.at(11)->Connection->Name;
218  QString Y8 = Ports.at(12)->Connection->Name;
219  QString Y7 = Ports.at(13)->Connection->Name;
220  QString Y6 = Ports.at(14)->Connection->Name;
221  QString Y5 = Ports.at(15)->Connection->Name;
222  QString Y4 = Ports.at(16)->Connection->Name;
223  QString Y3 = Ports.at(17)->Connection->Name;
224  QString Y2 = Ports.at(18)->Connection->Name;
225  QString Y1 = Ports.at(19)->Connection->Name;
226  QString Y0 = Ports.at(20)->Connection->Name;
227 
228  QString Y15R = "net_reg" + Name + Y15;
229  QString Y14R = "net_reg" + Name + Y14;
230  QString Y13R = "net_reg" + Name + Y13;
231  QString Y12R = "net_reg" + Name + Y12;
232  QString Y11R = "net_reg" + Name + Y11;
233  QString Y10R = "net_reg" + Name + Y10;
234  QString Y9R = "net_reg" + Name + Y9;
235  QString Y8R = "net_reg" + Name + Y8;
236  QString Y7R = "net_reg" + Name + Y7;
237  QString Y6R = "net_reg" + Name + Y6;
238  QString Y5R = "net_reg" + Name + Y5;
239  QString Y4R = "net_reg" + Name + Y4;
240  QString Y3R = "net_reg" + Name + Y3;
241  QString Y2R = "net_reg" + Name + Y2;
242  QString Y1R = "net_reg" + Name + Y1;
243  QString Y0R = "net_reg" + Name + Y0;
244 
245  l = "\n // " + Name + " 4to16 demux\n" +
246  " assign " + Y0 + " = " + Y0R + ";\n" +
247  " reg " + Y0R + " = 0;\n" +
248  " assign " + Y1 + " = " + Y1R + ";\n" +
249  " reg " + Y1R + " = 0;\n" +
250  " assign " + Y2 + " = " + Y2R + ";\n" +
251  " reg " + Y2R + " = 0;\n" +
252  " assign " + Y3 + " = " + Y3R + ";\n" +
253  " reg " + Y3R + " = 0;\n" +
254  " assign " + Y4 + " = " + Y4R + ";\n" +
255  " reg " + Y4R + " = 0;\n" +
256  " assign " + Y5 + " = " + Y5R + ";\n" +
257  " reg " + Y5R + " = 0;\n" +
258  " assign " + Y6 + " = " + Y6R + ";\n" +
259  " reg " + Y6R + " = 0;\n" +
260  " assign " + Y7 + " = " + Y7R + ";\n" +
261  " reg " + Y7R + " = 0;\n" +
262  " assign " + Y8 + " = " + Y8R + ";\n" +
263  " reg " + Y8R + " = 0;\n" +
264  " assign " + Y9 + " = " + Y9R + ";\n" +
265  " reg " + Y9R + " = 0;\n" +
266  " assign " + Y10 + " = " + Y10R + ";\n" +
267  " reg " + Y10R + " = 0;\n" +
268  " assign " + Y11 + " = " + Y11R + ";\n" +
269  " reg " + Y11R + " = 0;\n" +
270  " assign " + Y12 + " = " + Y12R + ";\n" +
271  " reg " + Y12R + " = 0;\n" +
272  " assign " + Y13 + " = " + Y13R + ";\n" +
273  " reg " + Y13R + " = 0;\n" +
274  " assign " + Y14 + " = " + Y14R + ";\n" +
275  " reg " + Y14R + " = 0;\n" +
276  " assign " + Y15 + " = " + Y15R + ";\n" +
277  " reg " + Y15R + " = 0;\n" +
278 
279  " always @ ("+En+" or "+A+" or "+B+" or "+C+" or "+D+")\n" +
280  " begin\n"+
281  " "+Y0R+" <="+td+" (~"+En+") && (~"+D+") && (~"+C+") && (~"+B+" ) && (~"+A+");\n"+
282  " "+Y1R+" <="+td+" (~"+En+") && (~"+D+") && (~"+C+") && (~"+B+" ) && "+A+";\n"+
283  " "+Y2R+" <="+td+" (~"+En+") && (~"+D+") && (~"+C+") && "+B+" && (~"+A+");\n"+
284  " "+Y3R+" <="+td+" (~"+En+") && (~"+D+") && (~"+C+") && "+B+" && "+A+";\n"+
285  " "+Y4R+" <="+td+" (~"+En+") && (~"+D+") && "+C+" && (~"+B+" ) && (~"+A+");\n"+
286  " "+Y5R+" <="+td+" (~"+En+") && (~"+D+") && "+C+" && (~"+B+" ) && "+A+";\n"+
287  " "+Y6R+" <="+td+" (~"+En+") && (~"+D+") && "+C+" && "+B+" && ( ~"+A+");\n"+
288  " "+Y7R+" <="+td+" (~"+En+") && (~"+D+") && "+C+" && "+B+" && "+A+";\n"+
289  " "+Y8R+" <="+td+" (~"+En+") && "+D+" && (~"+C+") && ( ~"+B+") && (~"+A+");\n"+
290  " "+Y9R+" <="+td+" (~"+En+") && "+D+" && (~"+C+") && ( ~"+B+") && "+A+";\n"+
291  " "+Y10R+" <="+td+" (~"+En+") && "+D+" && (~"+C+") && "+B+" && (~"+A+");\n"+
292  " "+Y11R+" <="+td+" (~"+En+") && "+D+" && (~"+C+") && "+B+" && "+A+";\n"+
293  " "+Y12R+" <="+td+" (~"+En+") && "+D+" && "+C+" && (~"+B+") && (~"+A+");\n"+
294  " "+Y13R+" <="+td+" (~"+En+") && "+D+" && "+C+" && (~"+B+") && "+A+";\n"+
295  " "+Y14R+" <="+td+" (~"+En+") && "+D+" && "+C+" && "+B+" && (~"+A+");\n"+
296  " "+Y15R+" <="+td+" (~"+En+") && "+D+" && "+C+" && "+B+" && "+A+";\n"+
297 
298  " end\n";
299 
300  return l;
301 }