Qucs-GUI
0.0.19
|
00001 /*************************************************************************** 00002 mux8to1 00003 --------- 00004 begin : December 2008 00005 copyright : (C) 2008 by Mike Brinson 00006 email : mbrin72043@yahoo.co.uk 00007 ***************************************************************************/ 00008 00009 /* 00010 * mux8to1.cpp - device implementations for mux8to1 module 00011 * 00012 * This is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License as published by 00014 * the Free Software Foundation; either version 2, or (at your option) 00015 * any later version. 00016 * 00017 */ 00018 #include "mux8to1.h" 00019 #include "node.h" 00020 #include "misc.h" 00021 00022 mux8to1::mux8to1() 00023 { 00024 Type = isComponent; // Analogue and digital component. 00025 Description = QObject::tr ("8to1 multiplexer verilog device"); 00026 00027 Props.append (new Property ("TR", "6", false, 00028 QObject::tr ("transfer function high scaling factor"))); 00029 Props.append (new Property ("Delay", "1 ns", false, 00030 QObject::tr ("output delay") 00031 +" ("+QObject::tr ("s")+")")); 00032 00033 createSymbol (); 00034 tx = x1 + 19; 00035 ty = y2 + 4; 00036 Model = "mux8to1"; 00037 Name = "Y"; 00038 } 00039 00040 Component * mux8to1::newOne() 00041 { 00042 mux8to1 * p = new mux8to1(); 00043 p->Props.getFirst()->Value = Props.getFirst()->Value; 00044 p->recreate(0); 00045 return p; 00046 } 00047 00048 Element * mux8to1::info(QString& Name, char * &BitmapFile, bool getNewOne) 00049 { 00050 Name = QObject::tr("8to1 Mux"); 00051 BitmapFile = (char *) "mux8to1"; 00052 00053 if(getNewOne) return new mux8to1(); 00054 return 0; 00055 } 00056 00057 void mux8to1::createSymbol() 00058 { 00059 Lines.append(new Line(-30, -80, 30,-80,QPen(Qt::darkBlue,2))); 00060 Lines.append(new Line( 30, -80, 30, 190,QPen(Qt::darkBlue,2))); 00061 Lines.append(new Line( 30, 190,-30, 190,QPen(Qt::darkBlue,2))); 00062 Lines.append(new Line(-30, 190,-30, -80,QPen(Qt::darkBlue,2))); 00063 00064 Lines.append(new Line(-50,-40,-40,-40,QPen(Qt::darkBlue,2))); //EN 00065 Lines.append(new Line(-50,-20,-30, -20,QPen(Qt::darkBlue,2))); //A 00066 Lines.append(new Line(-50, 0, -30, 0,QPen(Qt::darkBlue,2))); //B 00067 Lines.append(new Line(-50, 20, -30, 20,QPen(Qt::darkBlue,2))); //C 00068 00069 Lines.append(new Line(-50, 40, -30, 40,QPen(Qt::darkBlue,2))); //D0 00070 Lines.append(new Line(-50, 60, -30, 60,QPen(Qt::darkBlue,2))); //D1 00071 Lines.append(new Line(-50, 80, -30, 80,QPen(Qt::darkBlue,2))); //D2 00072 Lines.append(new Line(-50, 100,-30,100,QPen(Qt::darkBlue,2))); //D3 00073 Lines.append(new Line(-50, 120,-30,120,QPen(Qt::darkBlue,2))); //D4 00074 Lines.append(new Line(-50, 140,-30,140,QPen(Qt::darkBlue,2))); //D5 00075 Lines.append(new Line(-50, 160,-30,160,QPen(Qt::darkBlue,2))); //D6 00076 Lines.append(new Line(-50, 180,-30,180,QPen(Qt::darkBlue,2))); //D7 00077 Lines.append(new Line( 30, 60, 50, 60,QPen(Qt::darkBlue,2))); // Y 00078 00079 Arcs.append(new Arc( -40, -45, 10, 10, 0, 16*360, QPen(Qt::darkBlue,2))); 00080 00081 Texts.append(new Text(-17,-75, "MUX", Qt::darkBlue, 12.0)); 00082 00083 Texts.append(new Text(-25,-53, "En", Qt::darkBlue, 12.0)); 00084 Texts.append(new Text(-14,-13, "G", Qt::darkBlue, 12.0)); 00085 Texts.append(new Text(-1, -18, "}", Qt::darkBlue, 16.0)); 00086 Texts.append(new Text( 12,-22, "0", Qt::darkBlue, 12.0)); 00087 Texts.append(new Text( 12, -2, "7", Qt::darkBlue, 12.0)); 00088 00089 Texts.append(new Text(-25,-31, "0", Qt::darkBlue, 12.0)); 00090 Texts.append(new Text(-25, 7, "2", Qt::darkBlue, 12.0)); 00091 00092 Texts.append(new Text(-25, 27, "0", Qt::darkBlue, 12.0)); 00093 Texts.append(new Text(-25, 47, "1", Qt::darkBlue, 12.0)); 00094 Texts.append(new Text(-25, 67, "2", Qt::darkBlue, 12.0)); 00095 Texts.append(new Text(-25, 87, "3", Qt::darkBlue, 12.0)); 00096 Texts.append(new Text(-25,107, "4", Qt::darkBlue, 12.0)); 00097 Texts.append(new Text(-25,127, "5", Qt::darkBlue, 12.0)); 00098 Texts.append(new Text(-25,147, "6", Qt::darkBlue, 12.0)); 00099 Texts.append(new Text(-25,167, "7", Qt::darkBlue, 12.0)); 00100 00101 Lines.append(new Line(11, 0, 23, 0, QPen(Qt::darkBlue,2))); 00102 00103 Ports.append(new Port(-50,-40)); // En 00104 Ports.append(new Port(-50,-20)); // A 00105 Ports.append(new Port(-50, 0)); // B 00106 Ports.append(new Port(-50, 20)); // C 00107 Ports.append(new Port(-50, 40)); // D0 00108 Ports.append(new Port(-50, 60)); // D1 00109 Ports.append(new Port(-50, 80)); // D2 00110 Ports.append(new Port(-50,100)); // D3 00111 Ports.append(new Port(-50,120)); // D4 00112 Ports.append(new Port(-50,140)); // D5 00113 Ports.append(new Port(-50,160)); // D6 00114 Ports.append(new Port(-50,180)); // D7 00115 Ports.append(new Port( 50, 60)); // Y 00116 00117 x1 = -50; y1 = -84; 00118 x2 = 50; y2 = 194; 00119 } 00120 00121 QString mux8to1::vhdlCode( int ) 00122 { 00123 QString s=""; 00124 00125 QString td = Props.at(1)->Value; // delay time 00126 if(!misc::VHDL_Delay(td, Name)) return td; // time has not VHDL format 00127 td += ";\n"; 00128 00129 QString En = Ports.at(0)->Connection->Name; 00130 QString A = Ports.at(1)->Connection->Name; 00131 QString B = Ports.at(2)->Connection->Name; 00132 QString C = Ports.at(3)->Connection->Name; 00133 QString D0 = Ports.at(4)->Connection->Name; 00134 QString D1 = Ports.at(5)->Connection->Name; 00135 QString D2 = Ports.at(6)->Connection->Name; 00136 QString D3 = Ports.at(7)->Connection->Name; 00137 QString D4 = Ports.at(8)->Connection->Name; 00138 QString D5 = Ports.at(9)->Connection->Name; 00139 QString D6 = Ports.at(10)->Connection->Name; 00140 QString D7 = Ports.at(11)->Connection->Name; 00141 QString y = Ports.at(12)->Connection->Name; 00142 00143 s = "\n " + Name + ":process (" + En + ", " + A + ", " + B + ", " + C + ", " + 00144 D0 + ", " + D1 + ", " + D2 + ", " + D3 + ", " + 00145 D4 + ", " + D5 + ", " + D6 + ", " + D7 + ")\n" + 00146 " begin\n " + 00147 y + " <= " + "(not " + En + ") and ((" + D7 + " and " + C + " and " + B + " and " + A + ") or\n" + 00148 " (" + D6 + " and " + C + " and " + B + " and not "+ A + ") or\n" + 00149 " (" + D5 + " and " + C + " and not "+ B + " and " + A + ") or\n" + 00150 " (" + D4 + " and " + C + " and not " + B + " and not "+A + ") or\n" + 00151 " (" + D3 + " and not " + C + " and " + B + " and " + A + ") or\n" + 00152 " (" + D2 + " and not " + C + " and " + B + " and not "+ A + ") or\n" + 00153 " (" + D1 + " and not " + C + " and not "+ B + " and " + A + ") or\n" + 00154 " (" + D0 + " and not " + C + " and not " + B + " and not "+A + "))" + td + 00155 " end process;\n"; 00156 return s; 00157 } 00158 00159 QString mux8to1::verilogCode( int ) 00160 { 00161 QString td = Props.at(1)->Value; // delay time 00162 if(!misc::Verilog_Delay(td, Name)) return td; // time does not have VHDL format 00163 00164 QString l = ""; 00165 00166 QString En = Ports.at(0)->Connection->Name; 00167 QString A = Ports.at(1)->Connection->Name; 00168 QString B = Ports.at(2)->Connection->Name; 00169 QString C = Ports.at(3)->Connection->Name; 00170 QString D0 = Ports.at(4)->Connection->Name; 00171 QString D1 = Ports.at(5)->Connection->Name; 00172 QString D2 = Ports.at(6)->Connection->Name; 00173 QString D3 = Ports.at(7)->Connection->Name; 00174 QString D4 = Ports.at(8)->Connection->Name; 00175 QString D5 = Ports.at(9)->Connection->Name; 00176 QString D6 = Ports.at(10)->Connection->Name; 00177 QString D7 = Ports.at(11)->Connection->Name; 00178 QString y = Ports.at(12)->Connection->Name; 00179 00180 QString v = "net_reg" + Name + y; 00181 00182 l = "\n // " + Name + " 8to1 mux\n" + 00183 " assign " + y + " = " + v + ";\n" + 00184 " reg " + v + " = 0;\n" + 00185 " always @ (" + En + " or " + A + " or " + B + " or " + C + " or " + 00186 D0 + " or " + D1 + " or " + D2 + " or " + D3 + " or " + 00187 D4 + " or " + D5 + " or " + D6 + " or " + D7 + ")\n" + 00188 " " + v + " <=" + td + " (" + D7 + " && " + C + " && " + B + " && " + A +")" + " ||\n" + 00189 " (" + D6 + " && " + C + " && " + B + " && ~"+ A +")" + " ||\n" + 00190 " (" + D5 + " && " + C + " && ~"+ B + " && " + A +")" + " ||\n" + 00191 " (" + D4 + " && " + C + " && ~"+ B + " && ~"+ A +")" + " ||\n" + 00192 " (" + D3 + " && ~" + C + " && " + B + " && " + A +")" + " ||\n" + 00193 " (" + D2 + " && ~" + C + " && " + B + " && ~"+ A +")" + " ||\n" + 00194 " (" + D1 + " && ~" + C + " && ~"+ B + " && " + A +")" + " ||\n" + 00195 " (" + D0 + " && ~" + C + " && ~"+ B + " && ~"+ A +")" + ";\n" ; 00196 00197 return l; 00198 }