Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mux4to1.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  mux4to1
3  ---------
4  begin : December 2008
5  copyright : (C) 2008 by Mike Brinson
6  email : mbrin72043@yahoo.co.uk
7  ***************************************************************************/
8 
9 /*
10  * mux4to1.cpp - device implementations for mux4to1 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 #include <QtGui>
19 #include "mux4to1.h"
20 #include "node.h"
21 #include "main.h"
22 
24 {
25  Type = isComponent; // Analogue and digital component.
26  Description = QObject::tr ("4to1 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 = "mux4to1";
38  Name = "Y";
39 }
40 
42 {
43  mux4to1 * p = new mux4to1();
44  p->Props.getFirst()->Value = Props.getFirst()->Value;
45  p->recreate(0);
46  return p;
47 }
48 
49 Element * mux4to1::info(QString& Name, char * &BitmapFile, bool getNewOne)
50 {
51  Name = QObject::tr("4to1 Mux");
52  BitmapFile = (char *) "mux4to1";
53 
54  if(getNewOne) return new mux4to1();
55  return 0;
56 }
57 
59 {
60  Lines.append(new Line(-30, -80, 30,-80,QPen(Qt::darkBlue,2)));
61  Lines.append(new Line( 30, -80, 30, 100,QPen(Qt::darkBlue,2)));
62  Lines.append(new Line( 30, 100,-30, 100,QPen(Qt::darkBlue,2)));
63  Lines.append(new Line(-30, 100,-30, -80,QPen(Qt::darkBlue,2)));
64 
65  Lines.append(new Line(-50,-40,-40,-40,QPen(Qt::darkBlue,2)));
66  Lines.append(new Line(-50,-20,-30, -20,QPen(Qt::darkBlue,2)));
67  Lines.append(new Line(-50, 0, -30, 0,QPen(Qt::darkBlue,2)));
68  Lines.append(new Line(-50, 30, -30, 30,QPen(Qt::darkBlue,2)));
69  Lines.append(new Line(-50, 50,-30, 50,QPen(Qt::darkBlue,2)));
70  Lines.append(new Line(-50, 70, -30, 70,QPen(Qt::darkBlue,2)));
71  Lines.append(new Line(-50, 90, -30, 90,QPen(Qt::darkBlue,2)));
72 
73  Lines.append(new Line( 30, 10, 50, 10,QPen(Qt::darkBlue,2)));
74 
75  Arcs.append(new Arc( -40, -45, 10, 10, 0, 16*360, QPen(Qt::darkBlue,2)));
76 
77  Texts.append(new Text(-17,-75, "MUX", Qt::darkBlue, 12.0));
78 
79  Texts.append(new Text(-25,-53, "En", Qt::darkBlue, 12.0));
80  Texts.append(new Text(-14,-23, "G", Qt::darkBlue, 12.0));
81  Texts.append(new Text(-1, -28, "}", Qt::darkBlue, 16.0));
82  Texts.append(new Text( 12,-30, "0", Qt::darkBlue, 12.0));
83  Texts.append(new Text( 12,-10, "3", Qt::darkBlue, 12.0));
84 
85  Texts.append(new Text(-25,-31, "0", Qt::darkBlue, 12.0));
86  Texts.append(new Text(-25,-11, "1", Qt::darkBlue, 12.0));
87 
88  Texts.append(new Text(-25, 17, "0", Qt::darkBlue, 12.0));
89  Texts.append(new Text(-25, 37, "1", Qt::darkBlue, 12.0));
90  Texts.append(new Text(-25, 57, "2", Qt::darkBlue, 12.0));
91  Texts.append(new Text(-25, 77, "3", Qt::darkBlue, 12.0));
92 
93  Lines.append(new Line(11, -8, 23, -8, QPen(Qt::darkBlue,2)));
94 
95  Ports.append(new Port(-50,-40)); // En
96  Ports.append(new Port(-50,-20)); // A
97  Ports.append(new Port(-50, 0)); // B
98  Ports.append(new Port(-50, 30)); // D0
99  Ports.append(new Port(-50, 50)); // D1
100  Ports.append(new Port(-50, 70)); // D2
101  Ports.append(new Port(-50, 90)); // D3
102  Ports.append(new Port( 50, 10)); // Y
103 
104  x1 = -50; y1 = -84;
105  x2 = 50; y2 = 104;
106 }
107 
108 QString mux4to1::vhdlCode( int )
109 {
110  QString s="";
111 
112  QString td = Props.at(1)->Value; // delay time
113  if(!VHDL_Delay(td, Name)) return td; // time has not VHDL format
114  td += ";\n";
115 
116  QString En = Ports.at(0)->Connection->Name;
117  QString A = Ports.at(1)->Connection->Name;
118  QString B = Ports.at(2)->Connection->Name;
119  QString D0 = Ports.at(3)->Connection->Name;
120  QString D1 = Ports.at(4)->Connection->Name;
121  QString D2 = Ports.at(5)->Connection->Name;
122  QString D3 = Ports.at(6)->Connection->Name;
123  QString y = Ports.at(7)->Connection->Name;
124 
125  s = "\n " + Name + ":process (" + En + ", " + A + ", " + B + ", " +
126  D0 + ", " + D1 + ", " + D2 + ", " + D3 + ")\n" +
127  " begin\n " +
128  y + " <= " + "(not " + En + ") and ((" + D3 + " and " + B + " and " + A + ") or\n" +
129  " (" + D2 + " and " + B + " and not " + A + ") or\n" +
130  " (" + D1 + " and not " + B + " and " + A + ") or\n" +
131  " (" + D0 + " and not " + B + " and not " + A + ")" + ")" + td +
132  " end process;\n";
133  return s;
134 }
135 
136 QString mux4to1::verilogCode( int )
137 {
138  QString td = Props.at(1)->Value; // delay time
139  if(!Verilog_Delay(td, Name)) return td; // time does not have VHDL format
140 
141  QString l = "";
142 
143  QString En = Ports.at(0)->Connection->Name;
144  QString A = Ports.at(1)->Connection->Name;
145  QString B = Ports.at(2)->Connection->Name;
146  QString D0 = Ports.at(3)->Connection->Name;
147  QString D1 = Ports.at(4)->Connection->Name;
148  QString D2 = Ports.at(5)->Connection->Name;
149  QString D3 = Ports.at(6)->Connection->Name;
150  QString y = Ports.at(7)->Connection->Name;
151 
152  QString v = "net_reg" + Name + y;
153 
154  l = "\n // " + Name + " 4to1 mux\n" +
155  " assign " + y + " = " + v + ";\n" +
156  " reg " + v + " = 0;\n" +
157  " always @ (" + En + " or " + A + " or " + B + " or "
158  + D0 + " or " + D1 + " or " + D2 + " or " + D0 + ")\n" +
159  " " + v + " <=" + td + " (" + D3 + " && " + B + " && " + A +")" + " ||\n" +
160  " (" + D2 + " && " + B + " && ~"+ A +")" + " ||\n" +
161  " (" + D1 + " && ~"+ B + " && " + A +")" + " ||\n" +
162  " (" + D0 + " && ~"+ B + " && ~"+ A +");\n";
163 
164  return l;
165 }
166 
Q3PtrList< Line > Lines
Definition: component.h:67
QString vhdlCode(int)
Definition: mux4to1.cpp:108
int Type
Definition: element.h:152
Definition: element.h:55
int y1
Definition: element.h:153
bool VHDL_Delay(QString &td, const QString &Name)
Definition: main.cpp:493
Q3PtrList< struct Arc > Arcs
Definition: component.h:68
void createSymbol()
Definition: mux4to1.cpp:58
int tx
Definition: component.h:78
int y2
Definition: element.h:153
Definition: element.h:72
int x1
Definition: element.h:153
bool Verilog_Delay(QString &td, const QString &Name)
Definition: main.cpp:555
Definitions and declarations for the main application.
int ty
Definition: component.h:78
Q3PtrList< Property > Props
Definition: component.h:72
mux4to1()
Definition: mux4to1.cpp:23
Definition: element.h:82
Definition: element.h:48
Superclass of all schematic drawing elements.
Definition: element.h:142
Q3PtrList< Port > Ports
Definition: component.h:70
Component * newOne()
Definition: mux4to1.cpp:41
QString Name
Definition: component.h:80
Q3PtrList< Text > Texts
Definition: component.h:71
QString verilogCode(int)
Definition: mux4to1.cpp:136
QString Model
Definition: component.h:80
QString Description
Definition: component.h:81
#define isComponent
Definition: element.h:110
static Element * info(QString &, char *&, bool getNewOne=false)
Definition: mux4to1.cpp:49
int x2
Definition: element.h:153
virtual void recreate(Schematic *)
Definition: component.h:39