Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/dff_SR.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                               dff_SR
00003                              --------
00004     begin                : December 2008
00005     copyright            : (C) 2008 by Mike Brinson
00006     email                : mbrin72043@yahoo.co.uk
00007  ***************************************************************************/
00008 
00009 /*
00010  * dff_SR.cpp - device implementations for dff_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 "dff_SR.h"
00019 #include "node.h"
00020 #include "misc.h"
00021 
00022 dff_SR::dff_SR()
00023 {
00024   Type = isComponent; // Analogue and digital component.
00025   Description = QObject::tr ("D 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 = "dff_SR";
00039   Name  = "Y";
00040 }
00041 
00042 Component * dff_SR::newOne()
00043 {
00044   dff_SR * p = new dff_SR();
00045   p->Props.getFirst()->Value = Props.getFirst()->Value; 
00046   p->recreate(0); 
00047   return p;
00048 }
00049 
00050 Element * dff_SR::info(QString& Name, char * &BitmapFile, bool getNewOne)
00051 {
00052   Name = QObject::tr("D-FlipFlop w/ SR");
00053   BitmapFile = (char *) "dff_SR";
00054 
00055   if(getNewOne) return new dff_SR();
00056   return 0;
00057 }
00058 
00059 void dff_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,  "D", 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));  // D
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 dff_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 D     = 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       "      state := "+D+";\n"+
00123       "    end if;\n"+ 
00124       "    "+Q+" <= state"+td+
00125       "    "+QB+" <= not state"+td+
00126       "  end process;\n";
00127   return s;
00128 }
00129 
00130 QString dff_SR::verilogCode( int )
00131 {
00132   QString td = Props.at(2)->Value;        // delay time
00133   if(!misc::Verilog_Delay(td, Name)) return td; // time does not have VHDL format
00134   
00135   QString l = "";
00136  
00137   QString S     = Ports.at(0)->Connection->Name;
00138   QString D     = Ports.at(1)->Connection->Name;
00139   QString CLK   = Ports.at(2)->Connection->Name;
00140   QString R     = Ports.at(3)->Connection->Name;
00141   QString QB    = Ports.at(4)->Connection->Name;
00142   QString Q     = Ports.at(5)->Connection->Name;
00143 
00144   QString QR   = "Q_reg"  + Name + Q;
00145   QString QBR  = "QB_reg"  + Name + QB;
00146   QString ST   = "Q_state" + Name;
00147 
00148   l = "\n  // "+Name+" d flip-flop with set and reset\n"+
00149       "  assign  "+Q+" = "+QR+";\n"+
00150       "  reg     "+QR+" = 0;\n"+
00151       "  assign  "+QB+" = "+QBR+";\n"+
00152       "  reg     "+QBR+" = 1;\n"+
00153       "  reg     "+ST+" = 0;\n"+
00154       "  always @ (posedge "+CLK+")\n"+
00155       "  begin\n"+
00156       "    if ("+R+" == 1 && "+S+" == 1)\n"+
00157       "    begin\n"+
00158       "      "+ST+" = "+D+";\n"+
00159       "      "+QR+" <="+td+" "+ST+";\n"+
00160       "      "+QBR+" <="+td+" ~"+ST+";\n"+
00161       "    end\n"+
00162       "  end\n"+
00163       "  always @ ("+R+")\n"+
00164       "  begin\n"+
00165       "    if ("+R+" == 0) "+ST+" = 0;\n"+
00166       "    "+QR+" <="+td+" "+ST+";\n"+
00167       "    "+QBR+" <="+td+" ~"+ST+";\n"+
00168       "  end\n"+
00169       "  always @ ("+S+")\n"+
00170       "  begin if ("+S+" == 0) "+ST+" = 1;\n"+
00171       "    "+QR+" <="+td+" "+ST+";\n"+
00172       "    "+QBR+" <="+td+" ~"+ST+";\n"+
00173       "  end\n";
00174   return l;
00175 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines