Lecture 7
Lecture 7
and Counters
Ebrahim Karami
ENGI-9819
Computer Hardware Foundations
Winter 2023
Building Complex Memory Elements
Start-up States
Asynchronous vs. Synchronous logic
Registers
Storage unit. Can hold an n-bit value
Composed of a group of n flip-flops
Each flip-flop stores 1 bit of information
Normally use D flip-flops
D Q
Dff
clk
D Q
Dff
clk
D Q
Dff
clk
D Q
Dff
clk
Controlled Register D Q
Dff
clk
D Q
Dff
clk
D Q
Dff
clk
D Q
Dff
clk
Registers
Group of storage elements read/written as a unit
Shift Registers
Storage + ability to circulate data among storage elements
Q1 Q2 Q3 Q4
1 0 0 0
Shift
0 1 0 0
Shift
0 0 1 0
Shift
0 0 0 1
Shift
Shift from left storage Q1
element to right neighbor
on every lo-to-hi transition Q2
on shift signal
Q3
Wrap around from rightmost Q4
element to leftmost element
Master Slave FFs: sample inputs while
clock is high; change outputs on
falling edge
Shift Registers I/O
Serial vs. Parallel Inputs
Serial vs. Parallel Outputs
Shift Direction: Left vs. Right
Serial
transmission
Counters
Proceed through a well-defined sequence of states in response to
count signal
3 Bit Up-counter: 000, 001, 010, 011, 100, 101, 110, 111, 000, ...
3 Bit Down-counter: 111, 110, 101, 100, 011, 010, 001, 000, 111, ...
0 1 1 1 1
1 1 1 1 1 QA QB QC
TSQ T SQ T SQ
CLK CLK CLK
B Q Q Q
TA = 1 R R R
\Reset
C
CB
Count
A 00 01 11 10
0 0 0 0 0
Timing Diagram:
1 1 1 1 1
100
B
TB = A \Reset
CB
C QC
A 00 01 11 10
QB
0 0 0 0 0
QA
1 0 1 1 0
Count
B
TC = A • B
Ripple Counter
Present Next
State State
Present Next
State State
CB CB
A 00 01 11 10 A 00 01 11 10
0 0
1 1
C+ = B+ =
CB
A 00 01 11 10
0
A+ =
Counter Design
Present Toggle
State Inputs
CBA TC TB TA
Q Q+ T
000 0 1 0
0 0 0 001 XXX
0 1 1 010 0 0 1
1 0 1 011 1 1 0
1 1 0 100 XXX
101 0 1 1
110 1 1 0
Toggle Excitation 111 XXX
Table
Remapped Next State
Functions
Resultant Counter Design
Remapped K-Maps
CB CB
A 00 01 11 10 A 00 01 11 10
0 0
1 1
TC TB
CB
A 00 01 11 10
0
TA
TC = A’ C + A C’ = A xor C
TB = A + B’ + C
TA = A’ B C + B’ C
Resultant Circuit for Complex Counter
Resulting Logic:
5 Gates
13 Input Literals + TC S Q C TB B TA A
T T S Q T S Q
Flipflop connections CLK Q CLK Q CLK Q
R \C R \B R \A
Count
\Reset
A
C TC \A
B
C TA
A
Timing Waveform: TB \B
\B
C
C
100
Count
\Reset
0 0 0 0 1 1 0
C
B 0 0 1 1 0 1 0
A 0 0 0 1 1 0 0
Implementing Counters with Different FFs
Different counters can be implemented best with different
FFs
Steps in building a counter
Build state diagram
Build state transition table
Build next state K-map
Implementing the next state function with different FFs
Toggle flip flops best for binary counters
Existing CAD software for finite state machines favor D
FFs
Implementing 5-state counter with RS FFs
CB CB
A 00 01 11 10 A 00 01 11 10
0 X X 1 X 0 0 0 0 X
1 1 X 1 X X
X 0 X 0
RC = A
RC SC
CB CB SC = A
A 00 01 11 10 A 00 01 11 10
0 0 0 1 X 0 1 X 0 X
RB = A B + B C
1 1 SB = B
X 1 X 0 X 0 X 1
RB SB RA = C
CB CB SA = B C
A 00 01 11 10 A 00 01 11 10
0 X 0 X X 0 0 1 0 X
1
X 0 X 1 1
X X X 0
RA SA
Implementation With RS FFs
C B A
\A R Q RB R Q C R Q
CLK CLK CLK
A S Q \B S Q SA S Q
\C \B \A
Count
A
RB B SA
C
B \C
0 0 0 X 000 0 1 0 0 X 1 X 0 X
0 1 1 X 001 XXX X X X X X X
1 0 X 1 010 0 1 1 0 X X 0 1 X
1 1 X 0 011 1 0 1 1 X X 1 X 0
Q+ = S + R Q 100 XXX X X X X X X
RS Exitation Table 101 1 1 0 X 0 1 X X 1
110 0 0 0 X 1 X 1 0 X
111 XXX X X X X X X
1 1
JC = A
JC KC
CB CB KC = A/
A 00 01 11 10 A 00 01 11 10
0 0 JB = 1
1 1 KB = A + C
JB KB JA = B C/
CB CB KA = C
A 00 01 11 10 A 00 01 11 10
0 0
1 1
JA KA
Implementation with JK FFs
+
A J Q C J Q B JA J Q A
CLK CLK CLK
\A K Q KB K Q C K Q
\C \B \A
Count
A B
KB JA
C \C
DC = A
DB = A C + B
DA = B C
C B A
A D Q DB D Q DA D Q
\C
B
\A DB DA
\C
\B
But yielded worst gate and literal count for this example!
Tend to yield best choice for packaged logic where gate count is key