Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/tff_SR.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                               tff_SR
00003                              --------
00004     begin                : January 2009
00005     copyright            : (C) 2008 by Mike Brinson
00006     email                : mbrin72043@yahoo.co.uk
00007  ***************************************************************************/
00008 
00009 /*
00010  * tff_SR.cpp - device implementations for tff_SR 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 "tff_SR.h"
00019 #include "node.h"
00020 #include "misc.h"
00021 
00022 tff_SR::tff_SR()
00023 {
00024   Type = isComponent; // Analogue and digital component.
00025   Description = QObject::tr ("T flip flop with set and reset 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 + 4;
00037   ty = y2 + 4;
00038   Model = "tff_SR";
00039   Name  = "Y"; 
00040 }
00041 
00042 Component * tff_SR::newOne()
00043 {
00044   tff_SR * p = new tff_SR();
00045   p->Props.getFirst()->Value = Props.getFirst()->Value; 
00046   p->recreate(0); 
00047   return p;
00048 }
00049 
00050 Element * tff_SR::info(QString& Name, char * &BitmapFile, bool getNewOne)
00051 {
00052   Name = QObject::tr("T-FlipFlop w/ SR");
00053   BitmapFile = (char *) "tff_SR";
00054 
00055   if(getNewOne) return new tff_SR();
00056   return 0;
00057 }
00058 
00059 void tff_SR::createSymbol()
00060 {
00061   // put in here symbol drawing code and terminal definitions
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   Lines.append(new Line(-30,  40,-30,-40,QPen(Qt::darkBlue,2)));
00066 
00067   Lines.append(new Line(-50,-20,-30,-20,QPen(Qt::darkBlue,2)));
00068   Lines.append(new Line(-50, 20,-30, 20,QPen(Qt::darkBlue,2)));
00069   Lines.append(new Line( 30, 20, 50, 20,QPen(Qt::darkBlue,2)));
00070   Lines.append(new Line( 30,-20, 50,-20,QPen(Qt::darkBlue,2)));
00071 
00072   Lines.append(new Line( -30, 10,-20, 20,QPen(Qt::darkBlue,2)));
00073   Lines.append(new Line( -30, 30,-20, 20,QPen(Qt::darkBlue,2)));
00074 
00075   Lines.append(new Line(  0, -50,  0,-60,QPen(Qt::darkBlue,2)));
00076   Lines.append(new Line(  0,  50,  0, 60,QPen(Qt::darkBlue,2)));
00077 
00078   Arcs.append(new Arc( -5, -50, 10, 10, 0, 16*360, QPen(Qt::darkBlue,2)));
00079   Arcs.append(new Arc( -5,  40, 10, 10, 0, 16*360, QPen(Qt::darkBlue,2)));
00080 
00081   Texts.append(new Text(-25,-32, "T", Qt::darkBlue, 12.0));
00082   Texts.append(new Text( 11,-32, "Q", Qt::darkBlue, 12.0));
00083   Texts.append(new Text( -5,-39, "S", Qt::darkBlue, 12.0));
00084   Texts.append(new Text( 11,  7, "Q", Qt::darkBlue, 12.0));
00085   Texts.last()->over=true;
00086   Texts.append(new Text( -5, 17, "R", Qt::darkBlue, 12.0));
00087  
00088   Ports.append(new Port(  0,-60));  // S
00089   Ports.append(new Port(-50,-20));  // T
00090   Ports.append(new Port(-50, 20));  // CLK
00091   Ports.append(new Port(  0, 60));  // R
00092   Ports.append(new Port( 50, 20));  // QB
00093   Ports.append(new Port( 50,-20));  // Q
00094 
00095   x1 = -50; y1 = -60;
00096   x2 =  50; y2 =  60;
00097 }
00098 
00099 QString tff_SR::vhdlCode( int )
00100 {
00101   QString s="";
00102 
00103   QString td = Props.at(2)->Value;     // delay time
00104   if(!misc::VHDL_Delay(td, Name)) return td; // time has not VHDL format
00105   td += ";\n";
00106 
00107   QString S     = Ports.at(0)->Connection->Name;
00108   QString T     = Ports.at(1)->Connection->Name;
00109   QString CLK   = Ports.at(2)->Connection->Name;
00110   QString R     = Ports.at(3)->Connection->Name;
00111   QString QB    = Ports.at(4)->Connection->Name;
00112   QString Q     = Ports.at(5)->Connection->Name;
00113 
00114   s = "\n  "+Name+" : process ("+S+", "+CLK+", "+R+") is\n"+
00115       "  variable state : std_logic;\n"+
00116       "  begin\n" +
00117       "    if ("+S+" = '0') then\n"+
00118       "      state := '1';\n"+
00119       "    elsif ("+R+" = '0') then\n"+
00120       "      state := '0';\n"+
00121       "    elsif ("+CLK+" = '1' and "+CLK+"'event) then\n"+
00122       "      if ("+T+" = '1') then state := not state;\n"+
00123       "      end if;\n"+
00124       "    end if;\n"+ 
00125       "    "+Q+" <= state"+td+
00126       "    "+QB+" <= not state"+td+
00127       "  end process;\n";
00128   return s;
00129 }
00130 
00131 QString tff_SR::verilogCode( int )
00132 {
00133   QString td = Props.at(2)->Value;        // delay time
00134   if(!misc::Verilog_Delay(td, Name)) return td; // time does not have VHDL format
00135   
00136   QString l = "";
00137  
00138   QString S     = Ports.at(0)->Connection->Name;
00139   QString T     = Ports.at(1)->Connection->Name;
00140   QString CLK   = Ports.at(2)->Connection->Name;
00141   QString R     = Ports.at(3)->Connection->Name;
00142   QString QB    = Ports.at(4)->Connection->Name;
00143   QString Q     = Ports.at(5)->Connection->Name;
00144 
00145   QString QR   = "Q_reg"  + Name + Q;
00146   QString QBR  = "QB_reg"  + Name + QB;
00147   QString ST   = "Q_state" + Name;
00148 
00149   l = "\n  // "+Name+" t flip flop with set and reset\n"+
00150       "  assign  "+Q+" = "+QR+";\n"+
00151       "  reg     "+QR+" = 0;\n"+
00152       "  assign  "+QB+" = "+QBR+";\n"+
00153       "  reg     "+QBR+" = 1;\n"+
00154       "  reg     "+ST+" = 0;\n"+
00155       "  always @ (posedge "+CLK+")\n"+
00156       "  begin\n"+
00157       "    if ("+T+" == 1 && "+R+" == 1 && "+S+" == 1)\n"+
00158       "    begin\n"+
00159       "      "+ST+" = ~"+ST+";\n"+
00160       "      "+QR+" <="+td+" "+ST+";\n"+
00161       "      "+QBR+" <="+td+" ~"+ST+";\n"+
00162       "    end\n"+
00163       "  end\n"+
00164       "  always @ ("+R+")\n"+
00165       "  begin\n"+
00166       "    if ("+R+" == 0) "+ST+" = 0;\n"+
00167       "    "+QR+" <="+td+" "+ST+";\n"+
00168       "    "+QBR+" <="+td+" ~"+ST+";\n"+
00169       "  end\n"+
00170       "  always @ ("+S+")\n"+
00171       "  begin if ("+S+" == 0) "+ST+" = 1;\n"+
00172       "    "+QR+" <="+td+" "+ST+";\n"+
00173       "    "+QBR+" <="+td+" ~"+ST+";\n"+
00174       "  end\n";
00175   return l;
00176 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines