Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/comp_1bit.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                               comp_1bit
00003                              -----------
00004     begin                : December 2008
00005     copyright            : (C) 2008 by Mike Brinson
00006     email                : mbrin72043@yahoo.co.uk
00007  ***************************************************************************/
00008 
00009 /*
00010  * comp_1bit.cpp - device implementations for comp_1bit 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 "comp_1bit.h"
00019 #include "node.h"
00020 #include "misc.h"
00021 
00022 comp_1bit::comp_1bit()
00023 {
00024   Type = isComponent; // Analogue and digital component.
00025   Description = QObject::tr ("1bit comparator 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 = "comp_1bit";
00037   Name  = "Y";
00038 }
00039 
00040 Component * comp_1bit::newOne()
00041 {
00042   comp_1bit * p = new comp_1bit();
00043   p->Props.getFirst()->Value = Props.getFirst()->Value; 
00044   p->recreate(0); 
00045   return p;
00046 }
00047 
00048 Element * comp_1bit::info(QString& Name, char * &BitmapFile, bool getNewOne)
00049 {
00050   Name = QObject::tr("1Bit Comparator");
00051   BitmapFile = (char *) "comp_1bit";
00052 
00053   if(getNewOne) return new comp_1bit();
00054   return 0;
00055 }
00056 
00057 void comp_1bit::createSymbol()
00058 {
00059   Lines.append(new Line(-30, -60, 30,-60,QPen(Qt::darkBlue,2)));
00060   Lines.append(new Line( 30, -60, 30, 30,QPen(Qt::darkBlue,2)));
00061   Lines.append(new Line( 30,  30,-30, 30,QPen(Qt::darkBlue,2)));
00062   Lines.append(new Line(-30,  30,-30, -60,QPen(Qt::darkBlue,2)));
00063 
00064   Lines.append(new Line(-50,-10,-30,-10,QPen(Qt::darkBlue,2)));  // X
00065   Lines.append(new Line(-50, 10,-30, 10,QPen(Qt::darkBlue,2)));  // Y
00066   Lines.append(new Line( 30, 20, 50, 20,QPen(Qt::darkBlue,2)));  // L
00067   Lines.append(new Line( 30,  0, 50,  0,QPen(Qt::darkBlue,2)));  // G
00068   Lines.append(new Line( 30,-20, 50,-20,QPen(Qt::darkBlue,2)));  // E
00069 
00070   Texts.append(new Text(-25,-55, "COMP", Qt::darkBlue, 12.0));
00071 
00072   Texts.append(new Text(-25,-23,   "X",  Qt::darkBlue, 12.0));
00073   Texts.append(new Text(-25, -3,   "Y",  Qt::darkBlue, 12.0));
00074   Texts.append(new Text( -5,  7, "X<Y",  Qt::darkBlue, 12.0));
00075   Texts.append(new Text( -5,-13, "X>Y", Qt::darkBlue, 12.0));
00076   Texts.append(new Text( -5,-33, "X=Y", Qt::darkBlue, 12.0));
00077 
00078   Ports.append(new Port(-50,-10));  // X
00079   Ports.append(new Port(-50, 10));  // Y
00080   Ports.append(new Port( 50, 20));  // L
00081   Ports.append(new Port( 50,  0));  // G
00082   Ports.append(new Port( 50,-20));  // E
00083 
00084   x1 = -50; y1 = -64;
00085   x2 =  50; y2 =  34;
00086 }
00087 
00088 QString comp_1bit::vhdlCode( int )
00089 {
00090   QString s="";
00091 
00092   QString td = Props.at(1)->Value;     // delay time
00093   if(!misc::VHDL_Delay(td, Name)) return td; // time has not VHDL format
00094   td += ";\n";
00095  
00096   QString X    = Ports.at(0)->Connection->Name;
00097   QString Y    = Ports.at(1)->Connection->Name;
00098   QString L    = Ports.at(2)->Connection->Name;
00099   QString G    = Ports.at(3)->Connection->Name;
00100   QString E    = Ports.at(4)->Connection->Name;
00101  
00102   s = "\n  "+Name+":process ("+X+", "+Y+")\n"+
00103       "  begin\n"+
00104       "    "+L+" <= (not "+X+") and "+Y+td+
00105       "    "+G+" <= "+X+" and (not "+Y+")"+td+
00106       "    "+E+" <= not ("+X+" xor "+Y+")"+td+  
00107       "  end process;\n";
00108   return s;
00109 }
00110 
00111 QString comp_1bit::verilogCode( int )
00112 {
00113   QString l="";
00114 
00115   QString td = Props.at(1)->Value;        // delay time
00116   if(!misc::Verilog_Delay(td, Name)) return td; // time does not have VHDL format
00117 
00118   QString X    = Ports.at(0)->Connection->Name;
00119   QString Y    = Ports.at(1)->Connection->Name;
00120   QString L    = Ports.at(2)->Connection->Name;
00121   QString G    = Ports.at(3)->Connection->Name;
00122   QString E    = Ports.at(4)->Connection->Name;
00123 
00124   QString LR  = "L_reg"  + Name + L;
00125   QString GR  = "G_reg"  + Name + G;
00126   QString ER  = "E_reg"  + Name + E;
00127 
00128   l = "\n  // "+Name+" 1bit comparator\n"+
00129       "  assign  "+L+" = "+LR+";\n"+
00130       "  reg     "+LR+" = 0;\n"+
00131       "  assign  "+G+" = "+GR+";\n"+
00132       "  reg     "+GR+" = 0;\n"+
00133       "  assign  "+E+" = "+ER+";\n"+
00134       "  reg     "+ER+" = 0;\n"+
00135       "  always @ ("+X+" or "+Y+")\n"+
00136       "  begin\n"+
00137       "    "+LR+" <="+td+" (~"+X+") && "+Y+";\n"+
00138       "    "+GR+" <="+td+" "+X+" && (~"+Y+");\n"+
00139       "    "+ER+" <="+td+" ~("+X+" ^ "+Y+");\n"+
00140       "  end\n";
00141 
00142   return l;
00143 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines