Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/binarytogrey4bit.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                             binarytogrey4bit
00003                           -------------------
00004     begin                : December 2008
00005     copyright            : (C) 2008 by Mike Brinson
00006     email                : mbrin72043@yahoo.co.uk
00007  ***************************************************************************/
00008 
00009 /*
00010  * binarytogrey4bit.cpp - device implementations for binarytogrey4bit 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 "binarytogrey4bit.h"
00019 #include "node.h"
00020 #include "misc.h"
00021 
00022 binarytogrey4bit::binarytogrey4bit()
00023 {
00024   Type = isComponent; // Analogue and digital component.
00025   Description = QObject::tr ("4bit binary to Gray 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 = "binarytogrey4bit";
00037   Name  = "Y";
00038 }
00039 
00040 Component * binarytogrey4bit::newOne()
00041 {
00042   binarytogrey4bit * p = new binarytogrey4bit();
00043   p->Props.getFirst()->Value = Props.getFirst()->Value; 
00044   p->recreate(0); 
00045   return p;
00046 }
00047 
00048 Element * binarytogrey4bit::info(QString& Name, char * &BitmapFile, bool getNewOne)
00049 {
00050   Name = QObject::tr("4Bit Bin2Gray");
00051   BitmapFile = (char *) "binarytogrey4bit";
00052 
00053   if(getNewOne) return new binarytogrey4bit();
00054   return 0;
00055 }
00056 
00057 void binarytogrey4bit::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)));  // B0
00065   Lines.append(new Line(-50,-10,-30,-10,QPen(Qt::darkBlue,2)));  // B1
00066   Lines.append(new Line(-50, 10,-30, 10,QPen(Qt::darkBlue,2)));  // B2
00067   Lines.append(new Line(-50, 30,-30, 30,QPen(Qt::darkBlue,2)));  // B3
00068 
00069   Lines.append(new Line( 30, 30, 50, 30,QPen(Qt::darkBlue,2)));  // G3
00070   Lines.append(new Line( 30, 10, 50, 10,QPen(Qt::darkBlue,2)));  // G2
00071   Lines.append(new Line( 30,-10, 50,-10,QPen(Qt::darkBlue,2)));  // G1
00072   Lines.append(new Line( 30,-30, 50,-30,QPen(Qt::darkBlue,2)));  // G0
00073  
00074   Texts.append(new Text(-16,-59, "B", Qt::darkBlue, 12.0));
00075   Texts.append(new Text( -2,-59, "/", Qt::darkBlue, 12.0));
00076   Texts.append(new Text(  5,-59, "G", 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));  // B0
00089   Ports.append(new Port(-50,-10));  // B1
00090   Ports.append(new Port(-50, 10));  // B2
00091   Ports.append(new Port(-50, 30));  // B3
00092 
00093   Ports.append(new Port( 50, 30));  // G3
00094   Ports.append(new Port( 50, 10));  // G2
00095   Ports.append(new Port( 50,-10));  // G1
00096   Ports.append(new Port( 50,-30));  // G0
00097 
00098   x1 = -50; y1 = -64;
00099   x2 =  50; y2 =  44;
00100 }
00101 
00102 QString binarytogrey4bit::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 B0 = Ports.at(0)->Connection->Name;
00111   QString B1 = Ports.at(1)->Connection->Name;
00112   QString B2 = Ports.at(2)->Connection->Name;
00113   QString B3 = Ports.at(3)->Connection->Name;
00114   QString G3 = Ports.at(4)->Connection->Name;
00115   QString G2 = Ports.at(5)->Connection->Name;
00116   QString G1 = Ports.at(6)->Connection->Name;
00117   QString G0 = Ports.at(7)->Connection->Name;
00118  
00119  
00120   s = "\n  "+Name + ":process ("+B0+", "+B1+", "+B2+", "+B3+")\n" +
00121       "  begin\n"+
00122       "    "+G0+" <= "+B0+" xor "+B1+td+
00123       "    "+G1+" <= "+B1+" xor "+B2+td+
00124       "    "+G2+" <= "+B2+" xor "+B3+td+
00125       "    "+G3+" <= "+B3+td+
00126       "  end process;\n";
00127   return s;
00128 }
00129 
00130 QString binarytogrey4bit::verilogCode( int )
00131 {
00132   QString td = Props.at(1)->Value;        // delay time
00133   if(!misc::Verilog_Delay(td, Name)) return td; // time does not have VHDL format
00134   
00135   QString B0 = Ports.at(0)->Connection->Name;
00136   QString B1 = Ports.at(1)->Connection->Name;
00137   QString B2 = Ports.at(2)->Connection->Name;
00138   QString B3 = Ports.at(3)->Connection->Name;
00139   QString G3 = Ports.at(4)->Connection->Name;
00140   QString G2 = Ports.at(5)->Connection->Name;
00141   QString G1 = Ports.at(6)->Connection->Name;
00142   QString G0 = Ports.at(7)->Connection->Name; 
00143  
00144   QString l = "";
00145  
00146   QString G0R = "net_reg" + Name + G0;
00147   QString G1R = "net_reg" + Name + G1;
00148   QString G2R = "net_reg" + Name + G2;
00149   QString G3R = "net_reg" + Name + G3;
00150   
00151   l = "\n  // " + Name + " 4bit binary to Gray\n" +
00152       "  assign  " + G0 + " = " + G0R + ";\n" +
00153       "  reg     " + G0R + " = 0;\n" +
00154       "  assign  " + G1 + " = " + G1R + ";\n" +
00155       "  reg     " + G1R + " = 0;\n" +
00156       "  assign  " + G2 + " = " + G2R + ";\n" +
00157       "  reg     " + G2R + " = 0;\n" +
00158       "  assign  " + G3 + " = " + G3R + ";\n" +
00159       "  reg     " + G3R + " = 0;\n" +
00160       "  always @ ("+B0+" or "+B1+" or "+B2+" or "+B3+")\n" +
00161       "  begin\n"+
00162       "    "+G0R+" <="+td+" "+B0+" ^ "+B1+";\n"+
00163       "    "+G1R+" <="+td+" "+B1+" ^ "+B2+";\n"+
00164       "    "+G2R+" <="+td+" "+B2+" ^ "+B3+";\n"+
00165       "    "+G3R+" <="+td+" "+B3+";\n"+
00166       "  end\n";
00167   return l;
00168 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines