My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mux8to1.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  mux8to1
3  ---------
4  begin : December 2008
5  copyright : (C) 2008 by Mike Brinson
6  email : mbrin72043@yahoo.co.uk
7  ***************************************************************************/
8 
9 /*
10  * mux8to1.cpp - device implementations for mux8to1 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 "mux8to1.h"
20 #include "node.h"
21 #include "main.h"
22 
24 {
25  Type = isComponent; // Analogue and digital component.
26  Description = QObject::tr ("8to1 multiplexer 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 = "mux8to1";
38  Name = "Y";
39 }
40 
42 {
43  mux8to1 * p = new mux8to1();
44  p->Props.getFirst()->Value = Props.getFirst()->Value;
45  p->recreate(0);
46  return p;
47 }
48 
49 Element * mux8to1::info(QString& Name, char * &BitmapFile, bool getNewOne)
50 {
51  Name = QObject::tr("8to1 Mux");
52  BitmapFile = (char *) "mux8to1";
53 
54  if(getNewOne) return new mux8to1();
55  return 0;
56 }
57 
59 {
60  Lines.append(new Line(-30, -80, 30,-80,QPen(QPen::darkBlue,2)));
61  Lines.append(new Line( 30, -80, 30, 190,QPen(QPen::darkBlue,2)));
62  Lines.append(new Line( 30, 190,-30, 190,QPen(QPen::darkBlue,2)));
63  Lines.append(new Line(-30, 190,-30, -80,QPen(QPen::darkBlue,2)));
64 
65  Lines.append(new Line(-50,-40,-40,-40,QPen(QPen::darkBlue,2))); //EN
66  Lines.append(new Line(-50,-20,-30, -20,QPen(QPen::darkBlue,2))); //A
67  Lines.append(new Line(-50, 0, -30, 0,QPen(QPen::darkBlue,2))); //B
68  Lines.append(new Line(-50, 20, -30, 20,QPen(QPen::darkBlue,2))); //C
69 
70  Lines.append(new Line(-50, 40, -30, 40,QPen(QPen::darkBlue,2))); //D0
71  Lines.append(new Line(-50, 60, -30, 60,QPen(QPen::darkBlue,2))); //D1
72  Lines.append(new Line(-50, 80, -30, 80,QPen(QPen::darkBlue,2))); //D2
73  Lines.append(new Line(-50, 100,-30,100,QPen(QPen::darkBlue,2))); //D3
74  Lines.append(new Line(-50, 120,-30,120,QPen(QPen::darkBlue,2))); //D4
75  Lines.append(new Line(-50, 140,-30,140,QPen(QPen::darkBlue,2))); //D5
76  Lines.append(new Line(-50, 160,-30,160,QPen(QPen::darkBlue,2))); //D6
77  Lines.append(new Line(-50, 180,-30,180,QPen(QPen::darkBlue,2))); //D7
78  Lines.append(new Line( 30, 60, 50, 60,QPen(QPen::darkBlue,2))); // Y
79 
80  Arcs.append(new Arc( -40, -45, 10, 10, 0, 16*360, QPen(QPen::darkBlue,2)));
81 
82  Texts.append(new Text(-17,-75, "MUX", QPen::darkBlue, 12.0));
83 
84  Texts.append(new Text(-25,-53, "En", QPen::darkBlue, 12.0));
85  Texts.append(new Text(-14,-13, "G", QPen::darkBlue, 12.0));
86  Texts.append(new Text(-1, -18, "}", QPen::darkBlue, 16.0));
87  Texts.append(new Text( 12,-22, "0", QPen::darkBlue, 12.0));
88  Texts.append(new Text( 12, -2, "7", QPen::darkBlue, 12.0));
89 
90  Texts.append(new Text(-25,-31, "0", QPen::darkBlue, 12.0));
91  Texts.append(new Text(-25, 7, "2", QPen::darkBlue, 12.0));
92 
93  Texts.append(new Text(-25, 27, "0", QPen::darkBlue, 12.0));
94  Texts.append(new Text(-25, 47, "1", QPen::darkBlue, 12.0));
95  Texts.append(new Text(-25, 67, "2", QPen::darkBlue, 12.0));
96  Texts.append(new Text(-25, 87, "3", QPen::darkBlue, 12.0));
97  Texts.append(new Text(-25,107, "4", QPen::darkBlue, 12.0));
98  Texts.append(new Text(-25,127, "5", QPen::darkBlue, 12.0));
99  Texts.append(new Text(-25,147, "6", QPen::darkBlue, 12.0));
100  Texts.append(new Text(-25,167, "7", QPen::darkBlue, 12.0));
101 
102  Lines.append(new Line(11, 0, 23, 0, QPen(QPen::darkBlue,2)));
103 
104  Ports.append(new Port(-50,-40)); // En
105  Ports.append(new Port(-50,-20)); // A
106  Ports.append(new Port(-50, 0)); // B
107  Ports.append(new Port(-50, 20)); // C
108  Ports.append(new Port(-50, 40)); // D0
109  Ports.append(new Port(-50, 60)); // D1
110  Ports.append(new Port(-50, 80)); // D2
111  Ports.append(new Port(-50,100)); // D3
112  Ports.append(new Port(-50,120)); // D4
113  Ports.append(new Port(-50,140)); // D5
114  Ports.append(new Port(-50,160)); // D6
115  Ports.append(new Port(-50,180)); // D7
116  Ports.append(new Port( 50, 60)); // Y
117 
118  x1 = -50; y1 = -84;
119  x2 = 50; y2 = 194;
120 }
121 
122 QString mux8to1::vhdlCode( int )
123 {
124  QString s="";
125 
126  QString td = Props.at(1)->Value; // delay time
127  if(!VHDL_Delay(td, Name)) return td; // time has not VHDL format
128  td += ";\n";
129 
130  QString En = Ports.at(0)->Connection->Name;
131  QString A = Ports.at(1)->Connection->Name;
132  QString B = Ports.at(2)->Connection->Name;
133  QString C = Ports.at(3)->Connection->Name;
134  QString D0 = Ports.at(4)->Connection->Name;
135  QString D1 = Ports.at(5)->Connection->Name;
136  QString D2 = Ports.at(6)->Connection->Name;
137  QString D3 = Ports.at(7)->Connection->Name;
138  QString D4 = Ports.at(8)->Connection->Name;
139  QString D5 = Ports.at(9)->Connection->Name;
140  QString D6 = Ports.at(10)->Connection->Name;
141  QString D7 = Ports.at(11)->Connection->Name;
142  QString y = Ports.at(12)->Connection->Name;
143 
144  s = "\n " + Name + ":process (" + En + ", " + A + ", " + B + ", " + C + ", " +
145  D0 + ", " + D1 + ", " + D2 + ", " + D3 + ", " +
146  D4 + ", " + D5 + ", " + D6 + ", " + D7 + ")\n" +
147  " begin\n " +
148  y + " <= " + "(not " + En + ") and ((" + D7 + " and " + C + " and " + B + " and " + A + ") or\n" +
149  " (" + D6 + " and " + C + " and " + B + " and not "+ A + ") or\n" +
150  " (" + D5 + " and " + C + " and not "+ B + " and " + A + ") or\n" +
151  " (" + D4 + " and " + C + " and not " + B + " and not "+A + ") or\n" +
152  " (" + D3 + " and not " + C + " and " + B + " and " + A + ") or\n" +
153  " (" + D2 + " and not " + C + " and " + B + " and not "+ A + ") or\n" +
154  " (" + D1 + " and not " + C + " and not "+ B + " and " + A + ") or\n" +
155  " (" + D0 + " and not " + C + " and not " + B + " and not "+A + "))" + td +
156  " end process;\n";
157  return s;
158 }
159 
160 QString mux8to1::verilogCode( int )
161 {
162  QString td = Props.at(1)->Value; // delay time
163  if(!Verilog_Delay(td, Name)) return td; // time does not have VHDL format
164 
165  QString l = "";
166 
167  QString En = Ports.at(0)->Connection->Name;
168  QString A = Ports.at(1)->Connection->Name;
169  QString B = Ports.at(2)->Connection->Name;
170  QString C = Ports.at(3)->Connection->Name;
171  QString D0 = Ports.at(4)->Connection->Name;
172  QString D1 = Ports.at(5)->Connection->Name;
173  QString D2 = Ports.at(6)->Connection->Name;
174  QString D3 = Ports.at(7)->Connection->Name;
175  QString D4 = Ports.at(8)->Connection->Name;
176  QString D5 = Ports.at(9)->Connection->Name;
177  QString D6 = Ports.at(10)->Connection->Name;
178  QString D7 = Ports.at(11)->Connection->Name;
179  QString y = Ports.at(12)->Connection->Name;
180 
181  QString v = "net_reg" + Name + y;
182 
183  l = "\n // " + Name + " 8to1 mux\n" +
184  " assign " + y + " = " + v + ";\n" +
185  " reg " + v + " = 0;\n" +
186  " always @ (" + En + " or " + A + " or " + B + " or " + C + " or " +
187  D0 + " or " + D1 + " or " + D2 + " or " + D3 + " or " +
188  D4 + " or " + D5 + " or " + D6 + " or " + D7 + ")\n" +
189  " " + v + " <=" + td + " (" + D7 + " && " + C + " && " + B + " && " + A +")" + " ||\n" +
190  " (" + D6 + " && " + C + " && " + B + " && ~"+ A +")" + " ||\n" +
191  " (" + D5 + " && " + C + " && ~"+ B + " && " + A +")" + " ||\n" +
192  " (" + D4 + " && " + C + " && ~"+ B + " && ~"+ A +")" + " ||\n" +
193  " (" + D3 + " && ~" + C + " && " + B + " && " + A +")" + " ||\n" +
194  " (" + D2 + " && ~" + C + " && " + B + " && ~"+ A +")" + " ||\n" +
195  " (" + D1 + " && ~" + C + " && ~"+ B + " && " + A +")" + " ||\n" +
196  " (" + D0 + " && ~" + C + " && ~"+ B + " && ~"+ A +")" + ";\n" ;
197 
198  return l;
199 }