Lecture_5

Lecture 5
5. Sequential functions and circuits
5.1 Introduction
5.2 Feedback, memory, state
5.3 Sequential functions and circuits
5.4 Flip-flops
5.5 The S-R flip-flop
5.6 Examples
5.1 Introduction
• In the preceding chapters we have
discussed various types and aspects of
combinational functions, whose outputs
are determined completely by their inputs.
• An important property ot that functions and
circuits, where these functions are
implemented, is that there is no feedback
from the output to the input
5.2 Feedback, memory, state
• The moment we introduce this feedback,
we get a new type of function or circuit
with a new capability:
-The capability to store bits of information.
In other words the circuit also acquires
memory.
Depending on the contents of its memory,
we say that the circuit is in a certain state
Feedback, memory, state - 2
• Therefore a change in the contents of the
memory implies a change in the state of
the circuit.
• The output of such a circuit with memory is
not always the same for the same input,
as is the case with a combinational circuit
but also depends on its present state.
Feedback, memory, state - 3
• Note, that we have used the word „present“ in
the last sentence.
• This means that the next state as well as the
output depend not only on the present input but
also the present state.
• Hence the element of time also comes in.
• Such combinational functions (circuits) with
feedback , having memory of internal states, are
called sequental functions (circuits).
5.3 Sequential functions and
circuits
• Such combinational functions (circuits)
with feedback , having memory of internal
states, are called sequental functions
(circuits).
• A formal definition of sequential circuits or
the more general term sequential
machines (automatons) will be given later.
Sequential functions and circuits -1
• There are three special types of sequential
machines:
Flip-flops
Counters
Shift registers
The building blocks of all these sequential
circuits are the flip-flops, which we discuss
in this lecture.
5.4 Flip-flops
• A flip-flop is the most elementary
sequential machine having only two
states.
• These are therefore bistable circuits.
• Although the flip-flops may differ in their
electronic compositions, they exhibit
certain definite logical properties.
Flip-flops - 2
• In fact, all flip-flops, irrespective of their
internal circuit implementation, can be
classsified into a few types according to
their logical behavior.
• The R-S flip-flop
• The J-K flip-flop
• The D flip-flop
• The T flip-flop
Flip-flops - 3
• In subsequent sections we first discuss a
few typical types of flip-flops and then we
seehow theese flip-flops produce various
types of conters and shift registers
depending on their interconnections
Flip-flops - 4
• In PLC we usually have some of these flipflops at disposal (mostly RS flip -flop and
/or SR flip-flop) as co called „function
blocks“ (SW function blocks).
• We only program these blocks, that means
we connect them with other blocks in one
of the programming languages for PLCs
named „Function block diagram - FBD“
(see e.g. LOGO! )
5.5 The S-R flip-flop
• Consider the circuit shown in the figure:
S
>=1
Z1
NQ
G1
>=1
R
Q
G2
Z2
The S-R flip-flop - 2
• It is a combinational circuit with feedback
S
>=1
Z1
NQ
G1
>=1
R
Q
G2
Z2
It has only
two NOR
gates,G1 and
G2, with the
output of one
gate being fed
to the input of
the other
The S-R flip-flop - 3
• Now let us study the outputs of the circuit
Z1 and Z2 for the four different
combinations 00,01,10,11 of the input lines
S and R.
1.When S=0, Z1 becomes 1(0) depending
on if Z2=0(1):
Z1=N(S+Z2)=NS.NZ2=1.NZ2=NZ2
Z1=1.1…….Z2=0
Z1=1.0…….Z2=1
The S-R flip-flop - 4
2. Similarly, when R=0, Z2=NZ1, since
Z2=N(R+Z1)=NR.NZ1=1.NZ1=NZ1
3. Thus when SR=00, the values of Z1and
Z2 depend only on them and it is always
Z1=NZ2.
It can now be verified, that with SR=00, if
Z1Z2=01 or Z1Z2=10, they retain these
output values.
• In other words, the outputs remain
unchanged.
The S-R flip-flop - 5
4.However the situation changes if S=1 and
R=0, then the 1 on the S-line will force the
output Z1 to be 0, irrespective of the value
of Z2. Therefore Z1 becomes 0. This
forces Z2 to become 1, as both input lines
of gate G2 become 0.
Hence when SR=10, the circuit has a stable
state with Z1Z2=01.
The S-R flip-flop - 6
5. Similarly it can be found, that the circuit
has another stable state with SR=01 and
Z1Z2 becoming 10.
6. Now, let us investigate what happens, if
SR=11. In this situation, the 1 on the S-line
will force Z1 to be 0, and the 1 on the Rline will force Z2 to be 0. So under this
conditions, when SR=11, the output will be
Z1Z2=00 and this will also be a stable
state.
The S-R flip-flop - 7
7. Now, let S and R both become 00
simultanously. Then both NOR gates, G1
and G2, will „see“ 00 at their inputs
simultaneously, and their outputs will tend
to become 11. Now let the output Z1 of
gate G1 change to 1much earlier than Z2
of gate G2. Then the 1 at Z1 will prevent
Z2 to become 1 and Z2 will continue to
remain 0. Now it can be easily checked
that the output Z1Z2=10 with SR=00 is
also a stable state.
The S-R flip-flop - 8
8. However, when S and R become 00
simultaneously, if Z2 would have become
1 much earlier than Z1, the output will
stabilize at the value of Z1Z2=01. Thus the
outputs become unpredictable and depend
on the operating delays of the gates G1
and G2.
The S-R flip-flop - 9
• Even if these two delays are identical,
there is a serious problem.
• In that case it can beverified that the
outputs will oscillate between the values
11 and 00.
• These are very undesirable operating
conditions for the flip-flop.
The S-R flip-flop - 10
• Thus although SR=11 and Z1Z2=0 is a
stable state, it may introduce serious
anomalous situations in operation of the
flip-flop.
• Hence to eliminate this possibility entirely,
an aditional restriction, that the S- and Rlines should not be made 1 simultanously,
is accepted in the definition of an S-R flipflop.
S-R flip-flop - 11
Definition:
An S-R flip-flop has two input lines, S and R.
When S is 1, the flip flop is set to state 1.
When R becomes 1, the flip –flop is reset
to state 0. When both S and R are 0, the
flip-flop continues to be in the same state.
The S- and R-lines are never made 1
simultaneously. When the flip-flop is in
state 0(1), the output of the flip-flop Q is
also 0(1).
S-R flip-flop - 12
• This definition yields the truth table,(next
snap), where q denotes the present state
and Q the next state of the flip-flop.
• The truth table defines Q as a function of
the three variables S, R, and q:
• Q=f(S,R,q)
S-R flip-flop - 13
• The truth table of S-R- flip-flop
As a sum of minterms it can
be expressed as:
S R q Q
0 0 0 0
Q=(S,R,q)=SUM(1,4,5)+
0 0 1 1
0 1 0 0
+x SUM(6,7)
0 1 1 0
=NS.NR.q+S.NR.Nq+S.NR.q+
1 0 0 1
1 0 1 1
???(assume, that x=1)…..+
1 1 0 x
+S.R.nq+S.R.q=S+NR.q
1 1 1 x
This function is known as the characteristic function
of the RS flip-flop.
The S-R flip-flop – 14
• Theory says all this ….but what about praxis???
• In practical applications, we must solve the
situation when S=1 and R=1 simultaneously
• There are two types of SR flip-flops (both HW
and SW applications)
• SR - with prior setting
(if SR=11, then Q=1)
• RS - with prior reseting
(if SR=11, then Q=0)
The S-R flip-flop - 15
• The truth table of S-R- flip-flop with prior
setting (x=1)
S
0
0
0
0
1
1
1
1
R q
0 0
0 1
1 0
1 1
0 0
0 1
1 0
1 1
Q
0
1
0
0
1
1
1
1
As a sum of minterms it can
be expressed as:
Q=(S,R,q)=SUM(1,4,5,6,7)=
=NS.NR.q+S.NR.Nq+S.NR.q+
+S.R.nq+S.R.q=NS.NR.q+
+S.(NR.Nq+NR.q+R.Nq+R.q)=
=NS.NR.q+S(NR+R)=
=NS.NR.q+S=NR.q+S=
=S+NR.q
The R-S Flip-flop - 16
• The truth table of R-S flip-flop with prior
resetting (x=0)
S
0
0
0
0
1
1
1
1
R q
0 0
0 1
1 0
1 1
0 0
0 1
1 0
1 1
Q
0
1
0
0
1
1
0
0
As a sum of minterms it can
be expressed as:
Q=(S,R,q)=SUM(1,4,5)=
=NS.NR.q+S.NR.Nq+S.NR.q=
=NS.NR.q+S.NR=
=NR.(NS.q+S)=
=NR.(q+S)
The S-R Flip-flops - 17
Practical summary of the RS-flip-flops function:
• RS(SR) flip-flop (RS(SR) memory) has two
inputs:
S input – for setting the output Q (Q=1)
R input – for reseting the output Q (Q=0)
If both R and S inputs are 0, output remains on its
last value.
If on both S and R inputs are 1 simultaneously, the
value of output depends on the type of the flip
flop (SR …Q=1,RS…Q=0)
Very often the R-S flip-flop blocks have the
second output, negation of the output Q, NQ.
The S-R Flip-flop - 18
• Block diagram and function table
• (function table is not the same as the true
table, it serves for the function description )
S R Q NQ
S
R
Q
SR
NQ
1 0
1
0
0 0
1
0
0 1
0
1
0 0
0
1
1 1
1
0
The R-S Flip-flop - 19
• Block diagram and function table
S R Q NQ
S
R
Q
RS
NQ
1 0
1
0
0 0
1
0
0 1
0
1
0 0
0
1
1 1
0
1
5.6 Examples
Example 1:
• If sensor B1 has a 1-signal, this indicates
an error status in the system. A horn H1 is
sounded. The horn can only be switched
off by actuating push button S1. It is
possible to switch off the horn, even if the
B1-signal continues to be applied.
Example 1 - 2
• Block diagram of the system:
B1
H1
S1
The control system has
two inputs, from B1,S1
one output to the H1
Example 1 - 3
Let’s try to solve the task intuitively:
We use SR flip-flop in the control system first.
Horn H1 will be connected to the output Q of the
flip-flop.
This output should be switched on (set) by error
status (indicated by the sensor B1) …thus we
connect sensor B1 to the S-input of the flipflop.
This output should be switched off (reset) by push
button S1…thus we connect push button S1 to
the R-input of the flip-flop.
Example 1 - 4
• The first solution:
B1
S1
S
R
Q
H1
SR
NQ
The basic function is OK, but the last sentence of
the task definition cannot be fulfilled by this type of
flip-flop. If the B1-signal continues to be applied,
(this is Set signal for SR flip-flop), it is not possible
to reset this flip-flop by its reset signal S1!
Example 1 - 5
• Let’s try the second type of the flip-flop,
the RS-one.
Horn H1 will be connected to the output Q of the
flip-flop.
This output should be switched on (set) by error
status (indicated by the sensor B1) …thus we
connect sensor B1 to the S-input of the flip-flop.
This output should be switched off (reset) by push
button S1…thus we connect push button S1 to
the R-input of the flip-flop.
Example 1 - 6
• The second solution:
B1
S1
S
R
Q
H1
RS
NQ
The basic function is OK. Also the last sentence of
the task definition is fulfilled by this type of flip-flop.
If the B1-signal continues to be applied, (this is Set
signal for RS flip-flop), it is possible to reset this
flip-flop by its reset signal S1 and thus switch off
the horn. This solution is the right one.
Example 2
Example 2:
Pressing of the start button S2 is to cause the
piston of a cylinder to advance (if it is in initial
position, that is retracted) – signal Y1=1. This
mechanism is to be used to clamp workpieces.
When the piston has advanced fully, it is to
remain in this position for 20 seconds. (Signal
Time_out from the special „timer“ block is
on).The cylinder then returns to its initial position
signal Y1=0. Sensor B1 indicates, that cylinder is
retracted, sensor B2 indicates, that cylinder is
advanced.
Example 2 - 2
• Block diagram of the system:
S2
B1
B2
Time_out
Y1
Example 2 - 3
We use SR flip-flop in the control system.
Signal for cylinder Y1 will be connected to
the output Q of the SR flip-flop.
This output should be switched on (set) by
pressing the start button S2 if the piston is
in retracted position (indicated by the
sensor B1) …
thus we connect conjunction of the
signals S2 and B1 to the S-input of the
SR flip-flop.
Example 2 - 4
This output should be switched off (reset)
when the piston has advanced fully
(indicated by sensor B2) and has
remained there for 20 seconds (signal
from timer Time_out)….
thus we connect conjunction of the signals
S2 and Time_out to the R-input of the SR
flip-flop.
Example 2 - 5
S2
B1
&
S
Q
SR
R
B2
&
Time_out
NQ
Y1
Literature
• Nripendra N. Biswas: Logic Design
Theory,Prentice Hall
International,1993,ISBN 0-13-010695-X
6. The smallest control systems (PLCs)–
“Programmable modules“