ec555.cpp

00001 /***************************************************************************
00002  *   Copyright (C) 2003 by David Saxton                                    *
00003  *   david@bluehaze.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  ***************************************************************************/
00010 
00011 #include "ec555.h"
00012 
00013 #include "ecnode.h"
00014 #include "libraryitem.h"
00015 #include "pin.h"
00016 #include "resistance.h"
00017 
00018 #include <kiconloader.h>
00019 #include <klocale.h>
00020 #include <qpainter.h>
00021 
00022 Item* EC555::construct( ItemDocument *itemDocument, bool newItem, const char *id )
00023 {
00024         return new EC555( (ICNDocument*)itemDocument, newItem, id );
00025 }
00026 
00027 LibraryItem* EC555::libraryItem()
00028 {
00029         return new LibraryItem(
00030                 QString::QString("ec/555"),
00031                 i18n("555"),
00032                 i18n("Integrated Circuits"),
00033                 "ic1.png",
00034                 LibraryItem::lit_component,
00035                 EC555::construct
00036                         );
00037 }
00038 
00039 EC555::EC555( ICNDocument *icnDocument, bool newItem, const char *id )
00040         : Component( icnDocument, newItem, (id) ? id : "555" )
00041 {
00042         m_name = i18n("555");
00043         m_desc = i18n("Common timer IC");
00044 //      m_pins = QStringList::split( ',', "Gnd,Trg,Out,Res,CV,Th,Dis,Vcc" );
00045 //      m_pins = QStringList::split( ',', "Dis,Th,Trg,Gnd,CV,Out,Res,Vcc" );
00046         
00047         old_com1 = false;
00048         old_com2 = false;
00049         old_q = false;
00050         
00051         setSize( -32, -32, 64, 64 );
00052         
00053         
00054         // Pins down left
00055         
00056         // Pin 7
00057         discharge = createPin( -40, -16, 0, "Dis" )->pin();
00058         addDisplayText( "dis", QRect( -32, -24, 24, 16 ), "Dis" );
00059         
00060         // Pin 6
00061         threshold = createPin( -40, 0, 0, "Th" )->pin();
00062         addDisplayText( "th", QRect( -32, -8, 24, 16 ), "Th" );
00063         
00064         // Pin 2
00065         trigger = createPin( -40, 16, 0, "Trg" )->pin();
00066         addDisplayText( "trg", QRect( -32, 8, 24, 16 ), "Trg" );
00067         
00068         
00069         
00070         // Top two
00071         
00072         // Pin 8
00073         vcc = createPin( -16, -40, 90, "Vcc" )->pin();
00074         addDisplayText( "vcc", QRect( -24, -32, 16, 8 ), "+" );
00075         
00076         // Pin 4
00077         reset = createPin( 16, -40, 90, "Res" )->pin();
00078         addDisplayText( "res", QRect( 8, -28, 16, 16 ), "Res" );
00079         
00080         
00081         
00082         // Bottom two
00083         
00084         // Pin 1
00085         ground = createPin( -16, 40, 270, "Gnd" )->pin();
00086         addDisplayText( "gnd", QRect( -24, 20, 16, 8 ), "-" );
00087         
00088         // Pin 5
00089         control = createPin( 16, 40, 270, "CV" )->pin();
00090         addDisplayText( "cv", QRect( 8, 12, 16, 16 ), "CV" );
00091         
00092         
00093         
00094         // Output on right
00095         
00096         // Pin 3
00097         output = createPin( 40, 0, 180, "Out" )->pin();
00098         addDisplayText( "out", QRect( 8, -8, 16, 16 ), "Out" );
00099         
00100         
00101         
00102         m_r1 = createResistance( vcc, control, 5e3 );
00103         m_r23 = createResistance( control, ground, 1e4 );
00104         m_po_sink = createResistance( output, ground, 0. );
00105         m_po_source = createResistance( output, vcc, 0. );
00106         m_po_source->setConductance(0.);
00107         m_r_discharge = createResistance( discharge, ground, 0. );
00108 }
00109 
00110 EC555::~EC555()
00111 {
00112 }
00113 
00114 void EC555::stepNonLogic()
00115 {
00116         double v_threshold = threshold->voltage();
00117         double v_control = control->voltage();
00118         double v_ground = ground->voltage();
00119         double v_trigger = trigger->voltage();
00120         double v_reset = reset->voltage();
00121         double v_vcc = vcc->voltage();
00122         
00123         double v_r = (v_control+v_ground)/2;
00124         
00125         bool com1 = ( v_threshold == v_control ) ? old_com1 : ( v_threshold < v_control );
00126         bool com2 = ( v_r == v_trigger ) ? old_com2 : ( v_r > v_trigger );
00127         bool reset = ( v_reset >= (v_control-v_ground)/2 + v_ground );
00128         old_com1 = com1;
00129         old_com2 = com2;
00130         
00131         bool r = ( !reset || !com1 );
00132         bool s = com2;
00133         
00134         bool q = old_q;
00135         if ( v_vcc - v_ground >= 2.5 )
00136         {
00137                 if ( s && !r )
00138                 {
00139                         q = true;
00140                 }
00141                 else if ( r && !s )
00142                 {
00143                         q = false;
00144                 }
00145         }
00146         else
00147         {
00148                 q = false;
00149         }
00150         old_q = q;
00151         
00152         
00153         m_r_discharge->setConductance(0.);
00154         
00155         if (q)
00156         {
00157                 m_po_source->setResistance(10.);
00158                 m_po_sink->setConductance(0.);
00159         }
00160         else
00161         {
00162                 m_po_source->setConductance(0.);
00163                 m_po_sink->setResistance(10.);
00164                 if ( v_ground+0.7 <= v_vcc )
00165                 {
00166                         m_r_discharge->setResistance(10.);
00167                 }
00168         }
00169 }
00170 
00171 

Generated on Tue May 8 17:05:29 2007 for KTechLab by  doxygen 1.5.1