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