Analog
and
Digital Electronics
(Second Year BTech Computer)
(2019-20)
(Faculty: Mr. Y. K. Sharma)
Courtesy: R. P. Jain (Modern Digital
Electronics)
UNIT- 4
Counters
Courtesy: R. P. Jain & J. S. Katre
Counters
➢ Counters: Asynchronous counter. Synchronous counter, ring counters, Johnson Counter,
Modulus of the counter (IC 7490).
➢ Synchronous Sequential Circuit Design: Models – Moore and Mealy, State diagram and State
Tables, Design Procedure, Sequence generator and detector.
➢ Asynchronous Sequential Circuit Design: Difference with synchronous circuit design, design
principles and procedure, applications.
Counters
➢ There are two types of counters Asynchronous (ripple) & Synchronous counters.
➢ Asynchronous counter is easy to design & requires the least amount of homework.
➢ Asynchronous counter is not triggered simultaneously & is also called as serial or series counter.
➢ Design of Synchronous counter requires some amount of homework & each Flip-Flop is triggered
simultaneously.
➢ Each count of the counter is called as a state of the counter.
➢ The number of states through which the counter passes before returning to the starting state is called
the modulus of the counter.
➢ E.g. A 2-bit counter has 4 states, it is called a mod-4 counter & as it divides the clock signal frequency
by 4, it is called as divide-by-4 counter.
➢ An n-bit counter will have n FF’s & 2n states, and divides the input frequency by 2n. Hence it is called as
divide-by-2n counter. The LSB of ripple counters is the Q output of the FF to which the external clock is
applied.
Counters
Classification of Sequential Circuits:
➢ Synchronous sequential circuits: Contents of memory elements can be changed only at the rising or falling edges of clock
signal.
➢ Asynchronous sequential circuits: Contents of memory elements can be changed at any instant of time.
Asynchronous Synchronous
1. Depends upon the sequence 1. Behaviour can be defined from the knowledge of its signal at
in which the input signals discrete instants of time.
change.
2. Commonly used memory 2. Memory elements used are Flip-Flops.
elements are time delays.
3. Design is tedious. 3. Design is easy.
4. They are combinational circuit 4. Synchronization is achieved by system clock.
with feedback.
5. Also called as clocked sequential circuit.
Asynchronous Inputs
➢ It is common for the FF types we have mentioned to also have additional so called ‘asynchronous’ inputs
➢ They are called asynchronous since they take effect independently of any clock or enable inputs.
➢ Reset/Clear – force Q to 0
➢ Preset/Set – force Q to 1
➢ Often used to force a synchronous circuit into a known state, say at start-up.
Ripple Counters
➢ It can be designed by using negative edge triggered T-type FF’s operating in toggle mode, i.e T=1.
➢ Since FF’s are not clocked using the same clock therefore it is called as asynchronous or ripple counters.
Ripple Counters
➢ Timing diagram for ripple counter.
➢ Outputs do not change synchronously, so hard to know when count
output is actually valid.
➢Propagation delay builds up from stage to stage, limiting maximum clock
speed before miscounting occurs.
Synchronous Counters
➢ All flip flop clock inputs are directly connected to the clock signal and so all FF outputs change at the
same time, i.e. synchronously.
➢ More complex combinational logic is now needed to generate the appropriate FF input signals(Which will
be different depending upon the type of FF chosen.)
➢ We can design synchronous counters using any type of Flip-Flops.
➢ We will consider using D-type FFs to design 0-7 up counter.
➢ While designing counter we will make use of a modified state transition table. This table has additional
columns that defines the required FF inputs(or excitation table values).
➢ We make use of excitation table for a particular type of FF.
➢ Firstly investigate the so called characteristic table and characteristic equation for a FF.
➢ For D-FFs it is not necessary to write out the FF input columns, since we know they are identical to those
for the next state.
➢ To design the circuit we need to determine appropriate combinational logic circuits which will generate
the required FF inputs from the current states.
➢ This can be done using Boolean algebra or using K-maps.
Characteristic Table
Excitation Table
Characteristic and Excitation Tables
Modified State Transition Table
Modified State Transitation Table
Synchronous Counter
Ring Counter
➢ If the serial output Q0 of the shift register is connected back to the serial input, then an injected pulse will
keep circulating. This circuit is referred to as a ring counter.
➢ The pulse is injected by entering 00001 in the parallel form after clearing the Flip-Flop’s.
➢ When Clock pulses are applied, this 1 circulates around the circuit.
➢ The outputs are sequential non-overlapping pulses which are useful for control-state counters, for stepper
motor (which rotates in steps) which require sequential pulses to rotate it from one position to the next etc.
➢ This circuit can also be used for counting the number of pulses.
➢ The number of pulses counted is read by noting which FF is in state 1.
➢ Since there is one pulse at the output for each of the N clock pulses, this circuit is referred to as a divide-by-
N counter or an N:1 scalar.
➢ If Q0 is connected to the serial output, the resulting circuit is referred to as a twisted ring, johnson, or
moebius counter.
➢ If the clock pulses are applied after clearing the FF’s, square waveform is obtained at the Q outputs.
➢ It is useful for the generation of multiphase clock.
Ring Counter
➢ Ring counters are constructed by modifying the serial-in, serial-out, shift registers. There are two types of
ring counters- basic ring counter & Johnson counter.
➢ The basic ring counter can be obtained from a serial-in, serial-out, shift register by connecting Q output of
the last FF to D input of first FF.
➢ The ring counter is the decimal counter. It is divide-by-N counter, where N is the number of stages. The
keyboard encoder is an application of a ring counter.
Twisted Ring Counter (Johnson Counter)
➢ It is obtained from a serial-in, serial-out shift register by providing a feedback from Q bar of last FF to the
D input of first FF, called as twisted ring counter.
➢ The output Q is connected to the D input of next stage.
➢ It produces the unique sequence of states.
➢ Initially all the FF’s are reset i.e. the state of counter is 0000.
➢ After each clock pulse, the level of Q1 is shifted to Q2, the level of Q2 to Q3, Q3 to Q4 & finally Q4 bar to
Q1. The sequence is repeated after every 8 clock pulse.
➢ N Flip-Flop or n-bit Johnson counter can have 2n unique states and can count up to 2n states. So it is mod-
2n counter.
Twisted Ring Counter (Johnson Counter)
Advantages:
1. It is more economical than ring counter but less than ripple counter.
Disadvantages:
1. It requires 2 input gates for decoding regardless of number of Flip-Flops.
2. Both the ring counters suffer from problem of lock out i.e. if the counter finds itself in an unused
state, it will persist in moving from one unused state to another and will never find its way to a used
state.
Modulus of the counter (IC 7490)
7490 Asynchronous Counter IC: (Modulus of the counter)
➢ IC’s available are divided into 3 groups A,B,C depending on its features. It consists of four MS-FF.
➢ The load, set & reset (clear) operations are asynchronous. i.e. independent of clock pulse.
➢ It consists of four FF’s internally connected to provide mod-2 counter & a mod-5 counter. These
counters can be used independently or in combination.
➢ FFA operates as a mod-2 counter whereas the combination of FFB, FFC & FFD form a mod-5 counter.
➢ The two reset inputs R1 & R2 both are connected to logic 1 level for clearing all FF’s.
➢ The two set inputs S1 & S2 when connected to logic 1 level, are used for setting the counter to 1001.
➢ E.g. In a 7490 if QA output is connected to B input and the pulses are applied at A input, find the count
sequence. Ans. It is a decade counter.
Generalized FSM model: Moore and Mealy
➢Combinational logic computes next state and outputs
• Next state is a function of current state and inputs
• Outputs are functions of
• Current state (Moore machine)
• Current state and inputs (Mealy machine)
output Outputs
logic
Inputs
Next-state Next State
logic
Current State
Moore and Mealy Machines
There are two types of finite state machine that can be built from sequential logic circuits:
➢ Moore machine: The output depends only on the internal state. (Since the internal state only changes on a
clock edge, the output only changes on a clock edge).
➢ Mealy Machine: The output depends not only on the internal state, but also on the inputs.
➢ A clocked sequential system is a kind of Moore machine.
Moore versus Mealy machines
Moore machine
inputs Outputs are a function
combinational
logic for of current state
next state
logic for
reg outputs outputs Outputs change
synchronously with
state changes
state feedback
logic for Mealy machine
inputs outputs outputs Outputs depend on state
and on inputs
combinational
logic for reg
next state Input changes can cause
immediate output changes
(asynchronous)
state feedback
Impacts start of the FSM design procedure
➢Counter-design procedure
1. State diagram
2. State-transition table
3. Next-state logic minimization
4. Implement the design
➢FSM-design procedure
1. State diagram
2. State-transition table
3. State minimization
4. State encoding
5. Next-state logic minimization
6. Implement the design
State Diagrams
➢ Moore machine
• Each state is labeled by a pair:
state-name/output or state-name [output]
➢ Mealy machine
• Each transition arc is labeled by a pair:
input-condition/output
Example 10 → 01: Moore or Mealy?
• Circuits recognize AB=10 followed by AB=01
• What kinds of machines are they?
out
A
D Q D Q
Q Q
B
D Q D Q
Q Q
out
clock
A
D Q
Moore
Q
B
D Q
Mealy
Q
clock
Example “01 or 10” detector: a Moore machine
• Output is a function of state only
• Specify output in the state bubble
0
current next current
1 reset input state state output
B/0 D/1
1 – – A 0
0 0 0 A B 0
0 0 1 A C 0
reset 0 0 B B 0
A/0 1 0
0 1 B D 0
1 0 0 C E 0
1 0 1 C C 0
0 0 D E 1
C/0 E/1 0 1 D C 1
0
0 0 E B 1
1 0 1 E D 1
Example “01 or 10” detector: a Mealy machine
• Output is a function of state and inputs
• Specify outputs on transition arcs
0/0
current next current
B
reset input state state output
0/0
1 – – A 0
reset/0 0 0 A B 0
A 0/1 1/1 0 1 A C 0
0 0 B B 0
1/0 0 1 B C 1
C 0 0 C B 1
0 1 C C 0
1/0
Detect input sequence 1101
din
clk dout
fsm
clr
din 1 0 1 1 0 1 1 0 1 0 0 1 1 0 1 0
dout 0 0 0 0 0 1 0 0 1 0 0 0 0 0 1 0
Creating a State Diagram
Detect input sequence 1101
0
1 S1
0 1
S0 0
0
S11
0
0
1
CLR 0 1
S1101
1 S110
1 0
Mealy and Moore Machine
In general, a sequential machine will have the following:
1. A set S containing a finite number, say p, of internal states, so that
S={S1, S2,……Sp}
2. A set X having a finite number, say n, of inputs, so that
X={X1, X2,……Xn}
3. A set Z containing a finite number, say m, of outputs, so that
Z={Z1, Z2,……Zm}
4. A characterizing function f that uniquely defines the next state St+1 as a function of the present state St and the
present input Xt , so that St+1 = f(St , Xt )
5.A) Mealy machine
A characterizing function g that uniquely defines the output Zt as a function of the present input Xt and the
present internal state St , so that
Zt = g(St , Xt )
5.B) Moore machine
A characterizing function g that uniquely defines the output Zt as a function of the present internal state St , so that
Zt = g(St )
Mealy and Moore Machine
A sequential machine can therefore formally be defined as follows:
Definition:A sequential machine is a quintuple,
M=(X,Z,S,f,g), where X, Z and S are the finite and nonempty sets of inputs, outputs, and states
respectively.
f is the next-state function, such that
St+1 = f(St , Xt )
and the g is the output function such that
Zt = g(St , Xt ) for a Mealy machine
Zt = g(St ) for a Moore machine
To describe a sequential machine, either a state table or a state diagram is used.
State table
➢Table1 is a state table describing an example sequential
machine M1. It can be seen that machine M1 has a set of
four internal states A,B,C and D, a set of two inputs I1 and
I2 and a set of outputs O1 ,O2
➢The characterizing functions f and g are depicted in
tabular form, which is the state table.
State table
• State table of a Mealy machine M1
Present state Next state, output
Input
I1 I2
A A,O1 B,O2
B D,O2 A,O1
C B,O1 D,O2
D A,O1 C,O1
State table
➢ For example, for the present state B when the input is I1, the next state is D and the output is O2. If
the input is I2, the next state is A and the output is O1.
➢ Thus the table shows the next state and the output for each combination of the present state and the
input.
➢ Since the output of the machine M1 depends on both the present state and the input, it is a Mealy
machine.
➢ Table2 shows the state table of a Moore machine. Here the output is independent of the input and
depends only on the present state of the machine.
➢ Therefore, this table has a separate column defining the outputs, and two input columns defining the
next state without having any output associated with it.
State table
• State table of a Moore machine M2
Present state Next state
Input Output
I1 I2
A B C O1
B C D O2
C A C O1
D A C O2
State table
➢ Another interesting property of of the machines M1, M2 which we have depicted in the two state tables is
that for all combinations of present state and input, the next state and the output are completely
specified. Such machines are therefore called completely specified sequential machines (CSSMs).
➢ There is another clas of sequential machines, where sometimes the next state or the output or both may
remain unspecified. Such machines are known as incompetely specified sequential machines (ISSMs).
State diagram
➢ The information contained in the state table can also be shown in a graphical manner with the help of
nodes conected by directed graphs. Such diagrams are called state diagrams.
➢ Following figures show the state diagrams of machines M1 and M2 respectively.
State diagram of the Mealy machine M1 State diagram of the Moore machine M2
0
0/0
1
B/0 D/1
B
0/0 0
0
reset/0 reset
A 0/1 1/1 A/0 1 0
1
1/0 1
C C/0 E/1
0
1/0
1
Comparing Moore and Mealy machines
• Moore machines
+ Safer to use because outputs change at clock edge
– May take additional logic to decode state into outputs
• Mealy machines
+ Typically have fewer states
+ React faster to inputs — don't wait for clock
– Asynchronous outputs can be dangerous
Synchronous (registered) Mealy machine
• Registered state and registered outputs
• No glitches on outputs
• No race conditions between communicating machines
logic for reg
inputs outputs outputs
combinational
logic for reg
next state
state feedback
Example “=01”: Moore or Mealy?
➢ Recognize AB = 01
➢ Mealy or Moore?
A
out
D Q
B
Registered Mealy
clock
(actually Moore)
Q
A
D Q out
B Moore
D Q
clock
Q
Applications of Flip-Flops
Counters
➢ A clocked sequential circuit that goes through a predetermined sequence of states.
➢ A commonly used counter is an n-bit binary counter. This has n FFs and 2n states which are passed through in
the order 0, 1, 2, ….2n-1, 0, 1, .
Uses include:
➢ Counting
➢ Producing delays of a particular duration.
➢ Sequencers for control logic in a processor.
➢ Divide by m counter (a divider), as used in a digital watch.
Memories, e.g.,
➢ Shift register
➢ Parallel loading shift register : can be used for parallel to serial conversion in serial data communication
➢ Serial in, parallel out shift register: can be used for serial to parallel conversion in a serial data
communication system.
End
of
Unit-4