Digital-Electronics 5
Digital-Electronics 5
Counters
Counters are a specific type of
sequential circuit.
Like registers, the state, or the flip-flop
values themselves, serves as the
“output.”
The output value increases by one on
each clock cycle.
After the largest value, the output
“wraps around” back to 0.
Using two bits, we’d get something like
this:
1
Present State Next State 00 01
A B A B
0 0 0 1
0 1 1 0 1 1
1 0 1 1
1 1 0 0 1
11 10
Benefits of counters
Counters can act as simple clocks to keep track of “time.”
You may need to record how many times something has happened.
– How many bits have been sent or received?
– How many steps have been performed in some computation?
All processors contain a program counter, or PC.
– Programs consist of a list of instructions that are to be executed one
after another (for the most part).
– The PC keeps track of the instruction currently being executed.
– The PC increments once on each clock cycle, and the next program
instruction is then executed.
• In digital logic and computing, a counter is a device
which stores (and sometimes displays) the number of
times a particular event or process has occurred, often in
relationship to a clock signal.
11
Classifications of Counters
Asynchronous Counters
Only the first flip-flop is clocked by an external clock. All
subsequent flip-flops are clocked by the output of the
preceding flip-flop.means output of previous flip-flop is
connected to clock input of next flip flop.
Asynchronous counters are slower than synchronous
counters because of the delay in the transmission of the
pulses from flip-flop to flip-flop.
Asynchronous counters are also called ripple-counters
because of the way the clock pulse ripples it way through
the flip-flops.
Synchronous Counters
All flip-flops are clocked simultaneously by an external
clock. Means clock input of all flip flops are connected to
same external clock.
Synchronous counters are faster than asynchronous
counters because of the simultaneous clocking.
Synchronous counters are an example of state machine
design because they have a set of states and a set of
transition rules for moving between those states after
each clocked event.
States / Modulus / Flip-Flops
The number of flip-flops determines the count
limit or number of states.
(STATES = 2 # of flip flops)
4. Cascaded counter
5. Decade Counter
Asynchronous Counters 10.5
J Q0 J Q1
CLK C C
Q0
K K
FF0 FF1
CLK 1 2 3 4
Q0 Timing diagram
00 01 10 11 00 ...
Q0 0 1 0 1 0
Q1 0 0 1 1 0
Asynchronous (Ripple) Counters
Example: 3-bit ripple binary counter.
HIGH
J Q0 J Q1 J Q2
CLK C Q0 C Q1 C
K K K
FF0 FF1 FF2
CLK 1 2 3 4 5 6 7 8
Q0 0 1 0 1 0 1 0 1 0
Q1 0 0 1 1 0 0 1 1 0
Q2 0 0 0 0 1 1 1 1 0
Recycles back to 0
Asynchronous (Ripple) Counters
Propagation delays in an asynchronous (ripple-
clocked) binary counter.
If the accumulated delay is greater than the clock
pulse, some counter states may be
misrepresented!
CLK 1 2 3 4
Q0
Q1
Q2
tPHL (CLK to Q0) tPHL (CLK to Q0)
tPLH (Q0 to Q1) tPHL (Q0 to Q1)
tPLH
(CLK to Q0) tPLH (Q1 to Q2)
Asynchronous (Ripple) Counters
Example: 4-bit ripple binary counter (negative-
edge triggered).
HIGH
Q0 Q1 Q2 Q3
J J J J
CLK C C C C
K K K K
FF0 FF1 FF2 FF3
CLK
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Q0
Q1
Q2
Q3
n
Asyn. Counters with MOD no. < 2
States may be skipped resulting in a truncated
sequence.
Technique: force counter to recycle before going
through all of the states in the binary sequence.
Example: Given the following circuit, determine
the counting sequence (and hence the modulus
no.) CQ J B Q J AQ J
All J, K CLK CLK CLK
inputs are Q K Q K Q K
CLR CLR CLR
1 (HIGH).
B
C
n
Asyn. Counters with MOD no. < 2
Example (cont’d):
CQ J B Q J A Q J
All J, K CLK CLK CLK
inputs are Q K Q K Q K
CLR CLR CLR
1 (HIGH).
B
C
1 2 3 4 5 6 7 8 9 10 11 12
MOD-6 counter
Clock produced by clearing
A (a MOD-8 binary
B counter) when count
C of six (110) occurs.
NAND1
0
Output
n
Asyn. Counters with MOD no. < 2
Example (cont’d): Counting sequence of circuit
(in CBA order).
1 2 3 4 5 6 7 8 9 10 11 12
Clock
A 0 1 0 1 0 1 0 1
0 0 1 1 0 0 0 0
B
0 0 0 0 1 1 0 0
C
NAND 1
Output 0
Temporary 11 00
state 1 00
0 Counter is a MOD-6
11 1 counter.
01
0 0
10 01
1 10 1
0
n
Asyn. Counters with MOD no. < 2
Exercise: How to construct an asynchronous
MOD-5 counter? MOD-7 counter? MOD-12
counter?
Question: The following is a MOD-? counter?
FQ J EQ J DQ J CQ J BQ J AQ J
Q K Q K Q K Q K Q K Q K
CLR CLR CLR CLR CLR CLR
C
D All J = K = 1.
E
F
CS1104-13 Asynchronous 22
Counters with
n
Asyn. Counters with MOD no. < 2
Decade counters (or BCD counters) are
counters with 10 states (modulus-10) in their
sequence. They are commonly used in daily
life (e.g.: utility meters, odometers, etc.).
Design an asynchronous decade counter.
(A.C)'
HIGH
D C B A
J Q J Q J Q J Q
CLK C C C C
K K K K
CLR CLR CLR CLR
CS1104-13 Asynchronous 23
Counters with
n
Asyn. Counters with MOD no. < 2
Asynchronous decade/BCD counter (cont’d).
HIGH D C B A
J Q J Q J Q J Q (A.C)'
CLK C C C C
K K K K
CLR CLR CLR CLR
1 2 3 4 5 6 7 8 9 10 11
Clock
D 0 1 0 1 0 1 0 1 0 10
C 0 0 1 1 0 0 1 1 0 00
B 0 0 0 0 1 1 1 1 0 00
A 0 0 0 0 0 0 0 0 1 10
NAND
output
Asynchronous Down Counters
1
Q0 Q1 Q2
J Q J Q J Q 3-bit binary
CLK C C C down counter
Q' K Q' K Q'
K
Asynchronous Down Counters
Example: A 3-bit binary (MOD-8) down counter.
00
1 00 11
0
J
Q0 J Q1 J
Q2
1 1
CLK C
Q
C
Q
C
Q
01 11
Q' K Q' K Q'
K 0 0
01 10
1 10 1
CLK 1 2 3 4 5 6 7 8 0
Q0 0 1 0 1 0 1 0 1 0
Q1 0 1 1 0 0 1 1 0 0
Q2 0 1 1 1 1 0 0 0 0
Cascading Asynchronous Counters
Larger asynchronous (ripple) counter can be
constructed by cascading smaller ripple
counters.
Connect last-stage output of one counter to the
clock input of next counter so as to achieve
higher-modulus operation.
Example: A modulus-32 ripple counter
constructed from a modulus-4 counter and a
modulus-8 counter.
Q0 Q1 Q2 Q3 Q4
J Q J Q J Q J Q J Q
CLK C C C C C
Q' K Q' Q' K Q' K Q'
K K
BCD: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001
• Thus, the BCD encoding for the number 127 would be:
0001 0010 0111
• Whereas the pure binary number would be:
0111 1111
Binary-coded-decimal(BCD) counters
• Consists of two modulo-10 counters, one for each BCD
digit.
• It is necessary to reset the four flip-flops after the count
of 9 has been obtained. Thus the Load input to each stage
is equal to 1 when Q3=Q0=1, which causes 0s to be
loaded into the flip-flops at the next positive edge of the
clock signal.
• Keeping the Enable signal for BCD1 low at all times
except when BCD0 = 9
IBM and BCD
• IBM used the terms binary-coded decimal and BCD for 6-bit
alphamerics codes that represented numbers, upper-case letters and
special characters. Some variation of BCD alphamerics was used in
most early IBM computers, including the IBM 1620, IBM 1400
series, and non-Decimal Architecture members of the IBM
700/7000 series.
• Today, BCD data is still heavily used in IBM processors and
databases, such as IBM DB2, mainframes, and Power6. In these
products, the BCD is usually zoned BCD (as in EBCDIC or ASCII),
Packed BCD (two decimal digits per byte), or "pure" BCD encoding
(one decimal digit stored as BCD in the low four bits of each byte).
All of these are used within hardware registers and processing units,
and in software.