Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/gatedDlatch.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                              gatedDlatch
00003                             -------------
00004     begin                : January 2009
00005     copyright            : (C) 2008 by Mike Brinson
00006     email                : mbrin72043@yahoo.co.uk
00007  ***************************************************************************/
00008 
00009 /*
00010  * gatedDlatch.cpp - device implementations for gatedDlatch 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 "gatedDlatch.h"
00019 #include "node.h"
00020 #include "misc.h"
00021 
00022 gatedDlatch::gatedDlatch()
00023 {
00024   Type = isComponent; // Analogue and digital component.
00025   Description = QObject::tr ("gated D latch verilog device");
00026 
00027   Props.append (new Property ("TR_H", "6", false,
00028     QObject::tr ("cross coupled gate transfer function high scaling factor")));
00029   Props.append (new Property ("TR_L", "5", false,
00030     QObject::tr ("cross coupled gate transfer function low scaling factor")));
00031   Props.append (new Property ("Delay", "1 ns", false,
00032     QObject::tr ("cross coupled gate delay")
00033     +" ("+QObject::tr ("s")+")"));
00034 
00035   createSymbol ();
00036   tx = x1 + 19;
00037   ty = y2 + 4;
00038   Model = "gatedDlatch";
00039   Name  = "Y";
00040 }
00041 
00042 Component * gatedDlatch::newOne()
00043 {
00044   gatedDlatch * p = new gatedDlatch();
00045   p->Props.getFirst()->Value = Props.getFirst()->Value; 
00046   p->recreate(0); 
00047   return p;
00048 }
00049 
00050 Element * gatedDlatch::info(QString& Name, char * &BitmapFile, bool getNewOne)
00051 {
00052   Name = QObject::tr("Gated D-Latch");
00053   BitmapFile = (char *) "gatedDlatch";
00054 
00055   if(getNewOne) return new gatedDlatch();
00056   return 0;
00057 }
00058 
00059 void gatedDlatch::createSymbol()
00060 {
00061   Lines.append(new Line(-30, -40, 30,-40,QPen(Qt::darkBlue,2)));
00062   Lines.append(new Line( 30, -40, 30, 40,QPen(Qt::darkBlue,2)));
00063   Lines.append(new Line( 30,  40,-30, 40,QPen(Qt::darkBlue,2)));
00064   Lines.append(new Line(-30, 40,-30, -40,QPen(Qt::darkBlue,2)));
00065 
00066   Lines.append(new Line(-50,-20,-30,-20,QPen(Qt::darkBlue,2))); // D
00067   Lines.append(new Line(-50, 20,-30, 20,QPen(Qt::darkBlue,2))); // C
00068   Lines.append(new Line( 40, 20, 50, 20,QPen(Qt::darkBlue,2))); // QB
00069   Lines.append(new Line( 30,-20, 50,-20,QPen(Qt::darkBlue,2))); // Q
00070 
00071   Arcs.append(new Arc( 30, 15, 10, 10, 0, 16*360, QPen(Qt::darkBlue,2)));
00072 
00073   Texts.append(new Text(-25,-32, "D", Qt::darkBlue, 12.0));
00074   Texts.append(new Text(-25,  7, "C", Qt::darkBlue, 12.0));
00075   Texts.append(new Text( 11,-32, "Q", Qt::darkBlue, 12.0));
00076   Texts.append(new Text( 11,  7, "Q", Qt::darkBlue, 12.0));
00077   Texts.last()->over=true;
00078 
00079   Ports.append(new Port(-50,-20));  // D
00080   Ports.append(new Port(-50, 20));  // C
00081   Ports.append(new Port( 50, 20));  // QB
00082   Ports.append(new Port( 50,-20));  // Q
00083 
00084   x1 = -50; y1 = -44;
00085   x2 =  50; y2 =  44;
00086 }
00087 
00088 QString gatedDlatch::vhdlCode( int )
00089 {
00090   QString s="";
00091 
00092   QString td = Props.at(2)->Value;     // delay time
00093   if(!misc::VHDL_Delay(td, Name)) return td; // time has not VHDL format
00094   td += ";\n";
00095 
00096   QString D    = Ports.at(0)->Connection->Name;
00097   QString C    = Ports.at(1)->Connection->Name;
00098   QString QB   = Ports.at(2)->Connection->Name;
00099   QString Q    = Ports.at(3)->Connection->Name;
00100 
00101   s = "\n  "+Name+":process ("+D+", "+C+")\n"+
00102       "  begin\n" +
00103       "    if ("+C+" = '1') then\n"+
00104       "      "+Q+" <= "+D+td+
00105       "      "+QB+" <= not "+D+td+
00106       "    end if;\n"+
00107       "  end process;\n";
00108   return s;
00109 }
00110 
00111 QString gatedDlatch::verilogCode( int )
00112 {
00113   QString td = Props.at(2)->Value;        // delay time
00114   if(!misc::Verilog_Delay(td, Name)) return td; // time does not have VHDL format
00115   
00116   QString l = "";
00117 
00118   QString D    = Ports.at(0)->Connection->Name;
00119   QString C    = Ports.at(1)->Connection->Name;
00120   QString QB   = Ports.at(2)->Connection->Name;
00121   QString Q    = Ports.at(3)->Connection->Name;
00122 
00123   QString QR   = "Q_reg"  + Name + Q;
00124   QString QBR  = "QB_reg"  + Name + QB;
00125 
00126   l = "\n  // "+Name+" gated d latch\n"+
00127       "  assign  "+Q+" = "+QR+";\n"+
00128       "  reg     "+QR+" = 0;\n"+
00129       "  assign  "+QB+" = "+QBR+";\n"+
00130       "  reg     "+QBR+" = 0;\n"+
00131       "  always @ ("+D+" or "+C+")\n"+
00132       "  begin\n"+
00133       "    if ("+C+" == 1)\n"+
00134       "    begin\n"+
00135       "      " +QR+" <="+td+" "+D+";\n"+
00136       "      " +QBR+" <="+td+" ~"+D+";\n" +
00137       "    end\n"+
00138       "  end\n";
00139 
00140   return l;
00141 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines