Qucs-GUI
0.0.19
|
00001 /*************************************************************************** 00002 greytobinary4bit 00003 ------------------- 00004 begin : December 2008 00005 copyright : (C) 2008 by Mike Brinson 00006 email : mbrin72043@yahoo.co.uk 00007 ***************************************************************************/ 00008 00009 /* 00010 * greytobinary4bit.cpp - device implementations for greytobinary4bit 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 "greytobinary4bit.h" 00019 #include "node.h" 00020 #include "misc.h" 00021 00022 greytobinary4bit::greytobinary4bit() 00023 { 00024 Type = isComponent; // Analogue and digital component. 00025 Description = QObject::tr ("4bit Gray to binary converter verilog device"); 00026 00027 Props.append (new Property ("TR", "6", false, 00028 QObject::tr ("transfer function 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 = "greytobinary4bit"; 00037 Name = "Y"; 00038 } 00039 00040 Component * greytobinary4bit::newOne() 00041 { 00042 greytobinary4bit * p = new greytobinary4bit(); 00043 p->Props.getFirst()->Value = Props.getFirst()->Value; 00044 p->recreate(0); 00045 return p; 00046 } 00047 00048 Element * greytobinary4bit::info(QString& Name, char * &BitmapFile, bool getNewOne) 00049 { 00050 Name = QObject::tr("4Bit Gray2Bin"); 00051 BitmapFile = (char *) "greytobinary4bit"; 00052 00053 if(getNewOne) return new greytobinary4bit(); 00054 return 0; 00055 } 00056 00057 void greytobinary4bit::createSymbol() 00058 { 00059 Lines.append(new Line(-30, -60, 30,-60,QPen(Qt::darkBlue,2))); 00060 Lines.append(new Line( 30, -60, 30, 40,QPen(Qt::darkBlue,2))); 00061 Lines.append(new Line( 30, 40,-30, 40,QPen(Qt::darkBlue,2))); 00062 Lines.append(new Line(-30, 40,-30, -60,QPen(Qt::darkBlue,2))); 00063 00064 Lines.append(new Line(-50,-30,-30,-30,QPen(Qt::darkBlue,2))); // G0 00065 Lines.append(new Line(-50,-10,-30,-10,QPen(Qt::darkBlue,2))); // G1 00066 Lines.append(new Line(-50, 10,-30, 10,QPen(Qt::darkBlue,2))); // G2 00067 Lines.append(new Line(-50, 30,-30, 30,QPen(Qt::darkBlue,2))); // G3 00068 00069 Lines.append(new Line( 30, 30, 50, 30,QPen(Qt::darkBlue,2))); // B3 00070 Lines.append(new Line( 30, 10, 50, 10,QPen(Qt::darkBlue,2))); // B2 00071 Lines.append(new Line( 30,-10, 50,-10,QPen(Qt::darkBlue,2))); // B1 00072 Lines.append(new Line( 30,-30, 50,-30,QPen(Qt::darkBlue,2))); // B0 00073 00074 Texts.append(new Text(-16,-59, "G", Qt::darkBlue, 12.0)); 00075 Texts.append(new Text( -2,-59, "/", Qt::darkBlue, 12.0)); 00076 Texts.append(new Text( 5,-59, "B", Qt::darkBlue, 12.0)); 00077 00078 Texts.append(new Text(-25,-43, "0", Qt::darkBlue, 12.0)); 00079 Texts.append(new Text(-25,-23, "1", Qt::darkBlue, 12.0)); 00080 Texts.append(new Text(-25, -3, "2", Qt::darkBlue, 12.0)); 00081 Texts.append(new Text(-25, 17, "3", Qt::darkBlue, 12.0)); 00082 00083 Texts.append(new Text( 15,-43, "0", Qt::darkBlue, 12.0)); 00084 Texts.append(new Text( 15,-23, "1", Qt::darkBlue, 12.0)); 00085 Texts.append(new Text( 15, -3, "2", Qt::darkBlue, 12.0)); 00086 Texts.append(new Text( 15, 17, "3", Qt::darkBlue, 12.0)); 00087 00088 Ports.append(new Port(-50,-30)); // G0 00089 Ports.append(new Port(-50,-10)); // G1 00090 Ports.append(new Port(-50, 10)); // G2 00091 Ports.append(new Port(-50, 30)); // G3 00092 00093 Ports.append(new Port( 50, 30)); // B3 00094 Ports.append(new Port( 50, 10)); // B2 00095 Ports.append(new Port( 50,-10)); // B1 00096 Ports.append(new Port( 50,-30)); // B0 00097 00098 x1 = -50; y1 = -64; 00099 x2 = 50; y2 = 44; 00100 } 00101 00102 QString greytobinary4bit::vhdlCode( int ) 00103 { 00104 QString s=""; 00105 00106 QString td = Props.at(1)->Value; // delay time 00107 if(!misc::VHDL_Delay(td, Name)) return td; // time has not VHDL format 00108 td += ";\n"; 00109 00110 QString G0 = Ports.at(0)->Connection->Name; 00111 QString G1 = Ports.at(1)->Connection->Name; 00112 QString G2 = Ports.at(2)->Connection->Name; 00113 QString G3 = Ports.at(3)->Connection->Name; 00114 QString B3 = Ports.at(4)->Connection->Name; 00115 QString B2 = Ports.at(5)->Connection->Name; 00116 QString B1 = Ports.at(6)->Connection->Name; 00117 QString B0 = Ports.at(7)->Connection->Name; 00118 00119 s = "\n " + Name + ":process ("+G0+", "+G1+", "+G2+", "+G3+")\n"+ 00120 " begin\n"+ 00121 " "+B3+" <= "+G3+td+ 00122 " "+B2+" <= "+G3+" xor "+G2+td+ 00123 " "+B1+" <= "+G3+" xor "+G2+" xor "+G1+td+ 00124 " "+B0+" <= "+G3+" xor "+G2+" xor "+G1+" xor "+G0+td+ 00125 " end process;\n"; 00126 return s; 00127 } 00128 00129 QString greytobinary4bit::verilogCode( int ) 00130 { 00131 QString td = Props.at(1)->Value; // delay time 00132 if(!misc::Verilog_Delay(td, Name)) return td; // time does not have VHDL format 00133 00134 QString G0 = Ports.at(0)->Connection->Name; 00135 QString G1 = Ports.at(1)->Connection->Name; 00136 QString G2 = Ports.at(2)->Connection->Name; 00137 QString G3 = Ports.at(3)->Connection->Name; 00138 QString B3 = Ports.at(4)->Connection->Name; 00139 QString B2 = Ports.at(5)->Connection->Name; 00140 QString B1 = Ports.at(6)->Connection->Name; 00141 QString B0 = Ports.at(7)->Connection->Name; 00142 00143 QString l = ""; 00144 00145 QString B0R = "net_reg" + Name + B0; 00146 QString B1R = "net_reg" + Name + B1; 00147 QString B2R = "net_reg" + Name + B2; 00148 QString B3R = "net_reg" + Name + B3; 00149 00150 l = "\n // " + Name + " 4bit Gray to binary\n" + 00151 " assign " + B0 + " = " + B0R + ";\n" + 00152 " reg " + B0R + " = 0;\n" + 00153 " assign " + B1 + " = " + B1R + ";\n" + 00154 " reg " + B1R + " = 0;\n" + 00155 " assign " + B2 + " = " + B2R + ";\n" + 00156 " reg " + B2R + " = 0;\n" + 00157 " assign " + B3 + " = " + B3R + ";\n" + 00158 " reg " + B3R + " = 0;\n" + 00159 " always @ ("+G0+" or "+G1+" or "+G2+" or "+G3+")\n" + 00160 " begin\n"+ 00161 " "+B3R+" <="+td+" "+G3+";\n"+ 00162 " "+B2R+" <="+td+" "+G3+" ^ "+G2+";\n"+ 00163 " "+B1R+" <="+td+" "+G3+" ^ "+G2+" ^ "+G1+";\n"+ 00164 " "+B0R+" <="+td+" "+G3+" ^ "+G2+" ^ "+G1+" ^ "+G0+";\n"+ 00165 " end\n"; 00166 return l; 00167 } 00168