1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/***************************************************************************
* Copyright (C) 2016 by santiago González *
* santigoro@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, see <http://www.gnu.org/licenses/>. *
* *
***************************************************************************/
#include <QDebug>
#include "e-flipflopjk.h"
#include "simulator.h"
#include "circuit.h"
eFlipFlopJK::eFlipFlopJK( QString id )
: eLogicDevice( id )
{
}
eFlipFlopJK::~eFlipFlopJK() {}
void eFlipFlopJK::stamp()
{
eNode* enode = m_input[2]->getEpin()->getEnode(); // Set pin
if( enode ) enode->voltChangedCallback( this );
enode = m_input[3]->getEpin()->getEnode(); // Reset pin
if( enode ) enode->voltChangedCallback( this );
if( m_etrigger != Trig_Clk )
{
for( uint i=0; i<2; i++ )
{
eNode* enode = m_input[i]->getEpin()->getEnode();
if( enode ) enode->voltChangedCallback( this );
}
}
eLogicDevice::stamp();
}
void eFlipFlopJK::voltChanged()
{
// Get Clk to don't miss any clock changes
bool clkAllow = (eLogicDevice::getClockState() == Clock_Allow);
//qDebug() << "eFlipFlopJK::voltChanged()"<<clkRising;
if( eLogicDevice::getInputState( 2 )==true ) // Master Set
{
m_Q0 = true; // Q
m_Q1 = false; // Q'
//qDebug() << "eFlipFlopJK::voltChanged() set";
}
else if( eLogicDevice::getInputState( 3 )==true ) // Master Reset
{
m_Q0 = false; // Q
m_Q1 = true; // Q'
//qDebug() << "eFlipFlopJK::voltChanged() Reset";
}
else if( clkAllow ) // Allow operation
{
bool J = eLogicDevice::getInputState( 0 );
bool K = eLogicDevice::getInputState( 1 );
bool Q = m_output[0]->out();
bool state = (J && !Q) || (!K && Q) ;
//qDebug() << "eFlipFlopJK::voltChanged() clk"<<J<<K<<state;
m_Q0 = state ; // Q
m_Q1 = !state; // Q'
}
Simulator::self()->addEvent( m_propDelay, this );
}
void eFlipFlopJK::runEvent()
{
setOut( 0, m_Q0 ); // Q
setOut( 1, m_Q1 ); // Q'
}
void eFlipFlopJK::setSrInv( bool inv )
{
m_srInv = inv;
m_input[2]->setInverted( inv ); // Set
m_input[3]->setInverted( inv ); // Reset
Circuit::self()->update();
}
|