Академический Документы
Профессиональный Документы
Культура Документы
A grid of squares
SIMPLIFYING LOGIC Each square represents one product term
eg: top-left represents A B C , bottom-right represents A B C
CIRCUITS
The variables are ordered according to Gray code
only one variable changes between adjacent squares
Squares on edges are considered adjacent to squares on opposite edges
2nd semester, 2012/13 ENGG1203 - K. Wong 3 2nd semester, 2012/13 ENGG1203 - K. Wong 4
4 Variable K map
AB\CD
00
00 01 11 10
Filling out a Karnaugh Map
n Given an initial (unsimplified) logic Boolean expression
01 ? ?? n Write the expression in SOP form
11 n For each product term, write a 1 in all the squares which are included in the
term, 0 elsewhere
10 All variables present in the product term: one square
One variable missing: two adjacent squares
The square marked ? represents A B C D Two terms missing: 4 adjacent squares
A\BC 00 01 11 10
The square marked ?? represents A B C D nExample 1:
0 0 0 1 0
Note that they differ in only the C variable. X = ABC + ABC + ABC + ABC
1 0 1 1 1
Karnaugh maps become clumsier to use with more than 4 variables
A\BC 00 01 11 10
General procedure for using K map: n Example 2:
0 1 0 0 0
1. Fill out the K map for a given Boolean expression X = BC + ABC + AC 1 1 1 1 1
2. Simplify the expression by properly combining those squares in the
K map that contains 1s. This process is called looping A\BC 00 01 11 10
n Example 3: 0 1 1 0 1
X = B + ABC + A 1 1 1 1 1
2nd semester, 2012/13 ENGG1203 - K. Wong 5 2nd semester, 2012/13 ENGG1203 - K. Wong 6
2nd semester, 2012/13 ENGG1203 - K. Wong 9 2nd semester, 2012/13 ENGG1203 - K. Wong 10
AB + C D BD + ABC
2nd semester, 2012/13 ENGG1203 - K. Wong 11 2nd semester, 2012/13 ENGG1203 - K. Wong 12
Dont Care Conditions Quick Quiz
n In certain cases, some of the input conditions may never occur or it AB\CD 00 01 11 10 AB\CD 00 01 11 10
may not matter what happens even if they do
00 0 0 0 1 00 0 1 0 0
In such cases we fill in the K map with and X
meaning don't care 01 0 1 1 0 01 0 1 1 1
When minimizing an X is like a "joker" 11 0 1 1 0 11 1 1 X 0
X can be 0 or 1 - whatever helps best with the minimization 10 0 0 X 0
10 0 0 X X
E.g.,: ABC will never occur or we dont care what is the output
even if it occur
A\BC 00 01 11 10 1
BCD + BD 1
ABC + ACD + ACD + ABC
0 0 0 1 X
2
BCD + BD 2
ABC + ACD + ABC + BD
1 0 0 1 1
3
ABCD + BD 3
ABC + ACD + ABC
simplifies to B if X is assumed 1
If we assume X = 0, the output becomes AB+BC, which is more 4
ABCD + BD 4
ABC + ACD + ACD + ABC
complicated
2nd semester, 2012/13 ENGG1203 - K. Wong 13 2nd semester, 2012/13 ENGG1203 - K. Wong 14
2nd semester, 2012/13 ENGG1203 - K. Wong 15 2nd semester, 2012/13 ENGG1203 - K. Wong 16
From Binary to Decimal
Example
n Note that the value of a binary number is n Convert the binary number 11001 into
given by: decimal representation
2i bi 25
24
23
22
21
20
i= 0
2nd semester, 2012/13 ENGG1203 - K. Wong 17 2nd semester, 2012/13 ENGG1203 - K. Wong 18
1
0
1
00000000
00000001
4
100
00000100
Successively divide the 2
9
1
bitstrings that corresponds to
dividend by 2 their binary representation 5
101
00000101
2
4
0
6
110
00000110
The remainders form the n Represents equally spaced 7
111
00000111
resulting binary number when 2
2
0
integers on the number line
8
1000
00001000
counted from the bottom 1
n Sometimes called unsigned 9
1001
00001001
integer
n Example: Converts 1910 into 10
1010
00001010
0
1
2
3
4
5
6
7
8
2nd semester, 2012/13 ENGG1203 - K. Wong 19 2nd semester, 2012/13 ENGG1203 - K. Wong 20
Positive Integers
Positive Integers Addition
n With a bitstring of width n, the following n Two +ve integers can be added similar to the
properties hold: way decimal numbers are added in long
min value : 0 addition
max value : 2 n 1
n The value of a bistring {bn1 bn2b0 }can be 2
3
1
0
1
1
1
calculated as: +
1
1
9
+
1
1
0
1
0
1
1
1
1
n1
2i bi 4
2
1
0
1
0
1
0
i= 0
n E.g. The value of
101112 = 2 4 + 2 2 + 21 + 2 0 How do we implement binary addition in
= 16 + 4 + 2 + 1 hardware?
= 23
2nd semester, 2012/13 ENGG1203 - K. Wong 21 2nd semester, 2012/13 ENGG1203 - K. Wong 22
Half Adder
Full Adder
n Basic addition of two 1-bit values n The subsequent bits need to be slightly
n Generate a carry out to the next bit if the smarter than a half adder
result is 2
There may be carry input from the bit to the right
Short Summary
n Truth Table, Schematics and Boolean Expression
are 3 different ways to represent the same
functionality
Conversion between the 3 is relatively straight-forward
TT is the only representation that is unique
n Logic circuits can be minimized/manipulated by
Boolean algebra
May use TTs for proofs as they are unique
K map is a handy graphical ways to obtain minimized
logic functions
n Combinational techniques allow us to build large
circuits
Multi-bit Adder from single-bit HA and FA
2nd semester, 2012/13 ENGG1203 - K. Wong 27 2nd semester, 2012/13 ENGG1203 - K. Wong 28
Administrivia
Combinational vs Sequential
n Homework 1 has been posted on Course website +
Moodle today
Due on Feb 22, 2013
n Individual homework Sequential
Combinational
You may discuss the basic idea of the homework questions
with your classmates, but you must complete the questions
on your own and submit your own work.
n Make sure you finalize your submission in the Moodle
system. n In combinational logic, the output is a pure
Make changes to your draft as many time as you want function of the present input only, i.e. no
Finalize when it is ready
Will not cater I uploaded the wrong file requests
memory effect
n Remember, plagiarism is a serious act with heavy n In sequential logic, the output depends not
consequences
only on the present input, but also on the
history of the input, i.e. memory effect
2nd semester, 2012/13 ENGG1203 - K. Wong 29 1st semester, 2012 ENGG1015 - H. So 30
2nd semester, 2012/13 ENGG1203 - K. Wong 31 2nd semester, 2012/13 ENGG1203 - K. Wong 32
State Elements
Flip-Flops
n A state element (circuit component) stores a n An edge-trigger flip-flop (FF) is a circuit
1 or 0 permanently regardless of the that changes it output only when the value
changes in input of its clock input changes
0 1 = Rising Edge
n Simple example: 1 0 = Falling Edge
If x is 0, then y is 1, then x is 0,
x y n For simplicity, we will only use rising edge
If x is 1, then y is 0, then x is 1, triggered FF in this class
The value stored inside the circuit will not change
n An edge-triggering signal pin is usually
clk
To be useful: Need a way to change the state
denoted by a wedge in the schematic
symbol.
2nd semester, 2012/13 ENGG1203 - K. Wong 33 2nd semester, 2012/13 ENGG1203 - K. Wong 34
clk clk
n Which of the following best describes the n The value at x contains the value of x from previous
function of the circuit above? cycle
1
Always output the inverse of x n y = x x" = TRUE iff exactly one of the two is
TRUE
Always output x in previous cycle
2
x=0, x=1
Output 1 when x changes from 1 to 0
3
x=1, x=0
Output 1 when x stays 0 for 2 cycles
4
n y is HIGH for 1 cycle if the value of x changes from its
value in previous cycle
n Note the DFF has given us memory of x from
previous cycle
2nd semester, 2012/13 ENGG1203 - K. Wong 37 2nd semester, 2012/13 ENGG1203 - K. Wong 38
y
Timing
x
D
Q
clk
x
D
Q
clk
Example Implement Toggle FF
n A toggle flip-flop toggles the output at rising
clk
clock edge when the toggle signal (T) is
HIGH.
y x is a delayed Otherwise, the output remains unchanged.
version of x
x T
T
Q
x Q clk
instantly
y = x x"
clk clk
time
cycle
0
1
2
3
4
x
0
1
1
0
0
Can we use a DFF to implement a TFF?
y
0
1
0
1
0
2nd semester, 2012/13 ENGG1203 - K. Wong 39 2nd semester, 2012/13 ENGG1203 - K. Wong 40
Ex: Implementing TFF with DFF
Ex: Implement TFF using DFF
n 1st step: express the function of TFF in a table n 2nd step: Use a DFF to implement the function
similar to a truth table of storing next_Q into Q after the next clock
next_Q denotes the value that should be output at edge
Q after the next clock edge
T
Q
next_Q
Current Next Q
0
0
0
cycle
cycle
next_Q
D
Q
Q
0
1
1
T
clk
1
0
1
T
clk
1
1
0
Q
Q
next_Q
clk
T
2nd semester, 2012/13 ENGG1203 - K. Wong 41 2nd semester, 2012/13 ENGG1203 - K. Wong 42
Register
d3
D
Q
q3
Accumulator
n A register is a parallel clk
n An accumulator accumulates the input values (x)
composition of D-flip-flops. into the internally stored sum on every clock
An n-bit register contains n edge.
d2
q2
D
Q
DFFs X x0 x1 x2
clk
n A register stores multi-bit sum 0 x0 x0 + x1 x0 + x1 + x2
values d1
q1
clk
D
Q
n For simplicity, a single bus clk
connection to a DFF NOTE
symbol is often used
d0
q0
n Instead of simple 0 and 1, the value in the
D
Q
clk
signal X and S are used
clk
clk
clk
n The initial value of S must be reset to the value
zero for correct behavior
2nd semester, 2012/13 ENGG1203 - K. Wong 43 2nd semester, 2012/13 ENGG1203 - K. Wong 44
Synchronous vs Asynchronous
Accumulator
Sequential Circuit
current_sum
next_sum
A
S
sum
This synchronous
x
B
clk
Course
Sequential
Combinational
clk
asynchronous
WAIT_CARD WAIT_PASS
reset
Passenger Passed Gate Close
2nd semester, 2012/13 ENGG1203 - K. Wong 49 2nd semester, 2012/13 ENGG1203 - K. Wong 50
reset
reset
Passenger Passed Gate Close Passenger Passed Gate Close
2nd semester, 2012/13 ENGG1203 - K. Wong 51 2nd semester, 2012/13 ENGG1203 - K. Wong 52
State Transition Diagram
Quick Quiz
n A graphical tool to describe reset
n Which of the following is/ reset
the behavior of an FSM are possible sequence(s)
n Represent states as blocks of states that the FSM
S0
may go through? S0
Labeled: name of the state
n Represent transitions as S1
S1
directed edge 1
S0 S1 S3 S2 S0
Direction of an edge S0 S1 S1 S2 S2 S0
2
represents the direction of S3
S3
state transition S0 S0 S1 S1 S3 S3 S3
3
S2 S2 S0 S0 S0 S0
4
n All possible states & S2
S2
transitions are included
2nd semester, 2012/13 ENGG1203 - K. Wong 53 2nd semester, 2012/13 ENGG1203 - K. Wong 54
reset
n Each state transition is labeled with:
Passenger Passed Gate Close
1. Condition that the transition should take place
2. Output of the FSM during the transition
n The gate should only open after a valid
n There should only be 1 active transition at Octopus card is scanned.
any one time
n It should close the gate after a person has
The input conditions of all transitions in a FSM
passed through the gate.
should be mutually exclusive
2nd semester, 2012/13 ENGG1203 - K. Wong 55 2nd semester, 2012/13 ENGG1203 - K. Wong 56
FSM in Hardware
Ticket Gate Control (1)
n FSM can be efficiently implemented in Card Valid Gate Close
Card Valid Gate Open
Passenger Passed Gate Open
circuits reset
Passenger Passed Gate Close
reset
reset
Passenger Passed Gate Close Passenger Passed Gate Close
Step 2: Determine how the FSM states will be Step 3: Implement the state transition logic
represented in hardware n At each cycle, determine what is the next state
this FSM should be in the next cycle
n 2 FSM states 1 DFF needed Determine which transition is active by checking all the
transition conditions
n Encode the state as follows:
0 WAIT_CARD state n The next state logic is a combinational function of
the current state and the input signals
1 WAIT_PASS state
The input to the state register
Can be found using a truth table
2nd semester, 2012/13 ENGG1203 - K. Wong 59 2nd semester, 2012/13 ENGG1203 - K. Wong 60
Ticket Gate Control (3b)
Ticket Gate Control (4a)
Card Valid Gate Close Passenger Passed Gate Open
Card Valid Gate Close Passenger Passed Gate Open
Card Valid Gate Open Card Valid Gate Open
WAIT_CARD
WAIT_PASS
WAIT_CARD
WAIT_PASS
reset
reset
Passenger Passed Gate Close
Passenger Passed Gate Close ns = s valid + s passed Step 4: Determine the output logic
s
valid
passed
ns
n Can be performed similar to the way the next
0
0
0
0
0
0
1
0
state logic is obtained
0
1
0
1
0
1
1
1
1
0
0
1
1
0
1
0
1
1
0
1
1
1
1
0
2nd semester, 2012/13 ENGG1203 - K. Wong 61 2nd semester, 2012/13 ENGG1203 - K. Wong 62