My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dmux2to4.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  dmux2to4
3  ----------
4  begin : December 2008
5  copyright : (C) 2008 by Mike Brinson
6  email : mbrin72043@yahoo.co.uk
7  ***************************************************************************/
8 
9 /*
10  * dmux2to4.cpp - device implementations for dmux2to4 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 "dmux2to4.h"
20 #include "node.h"
21 #include "main.h"
22 
24 {
25  Type = isComponent; // Analogue and digital component.
26  Description = QObject::tr ("2to4 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 = "dmux2to4";
38  Name = "Y";
39 }
40 
42 {
43  dmux2to4 * p = new dmux2to4();
44  p->Props.getFirst()->Value = Props.getFirst()->Value;
45  p->recreate(0);
46  return p;
47 }
48 
49 Element * dmux2to4::info(QString& Name, char * &BitmapFile, bool getNewOne)
50 {
51  Name = QObject::tr("2to4 Demux");
52  BitmapFile = (char *) "dmux2to4";
53 
54  if(getNewOne) return new dmux2to4();
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, 20,QPen(QPen::darkBlue,2)));
62  Lines.append(new Line( 30, 20,-30, 20,QPen(QPen::darkBlue,2)));
63  Lines.append(new Line(-30, 20,-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( 30, 10, 50, 10,QPen(QPen::darkBlue,2))); // Y3
69  Lines.append(new Line( 30,-10, 50,-10,QPen(QPen::darkBlue,2))); // Y2
70  Lines.append(new Line( 30,-30, 50,-30,QPen(QPen::darkBlue,2))); // Y1
71  Lines.append(new Line( 30,-50, 50,-50,QPen(QPen::darkBlue,2))); // Y0
72 
73  Arcs.append(new Arc( -40, -55, 10, 10, 0, 16*360, QPen(QPen::darkBlue,2)));
74 
75  Texts.append(new Text(-25,-85, "DMUX", QPen::darkBlue, 12.0));
76 
77  Texts.append(new Text(-28,-63, "En",QPen::darkBlue, 12.0));
78  Texts.append(new Text(-20,-33, "G", QPen::darkBlue, 12.0));
79  Texts.append(new Text(-8, -38, "}", QPen::darkBlue, 16.0));
80  Texts.append(new Text( 2, -40, "0", QPen::darkBlue, 12.0));
81  Texts.append(new Text( 2, -20, "3", QPen::darkBlue, 12.0));
82 
83  Texts.append(new Text(-28,-43, "0", QPen::darkBlue, 12.0));
84  Texts.append(new Text(-28,-23, "1", QPen::darkBlue, 12.0));
85 
86  Texts.append(new Text( 15,-63, "0", QPen::darkBlue, 12.0));
87  Texts.append(new Text( 15,-43, "1", QPen::darkBlue, 12.0));
88  Texts.append(new Text( 15,-23, "2", QPen::darkBlue, 12.0));
89  Texts.append(new Text( 15, -3, "3", QPen::darkBlue, 12.0));
90 
91  Lines.append(new Line(0, -18, 12, -18, QPen(QPen::darkBlue,2)));
92 
93  Ports.append(new Port(-50,-50)); // En
94  Ports.append(new Port(-50,-30)); // A
95  Ports.append(new Port(-50,-10)); // B
96  Ports.append(new Port( 50, 10)); // Y3
97  Ports.append(new Port( 50,-10)); // Y2
98  Ports.append(new Port( 50,-30)); // Y1
99  Ports.append(new Port( 50,-50)); // Y0
100 
101  x1 = -50; y1 = -94;
102  x2 = 50; y2 = 24;
103 }
104 
105 QString dmux2to4::vhdlCode( int )
106 {
107  QString s="";
108 
109  QString td = Props.at(1)->Value; // delay time
110  if(!VHDL_Delay(td, Name)) return td; // time has not VHDL format
111  td += ";\n";
112 
113  QString En = Ports.at(0)->Connection->Name;
114  QString A = Ports.at(1)->Connection->Name;
115  QString B = Ports.at(2)->Connection->Name;
116  QString Y3 = Ports.at(3)->Connection->Name;
117  QString Y2 = Ports.at(4)->Connection->Name;
118  QString Y1 = Ports.at(5)->Connection->Name;
119  QString Y0 = Ports.at(6)->Connection->Name;
120 
121  s = "\n "+Name+":process ("+En+", "+A+", "+B+")\n"+
122  " begin\n" +
123  " "+Y0+" <= "+"(not "+En+") and (not "+B+") and (not "+A+")"+td+
124  " "+Y1+" <= "+"(not "+En+") and (not "+B+") and "+A+td+
125  " "+Y2+" <= "+"(not "+En+") and "+B+" and (not "+A+")"+td+
126  " "+Y3+" <= "+"(not "+En+") and "+B+" and "+A+td+
127  " end process;\n" ;
128  return s;
129 }
130 
131 QString dmux2to4::verilogCode( int )
132 {
133  QString td = Props.at(1)->Value; // delay time
134  if(!Verilog_Delay(td, Name)) return td; // time does not have VHDL format
135 
136  QString l = "";
137 
138  QString En = Ports.at(0)->Connection->Name;
139  QString A = Ports.at(1)->Connection->Name;
140  QString B = Ports.at(2)->Connection->Name;
141  QString Y3 = Ports.at(3)->Connection->Name;
142  QString Y2 = Ports.at(4)->Connection->Name;
143  QString Y1 = Ports.at(5)->Connection->Name;
144  QString Y0 = Ports.at(6)->Connection->Name;
145 
146  QString Y3R = "net_reg" + Name + Y3;
147  QString Y2R = "net_reg" + Name + Y2;
148  QString Y1R = "net_reg" + Name + Y1;
149  QString Y0R = "net_reg" + Name + Y0;
150 
151  l = "\n // " + Name + " 2to4 demux\n" +
152  " assign " + Y0 + " = " + Y0R + ";\n" +
153  " reg " + Y0R + " = 0;\n" +
154  " assign " + Y1 + " = " + Y1R + ";\n" +
155  " reg " + Y1R + " = 0;\n" +
156  " assign " + Y2 + " = " + Y2R + ";\n" +
157  " reg " + Y2R + " = 0;\n" +
158  " assign " + Y3 + " = " + Y3R + ";\n" +
159  " reg " + Y3R + " = 0;\n" +
160 
161  " always @ ("+En+" or "+A+" or "+B+")\n" +
162  " begin\n"+
163  " "+Y0R+" <="+td+" (~"+En+") && (~"+B+") && (~"+A+")"+";\n" +
164  " "+Y1R+" <="+td+" (~"+En+") && (~"+B+") && ("+A+")"+";\n" +
165  " "+Y2R+" <="+td+" (~"+En+") && ("+B+") && (~"+A+")"+";\n" +
166  " "+Y3R+" <="+td+" (~"+En+") && ("+B+") && ("+A+")"+";\n" +
167  " end\n" ;
168 
169  return l;
170 }