Professional Documents
Culture Documents
Digital System
Digital design is concerned with the design of digital electronic circuits. The subject is
also known by other names such as logic design, switching circuits, digital logic, and
digital systems. Digital circuits are employed in the design of systems of digital
computers, electronic calculators, digital control devices, digital communication
equipments, and many other applications that required electronic digital hardware.
X
0
1
Z
1
0
Z=X
ByDr.OdayA.L.ARidha
x
y
Z = X Y
X
0
0
1
1
Truth table
Y
0
1
0
1
Z
0
0
0
1
X
0
0
1
1
Truth table
Y
0
1
0
1
Z
0
1
1
1
3- OR gate (sum)
x
y
Z = X +Y
Positive and negative logic
There are two choices for logic-level assignment. Choosing the high-level H to
represent logic-1 defines a positive logic system. Choosing the low-level L to represent
logic-1 defines a negative logic system.
ByDr.OdayA.L.ARidha
Logic
value
Signal
value
Logic
value
Signal
value
a) Positive logic
b) Negative logic
Example:
Truth table
Y
Truth table
Y
x
y
z
NAND gate
Truth table
Y
ByDr.OdayA.L.ARidha
x
y
NOR gate
ByDr.OdayA.L.ARidha
5) A( B + C ) = A B + A C (distributive property)
Boolean rules are
1) A + AB = A
2) A + A B = A + B
3) ( A + B)( A + C ) = A + BC
DeMorgan's Theorems
A mathematician named DeMorgan developed a pair of important rules regarding
group complementation in Boolean algebra.
DeMorgan's theorem may be thought of in terms of breaking a long bar symbol.
When a long bar is broken, the operation directly underneath the break changes from
addition to multiplication, or vice versa, and the broken bar pieces remain over the
individual variables.
ByDr.OdayA.L.ARidha
Solution:
Step 1:
a)
ByDr.OdayA.L.ARidha
b)
c)
Step 2:
ByDr.OdayA.L.ARidha
Step 3:
ByDr.OdayA.L.ARidha
Minterms
Maxterms
term
designation
term
designation
000
X Y Z
m0
X +Y + Z
M0
001
X Y Z
m1
X +Y + Z
M1
010
X Y Z
m2
X +Y + Z
M2
011
X Y Z
m3
X +Y + Z
M3
100
X Y Z
m4
X +Y + Z
M4
101
X Y Z
m5
X +Y + Z
M5
110
X Y Z
m6
X +Y + Z
M6
111
X Y Z
m7
X +Y + Z
M7
(sum) and
(product) notation
ByDrOdayAl.ARidha
12
Example
No.
Inputs
Output
Z = F ( A, B ) = (m0 , m3 )
Z = F ( A, B ) = (0,3)
Z = F ( A, B) = A B + A B . (a)
Z = F ( A, B ) = ( A + B ) ( A + B ) .. (b)
Exercise Show that expressions (a) and (b) in the above example are
equivalents.
Karnaugh map
The Karnaugh map, like Boolean algebra, is a simplification tool
applicable to digital logic. The Karnaugh Map will simplify logic faster and
more easily in most cases. Boolean simplification is actually faster than the
Karnaugh map for a task involving two or fewer Boolean variables. It is still
quite usable at three variables, but a bit slower. At four input variables,
Boolean algebra becomes tedious. Karnaugh maps are both faster and easier.
Karnaugh maps work well for up to six input variables, are usable for up to
eight variables. For more than six to eight variables, simplification should be
by CAD (computer automated design).
The outputs of a truth table correspond on a one-to-one basis to Karnaugh
map (simply k-map) entries.
For two input variables A and B k-map is formed as follow:
Starting at the top of the truth table, the A=0, B=0 inputs produce an
output . Note that this same output is found in the Karnaugh map at the
A=0, B=0 cell address, upper left corner of K-map where the A=0 row and
ByDrOdayAl.ARidha
13
B=0 column intersect. The other truth table outputs , , from inputs
AB=01, 10, 11 are found at corresponding K-map locations.
ByDrOdayAl.ARidha
14
ByDrOdayAl.ARidha
15
Examples
Binary
number
Inputs
ABCD
Output
Z
0000
1111
ABC D
ABC D
A B CD
A B CD
A BC D
A BC D
A BCD
A BCD
AB C D
AB C D
AB CD
AB CD
ABC D
ABC D
ABCD
ABCD
Binary
number
Inputs
ABCD
Output
Z
0000
ABCD
ABC D
A B CD
A B CD
A BC D
A BC D
A BCD
A BCD
AB C D
AB C D
AB CD
AB CD
ABC D
ABC D
ABCD
ABCD
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
ByDrOdayAl.ARidha
out = (0,2,8,15)
1
0
0
0
0
0
1
0
0
0
0
0
0
1
out = (0,1,4,5,8,9,12,13,15)
1
0
0
1
1
0
0
1
1
0
0
1
1
0
1
16
Binary
number
Inputs
ABCD
Output
Z
Binary
number
Inputs
ABCD
Output
Z
0000
ABC D
ABC D
A B CD
A B CD
A BC D
A BC D
A BCD
A BCD
1000
1001
AB C D
AB C D
AB CD
AB CD
ABC D
ABC D
ABCD
ABCD
0001
0010
0011
0100
0101
0110
0111
1010
1011
1100
1
1110
1
Binary
number
Inputs
ABCD
Output
Z
0000
ABC D
ABC D
A B CD
A B CD
A BC D
A BC D
A BCD
A BCD
AB C D
AB C D
AB CD
AB CD
ABC D
ABC D
ABCD
ABCD
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
ByDrOdayAl.ARidha
1101
1111
0
1
0
0
0
1
1
out = (3,7,11,12,13,14,15)
0
0
1
0
0
0
1
0
0
0
1
1
1
1
1
17
Binary
number
Inputs
ABCD
Output
Z
0000
1111
ABCD
ABCD
A B CD
A B CD
A BC D
A BC D
A BCD
A BCD
AB C D
AB C D
AB CD
AB CD
ABC D
ABC D
ABCD
ABCD
Binary
number
Inputs
ABCD
Output
Z
0000
ABCD
ABCD
A B CD
A B CD
A BC D
A BC D
A BCD
A BCD
AB C D
AB C D
AB CD
AB CD
ABC D
ABC D
ABCD
ABCD
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
ByDrOdayAl.ARidha
0
1
1
1
0
1
0
0
0
0
1
1
0
1
out = (0,1,2,3,8,9,10,11)
1
1
0
0
0
0
1
1
1
1
0
0
0
0
18
Example
Design a lamp logic circuits that drives five lamps (L1-L5), as shown
in the figure below. These lights work as follows:
No lamps will light for no motion of the bicycle. As speed increases, the
lower lamp, L1 lights, then L1 and L2, then, L1, L2, and L3, until all lamps
light at the highest speed. Once all the lamps illuminate, no further increase
in speed will have any effect on the display. A small DC generator coupled
to the bicycle tire outputs a voltage proportional to speed. It drives a
ByDrOdayAl.ARidha
19
tachometer board which limits the voltage at the high end of speed where all
lamps light. No further increase in speed can increase the voltage beyond
this level. This is crucial because the downstream A to D (Analog to Digital)
converter puts out a 3-bit code, ABC, 23 or 8-codes, but we only have five
lamps. A is the most significant bit, C the least significant bit. The lamp
logic needs to respond to the six codes out of the A to D. For ABC=000, no
motion, no lamps light. For the five codes (001 to 101) lamps L1, L1&L2,
L1&L2&L3, up to all lamps will light, as speed, voltage, and the A to D
code (ABC) increases. We do not care about the response to input codes
(110, 111) because these codes will never come out of the A to D due to the
limiting in the tachometer block. We need to design five logic circuits to
drive the five lamps.
Solution
A/D
000
001
010
011
100
101
110
111
ByDrOdayAl.ARidha
Inputs
ABC
ABC
ABC
A BC
A BC
AB C
AB C
ABC
ABC
L1
L2
Output
L3
L4
L5
20
ByDrOdayAl.ARidha
21
ByDrOdayAl.ARidha
22
Examples:
ByDrOdayAl.ARidha
23
ByDrOdayAl.ARidha
24
Step 1
1
3
4
ABCD
No.
Step2
Step3
0001
-001 (1,9)
10- - (8,9,10,11)
0100
01-0 (4,6)
10- - (8,9,10,11)
1000
100- (8,9)
0110
10-0 (8,10)
1001
011- (6,7)
1010
10
10-1 (9,11)
0111
101- (10,11)
1011
11
-111 (7,15)
1111
15
1-11 (11,15)
For the above example prime-implicant are (-001, 01-0, 011-, -111, 1-11,
10--) or ( B C D , A BD , A BC , BCD , ACD , AB ).
F ( A, B, C , D) = B C D + A BD + A BC + BCD + ACD + AB
25
STEP 1 and 2
Terms
No.
BCD
1,9
A BD
4,6
A BC
6,7
BCD
7,15
ACD
11,15
AB
8,9,10,11
10 11 15
X
X X
X X
X
X
X X
X X X X
STEP 3
Terms
No.
BCD
1,9
A BD
4,6
A BC
6,7
BCD
7,15
ACD
11,15
AB
8,9,10,11
10 11 15
X
X X
X X
X
X
X X
X X X X
Step 4: check each column whose minterms is covered by essential primeimplicants. A check is inserted in the bottom of the columns.
Step 5: uncovered minterms must be included by selecting one or more of
prime-implicants. In our example, we have two minterms (7, 15) uncovered
and three unchecked prime-implicants ( A BC , BCD , ACD ). Selecting BCD
only will lead to covered all minterms; therefore it must be included in the
final simplified expression in addition to essential prime-implicants terms.
F ( A, B, C , D) = B C D + A BD + BCD + AB
ByDrOdayAl.ARidha
26
STEP 4
Terms
No.
BCD
1,9
A BD
4,6
A BC
6,7
BCD
7,15
ACD
11,15
AB
8,9,10,11
10 11 15
X
X X
X X
X
X
X X
X X X X
10 11 15
STEP 5
Terms
No.
BCD
1,9
A BD
4,6
A BC
6,7
BCD
7,15
ACD
11,15
AB
8,9,10,11
X
X X
X X
X
X
X X
X X X X
NOTES
1) We can use decimal number instead of binary numbers
2) Tabulation method can be adopted to give a simplified expression in
product of sums. As in the map method, we have to start with the
complement of the function by taking the 0s as the initial list of
minterms. This list contains those minterms not included in the
original function which are numerically equal to the maxterms of the
function. The tabulation process is carried out with 0s of the function
ByDrOdayAl.ARidha
27
ByDrOdayAl.ARidha
28
Not equivalent
OR equivalent
AND equivalent
Example: implement the following logic circuit using NAND gates only
DrOdayA.L.ARidha
29
Solution:
Step 1:
Step 2:
30
Parity bit
Generated
P
000
001
010
011
100
101
110
111
1
0
0
1
0
1
1
0
DrOdayA.L.ARidha
BC
A
00 01 11 10
0 1
1
1
1
1
P = ( A B C ) = A B C
31
Check
E
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
1
0
0
1
0
1
1
0
0
1
1
0
1
0
0
1
AB
CP
00
00
01
01
11
1
11
10
10
1
1
E = ABC P
Parallel adder
A4 B 4
C5
FA
4
S4
A3 B 3
C4
FA
3
S3
A2 B 2
C3
FA
2
A1 B 1
C2
S2
FA
1
C1
S1
DrOdayA.L.ARidha
32
Carry propagation
An
Bn
Cn+1
HA
HA
Cn
FA n
A2
B2
HA
C3
HA
C2
FA 2
A1
B1
HA
Sn
S2
C2
HA
C1
S1
FA 1
Pi = Ai Bi
Gi = Ai Bi
DrOdayA.L.ARidha
33
Now we can write the Boolean function for the carry output of each
stage and substitute for each its value from the previous equations:
C 2 = G1 + P1C1
C3 = G2 + P2C2 = G2 + P2 (G1 + P1C1 ) = G2 + P2G1 + P2 P1C1
C4 = G3 + P3C3 = G3 + P3G2 + P3 P2G1 + P3 P2 P1C1
Since the Boolean function for each output carry is expressed in sum
of products, each function can be implemented with one level of AND gates
follows by an OR gate. Note that Cn does not have to wait for Cn-1, Cn-2, ...,
and C1 to propagate; in fact, Cn is propagated at the same time as C1, and C2.
A4
B4
P4
C5
C4
C5
P4
S4
P3
S3
P2
S2
G4
A3
B3
P3
C3
Lookahead carry
P2 generator C2
G3
A2
B2
G2
A1
B1
P1
P1
S1
G1
C1
C1
BCD adder
Is a circuit that adds two BCD digits with a possible carry from previous
stage, in parallel, and produces a sum digit also in BCD. Since each input
digit doesnt exceed 9, the output sum cannot be greater 19, (9+9+1).
Suppose we apply two BCD digits to a 4-bit binary adder. The adder
will form the sum in binary and produce a result which may range from 0 to
19. These binary numbers are listed in the table below and are labeled by
symbols K, Z8, Z4, Z2, Z1. K is the carry, and subscripts under the letter Z
represent the weights that can be assigned to the four bits in the BCD code.
The first column in the table lists the binary sums as they appear in the
outputs of a 4-bit binary adder. The output sum of two decimal digits must
DrOdayA.L.ARidha
34
be represented in BCD and should appear in the form listed in the second
column of the table.
K
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
1
Z8
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
0
0
0
0
Binary sum
Z4
0
0
0
0
1
1
1
1
0
0
0
0
1
1
1
1
0
0
0
0
Z2
0
0
1
1
0
0
1
1
0
0
1
1
0
0
1
1
0
0
1
1
Z1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
C
0
0
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
S8
0
0
0
0
0
0
0
0
1
1
0
0
0
0
0
0
0
0
1
1
BCD sum
S4
S2
0
0
0
0
0
1
0
1
1
0
1
0
1
1
1
1
0
0
0
0
0
0
0
0
0
1
0
1
1
0
1
0
1
1
1
1
0
0
0
0
S1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
Decimal
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
In examination the contents of the table, it is apparent that when the sum is
equal or less than 9, the corresponding BCD number is identical, and
therefore no conversion is needed. When the binary sum is greater than 9,
we obtain a nonvalid BCD representation. The addition of 6 to the binary
sum converts it to the correct BCD representation and also produces an
output carry as required.
The logic circuit that detects the necessary correction can be derived from
the table entries. It obvious that correction is needed when the binary sum
has an output carry K=1. The other six combinations from 1010 to 1111 that
need a correction have a 1 in position Z8. To distinguish them from binary
1000 and 1001 which also have a 1 in position Z8, we specify further that
either Z4 or Z2 must have a 1. The condition for a correction and an output
carry can be expressed by the Boolean function:
C = K + Z8Z 4 + Z8Z 2
When C=1, it is necessary to add 6 to the binary sum and provide an output
carry for next stage.
DrOdayA.L.ARidha
35
Addend
Augend
Carry in
Z8
Z4
Z2
Z1
0
4-bit binary adder
S8
S4
S2
S1
Output Carry
Magnitude Comparator
The comparison of two numbers is an operation that determines if one
number is greater than, less than, or equal to the other number. A magnitude
comparator is a combinational circuit that compares two numbers, A and B,
and determines their relative magnitude. The outcome of the comparison is
specified by three binary variables that indicate whether A>B, A=B, or A<B.
If
A = A3 A2 A1 A0
B = B3 B2 B1 B0
We define
xi = Ai Bi + AiBi
i=0, 1, 2, 3
Then
( A = B) = x3 x 2 x1 x0
( A > B) = A3 B3 + x3 A2 B2 + x3 x 2 A1 B1 + x3 x 2 x1 A0 B0
( A < B) = A3 B3 + x3 A2 B2 + x3 x 2 A1B1 + x3 x 2 x1 A0 B0
DrOdayA.L.ARidha
36
Decoders
Discrete quantities of information are represented in digital system with
binary codes. A binary code of n bits is capable of representing up 2n distinct
elements of the coded information. Decoder is a combinational circuit that
converts binary information from n input lines to a maximum of 2n unique
output lines. If n-bit decoded information has unused or dont-care
conditions, the output decoder will have less than 2n output. The name
decoder is also used in conjunction with some code converters such as BCDto-seven-segment decoder.
Inputs
Outputs
XYZ
D0
D1
D2
D3
D4
D5
D6
D7
000
001
010
011
100
101
110
111
1
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
A
B
C
38
Decoder
En
D0
D1
D2
D3
D4
D5
D6
D7
38
Decoder
En
DrOdayA.L.ARidha
D8
D9
D2
D11
D12
D13
D14
D15
37
Outputs
D7
D6
D5
D4
D3
D2
D1
D0
XYZ
0
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
0
0
000
001
010
011
100
101
110
111
0
1
2
3
41
MUX
S0 S1
Output
S1
S0
I0
I1
I2
I3
Select
DrOdayA.L.ARidha
38
I1
I2
I3
I4
I5
I6
I7
10
11
12
13
14
15
I0
I1
I2
I3
I4
I5
I6
I7
81
MUX
B
C
D
DrOdayA.L.ARidha
39
Demultiplexers
It is a combinational logic circuit that receives information on a single line
and transmits this information on one of 2n possible output lines. The
selection of a specific output line is controlled by the bit values of n
selection lines. A decoder with an enable input can function as a
demultiplexer.
14
Demultiplexer
E
Input
D0
D1
D2
D3
A
B
E
Enable
A
B
Select
A
0
0
1
1
B
0
1
0
1
D0
E
0
0
0
D1
0
E
0
0
D2
0
0
E
0
D0
D1
D2
D3
24
Decoder
E
0
1
1
1
1
D3
0
0
0
E
A
X
0
0
1
1
B
X
0
1
0
1
D0
0
1
0
0
0
D1
0
0
1
0
0
D2
0
0
0
1
0
D3
0
0
0
0
1
n Inputs
(Address)
2nm
ROM
m Outputs
(Data)
Memory size=2nm
DrOdayA.L.ARidha
40
ROM types
1) Mask programming ROM
2) Programmable ROM (PROM)
3) Erasable Programmable ROM (EPROM)
4) Electrically Erasable Programmable ROM (E2PROM)
Example: Design a combinational circuit that accept a 3-bit number and
generates an output binary number equal to the square of the input number.
Use a minimum ROM size.
Solution:
Inputs
XYZ
000
001
010
011
100
101
110
111
Outputs
D5
0
0
0
0
0
0
1
1
DrOdayA.L.ARidha
D4
0
0
0
0
1
1
0
1
D3
0
0
0
1
0
1
0
0
D2
0
0
1
0
0
0
1
0
D1
0
0
0
0
0
0
0
0
D0
0
1
0
1
0
1
0
1
X
Y
Z
D5
D4
2 4
ROM
D3
D2
D1
D0
41
DrOdayA.LARidha
42
Clock Signal
From the diagram you can see that the clock period is the time between successive transitions in the same
direction, that is, between two rising or two falling edges. State transitions in synchronous sequential circuits
are made to take place at times when the clock is making a transition from 0 to 1 (rising edge) or from 1 to 0
(falling edge). Between successive clock pulses there is no change in the information stored in memory.
The reciprocal of the clock period is referred to as the clock frequency. The clock width is defined as the
time during which the value of the clock signal is equal to 1. The ratio of the clock width and clock period is
referred to as the duty cycle. A clock signal is said to be active high if the state changes occur at the clock's
rising edge or during the clock width. Otherwise, the clock is said to be active low. Synchronous sequential
circuits are also known as clocked sequential circuits.
The memory elements used in synchronous sequential circuits are usually flip-flops. These circuits are binary
cells capable of storing one bit of information. A flip-flop circuit has two outputs, one for the normal value
and one for the complement value of the bit stored in it. Binary information can enter a flip-flop in a variety
of ways, a fact which give rise to the different types of flip-flops.
In asynchronous sequential circuits, the transition from one state to another is initiated by the change in the
primary inputs; there is no external synchronization. The memory commonly used in asynchronous
sequential circuits are time-delayed devices, usually implemented by feedback among logic gates. Thus,
asynchronous sequential circuits may be regarded as combinational circuits with feedback. Because of the
feedback among logic gates, asynchronous sequential circuits may, at times, become unstable due to transient
conditions. The instability problem imposes many difficulties on the designer. Hence, they are not as
commonly used as synchronous systems.
DrOdayA.LARidha
43
Flip-flops types
1) RS Flip-Flop
Basic flip-flop circuit with NOR gates
S
1
0
0
0
1
0
0
1
0
1
1
1
0
0
0
0
0
1
1
0
after SR=10
after SR=01
Truth table
Basic flip-flop circuit with NAND gates
S
1
1
0
1
0
0
1
1
1
0
0
0
1
1
1
1
1
0
0
1
after SR=10
after SR=01
Truth table
2) Clocked RS Flip-Flop
Qi S
Qi+1
indeterminate
indeterminate
Characteristic table
DrOdayA.LARidha
44
3) D-type Flip-Flop
Qi
Qi+1
0
0
1
1
0
1
0
1
0
1
0
1
Characteristic table
4) JK Flip-Flop
Qi J
Qi+1
Characteristic table
5) T Flip-Flop
Qi
Qi+1
0
0
1
1
0
1
0
1
0
1
1
0
Characteristic table
DrOdayA.LARidha
45
6) Master-slave Flip-Flop
CLK
Master
Slave
Y
Q
CLK
The master-slave combination can be constructed for any type of flip-flop by adding a clock RS flip-flop with
an inverted clock to form the slave
7) Edge-triggered Flip-Flop
tS tH
CLK
D
Q
Valid
Valid
tS Setup time
tH Hold time
Setup time is a definite time in which D input must be maintained at a constant value prior to the application
of the clock pulse.
Hold time is a definite time that D input must be not change after application of positive going transition of
the clock pulse.
DrOdayA.LARidha
46
SR
JK
FLIP-FLOP
SYMBOL
CHARACTERISTIC
TABLE
Q(next)
CHARACTERISTIC
EQUATION
Q(next) = S + R'Q
SR = 0 (condition)
EXCITATION TABLE
Q Q(next) S
Q Q(next) J
Q(next)
Q'
Q(next)
Q(next)
Q(next)
Q(next)
Q'
Q(next) = D
Each of these flip-flops can be uniquely described by its graphical symbol, its characteristic table, its
characteristic equation or excitation table. All flip-flops have output signals Q and Q'.
DrOdayA.LARidha
47
The characteristic table in the third column of the table defines the state of each flip-flop as a function of its
inputs and previous state. Q refers to the present state and Q(next) refers to the next state after the
occurrence of the clock pulse. The characteristic table for the RS flip-flop shows that the next state is equal to
the present state when both inputs S and R are equal to 0. When R=1, the next clock pulse clears the flip-flop.
When S=1, the flip-flop output Q is set to 1. The equation mark (?) for the next state when S and R are both
equal to 1 designates an indeterminate next state.
The characteristic table for the JK flip-flop is the same as that of the RS when J and K are replaced by S and
R respectively, except for the indeterminate case. When both J and K are equal to 1, the next state is equal to
the complement of the present state, that is, Q(next) = Q'.
The next state of the D flip-flop is completely dependent on the input D and independent of the present state.
The next state for the T flip-flop is the same as the present state Q if T=0 and complemented if T=1.
The characteristic table is useful during the analysis of sequential circuits when the value of flip-flop inputs
are known and we want to find the value of the flip-flop output Q after the rising edge of the clock signal. As
with any other truth table, we can use the map method to derive the characteristic equation for each flip-flop,
which are shown in the third column of the table.
During the design process we usually know the transition from present state to the next state and wish to find
the flip-flop input conditions that will cause the required transition. For this reason we will need a table that
lists the required inputs for a given change of state. Such a list is called the excitation table, which is shown
in the fourth column of the table. There are four possible transitions from present state to the next state. The
required input conditions are derived from the information available in the characteristic table. The symbol X
in the table represents a "don't care" condition, that is, it does not matter whether the input is 1 or 0.
DrOdayA.LARidha
48
DrOdayA.LARidha
49
We start with the logic schematic from which we can derive excitation equations for each flip-flop input.
Then, to obtain next-state equations, we insert the excitation equations into the characteristic equations. The
output equations can be derived from the schematic, and once we have our output and next-state equations,
we can generate the next-state and output tables as well as state diagrams. When we reach this stage, we use
either the table or the state diagram to develop a timing diagram which can be verified through simulation.
Now let's look at some examples, using these procedures to analyze a sequential circuit.
This example is taken from D. D. Gajski, Principles of Digital Design, Prentice Hall, 1997, p.230.
SOLUTION:
STEP 1: First we derive the Boolean expressions for the inputs of each flip-flops in the schematic, in
terms of external input Cnt and the flip-flop outputs Q1 and Q0. Since there are two D flip-flops in this
example, we derive two expressions for D1 and D0:
DrOdayA.LARidha
Cnt.Q1.Q0'
50
STEP 3:
Now convert these next-state equations into tabular form called the next-state table.
Present State
Q1Q0
00
01
10
11
Next State
Cnt = 0
Cnt = 1
00
01
10
11
01
10
11
00
Each row is corresponding to a state of the sequential circuit and each column represents one set of input
values. Since we have two flip-flops, the number of possible states is four - that is, Q1Q0 can be equal to 00,
01, 10, or 11. These are present states as shown in the table.
For the next state part of the table, each entry defines the value of the sequential circuit in the next clock
cycle after the rising edge of the CLK. Since this value depends on the present state and the value of the
input signals, the next state table will contain one column for each assignment of binary values to the input
signals. In this example, since there is only one input signal, Cnt, the next-state table shown has only two
columns, corresponding to Cnt = 0 and Cnt = 1.
Note that each entry in the next-state table indicates the values of the flip-flops in the next state if their value
in the present state is in the row header and the input values in the column header.
Each of these next-state values has been computed from the next-state equations in STEP 2.
STEP 4:
The state diagram is generated directly from the next-state table, shown in the Figure below.
State diagram
Each arc is labeled with the values of the input signals that cause the transition from the present state (the
source of the arc) to the next state (the destination of the arc).
DrOdayA.LARidha
51
In general, the number of states in a next-state table or a state diagram will equal 2m , where m is the number
of flip-flops. Similarly, the number of arcs will equal 2m x 2k, where k is the number of binary input signals.
Therefore, in the state diagram, there must be four states and eight transitions. Following these transition
arcs, we can see that as long as Cnt = 1, the sequential circuit goes through the states in the following
sequence: 0, 1, 2, 3, 0, 1, 2,.... On the other hand, when Cnt = 0, the circuit stays in its present state until Cnt
changes to 1, at which the counting continues.
Since this sequence is characteristic of modulo-4 counting, we can conclude that the given sequential circuit
is a modulo-4 counter with one control signal, Cnt, which enables counting when Cnt = 1 and disables it
when Cnt = 0.
Below, we show a timing diagram, representing four clock cycles, which enables us to observe the behavior
of the counter in greater detail.
Timing Diagram
In this timing diagram we have assumed that Cnt is asserted in clock cycle 0 at t0 and is disserted in clock
cycle 3 at time t4. We have also assumed that the counter is in state Q1Q0 = 00 in the clock cycle 0. Note that
on the clock's rising edge, at t1, the counter will go to state Q1Q0 = 01 with a slight propagation delay; in
cycle 2, after t2, to Q1Q0 = 10; and in cycle 3, after t3 to Q1Q0 = 11. Since Cnt becomes 0 at t4, we know that
the counter will stay in state Q1Q0 = 11 in the next clock cycle.
In the previous Example, we demonstrated the analysis of a sequential circuit that has no outputs by
developing a next-state table and state diagram which describes only the states and the transitions from one
state to the next. In the next example we complicate our analysis by adding output signals, which means that
we have to upgrade the next-state table and the state diagram to identify the value of output signals in each
state.
This example is taken from D. D. Gajski, Principles of Digital Design, Prentice Hall, 1997, p.234.
Example Derive the next state, the output table and the state diagram for the sequential circuit shown in the
Figure below.
DrOdayA.LARidha
52
SOLUTION:
The input combinational logic in the above Figure is the same as in the previous example, so the excitation
and the next-state equations will be the same.
Excitation equations:
D0 = Cnt
Q0 = Cnt'.Q0 + Cnt.Q0'
D1 = Cnt'.Q1
Cnt.Q1'.Q0
Cnt.Q1.Q0'
Next-state equations:
Cnt.Q1.Q0'
Y = Q1Q0
Output equation:
As this equation shows, the output Y will equal to 1 when the counter is in state Q1Q0 = 11, and it will stay 1
as long as the counter stays in that state.
Next-state and output table:
Present State
Q1 Q0
00
01
10
11
DrOdayA.LARidha
Next State
Cnt=0
Cnt=1
00
01
10
11
01
10
11
00
Output
Y
0
0
0
1
53
State diagram:
DrOdayA.LARidha
54
specification. The first step in the design of sequential circuits is to obtain a state table or an equivalence
representation, such as a state diagram.
A synchronous sequential circuit is made up of flip-flops and combinational gates. The design of the circuit
consists of choosing the flip-flops and then finding the combinational structure which, together with the flipflops, produces a circuit that fulfils the required specifications. The number of flip-flops is determined from
the number of states needed in the circuit.
The recommended steps for the design of sequential circuits are set out below.
DrOdayA.LARidha
55
STEP 2
State Diagram
STEP 3
Present State
Q0 Q1
Next State
x=0
x=1
00
01
10
11
STEP 4
00
10
10
11
01
01
11
00
State Reduction
Any design process must consider the problem of minimizing the cost of the final circuit. The two most
obvious cost reductions are reductions in the number of flip-flops and the number of gates.
The number of states in a sequential circuit is closely related to the complexity of the resulting circuit. It is
therefore desirable to know when two or more states are equivalent in all aspects. The process of eliminating
the equivalent or redundant states from a state table/diagram is known as state reduction. Two states are
said to be equivalent if, for each member of the set of inputs, they give exactly the same output and send
the circuit either to the same state or to an equivalent state. When two states are equivalent, one of them
can be removed without altering the input-output relationships.
Example: Let us consider the state table of a sequential circuit shown below.
Present State
A
B
C
D
E
F
DrOdayA.LARidha
Next State
x=0
x=1
B
F
D
F
A
B
C
D
E
E
D
C
Output
x=0 x=1
1
0
1
0
0
1
0
0
1
1
0
0
56
It can be seen from the table that the present state A and F both have the same next states, B (when x=0) and
C (when x=1). They also produce the same output 1 (when x=0) and 0 (when x=1). Therefore states A and F
are equivalent. Thus one of the states, A or F can be removed from the state table. For example, if we remove
row F from the table and replace all F's by A's in the columns, the state table is modified as shown in the
table below.
Present State
A
B
C
D
E
Next State
x=0
x=1
B
A
D
A
A
C
D
E
E
D
Output
x=0 x=1
1
0
1
0
0
0
0
1
1
0
State F removed
It is apparent that states B and E are equivalent. Removing E and replacing E's by B's results in the reduce
table below..
Present State
A
B
C
D
Next State
x=0
x=1
B
A
D
A
C
D
B
B
Output
x=0 x=1
1
0
1
0
0
0
1
1
Example 1 We wish to design a synchronous sequential circuit whose state diagram is shown below. The
type of flip-flop to be use is J-K.
DrOdayA.LARidha
57
State diagram
From the state diagram, we can generate the state table shown in Table 9. Note that there is no output section
for this circuit. Two flip-flops are needed to represent the four states and are designated Q0Q1. The input
variable is labeled x.
Present State
Q0 Q1
Next State
x=0
x=1
00
01
10
11
00
10
10
11
01
01
11
00
State table.
We shall now derive the excitation table and the combinational structure. The table is now arranged in a
different form shown in the table below, where the present state and input variables are arranged in the form
of a truth table. Remember, the excitable for the JK flip-flop was derive in the table.
Excitation table for JK flip-flop
Output Transitions
Q Q(next)
0
0
1
1
DrOdayA.LARidha
0
1
0
1
Flip-flop inputs
JK
0 X
1 X
X 1
X 0
58
Next State
Q0 Q1
Input
x
00
00
01
01
10
10
11
11
00
01
10
01
10
11
11
00
0
1
0
1
0
1
0
1
Flip-flop Inputs
J0K0
J1K1
0X
0X
1X
0X
X0
X0
X0
X1
0X
1X
X1
X0
0X
1X
X0
X1
In the first row of the above table, we have a transition for flip-flop Q0 from 0 in the present state to 0 in the
next state. In the table we find that a transition of states from 0 to 0 requires that input J = 0 and input K = X.
So 0 and X are copied in the first row under J0 and K0 respectively. Since the first row also shows a
transition for the flip-flop Q1 from 0 in the present state to 0 in the next state, 0 and X are copied in the first
row under J1 and K1. This process is continued for each row of the table and for each flip-flop, with the input
conditions as specified in the table.
The simplified Boolean functions for the combinational circuit can now be derived. The input variables are
Q0, Q1, and x; the outputs are the variables J0, K0, J1 and K1. The information from the truth table is plotted
on the Karnaugh maps shown in the figure below.
Karnaugh Maps
The flip-flop input functions are derived:
J0 = Q1.x'
J1 = x
DrOdayA.LARidha
K0 = Q1.x
K1 = Q0'.x' + Q0.x = Q0
59
Logic diagram of
the sequential
circuit.
Example 2
Design a sequential circuit whose state tables are specified in the table below, using D flip-
flops.
This example is taken from P. K. Lala, Practical Digital Logic Design and Testing, Prentice Hall, 1996,
p.176.
Next State
x=0
x=1
00
01
10
11
00
00
11
00
Output
x=0 x=1
01
10
10
01
0
0
0
0
0
0
0
1
DrOdayA.LARidha
Flip-flop inputs
D
60
Next step is to derive the excitation table for the design circuit, which is shown in the table below. The output
of the circuit is labeled Z.
Present State
Q0 Q1
Next State
Q0 Q1
Input
x
00
00
01
01
10
10
11
11
00
01
00
10
11
10
00
01
0
1
0
1
0
1
0
1
Flip-flop
Inputs
D0
D1
0
0
0
1
1
1
0
0
0
1
0
0
1
0
0
1
Output
Z
0
0
0
0
0
0
0
1
Excitation table
Now plot the flip-flop inputs and output functions on the Karnaugh map to derive the Boolean expressions,
which is shown in Figure below.
Karnaugh maps
The simplified Boolean expressions are:
D0 = Q0.Q1' + Q0'.Q1.x
D1 = Q0'.Q1'.x + Q0.Q1.x + Q0.Q1'.x'
Z = Q0.Q1.x
Finally, draw the logic diagram.
DrOdayA.LARidha
61
DrOdayA.LARidha
62
State table
Present State
Q2 Q1 Q0
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
Next State
Q2 Q1 Q0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
Since there are eight states, the number of flip-flops required would be three. Now we want to implement the
counter design using JK flip-flops.
Next step is to develop an excitation table from the state table, which is shown in the table below
DrOdayA.LARidha
63
Excitation table
Output State Transitions
Present State
Q2 Q1 Q0
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
Flip-flop inputs
Next State
Q2 Q1 Q0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
J2 K2
J1 K1
J0 K0
0X
0X
0X
1X
X0
X0
X0
X1
0X
1X
X0
X1
0X
1X
X0
X1
1X
X1
1X
X1
1X
X1
1X
X1
Now transfer the JK states of the flip-flop inputs from the excitation table to Karnaugh maps to derive a
simplified Boolean expression for each flip-flop input. This is shown in the Figure below.
The 1s in the Karnaugh maps of the above Figure are grouped with "don't cares" and the following
expressions for the J and K inputs of each flip-flop are obtained:
J0 = K0 = 1
J1 = K1 = Q0
DrOdayA.LARidha
64
J2 = K2 = Q1.Q0
The final step is to implement the combinational logic from the equations and connect the flip-flops to form
the sequential circuit. The complete logic of a 3-bit binary counter is shown in the Figure below.
Logic diagram of a
3-bit binary counter.
Example 4
Design a counter specified by the state diagram in Example 3 using T flip-flops. The state
diagram is shown here again in the Figure below.
This example is taken from M. M. Mano, Digital Design, Prentice Hall, 1984, p.243.
DrOdayA.LARidha
65
Excitation table.
Output State Transitions
Present State
Q2 Q1 Q0
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
Flip-flop inputs
Next State
Q2 Q1 Q0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
T2 T1 T0
0
0
0
1
0
0
0
1
0
1
0
1
0
1
0
1
1
1
1
1
1
1
1
1
Next step is to transfer the flip-flop input functions to Karnaugh maps to derive a simplified Boolean
expressions, which is shown in the Figure below.
T0 = 1;
T1 = Q0;
T2 = Q1.Q0
Finally, draw the logic diagram of the circuit from the expressions obtained. The complete logic diagram of
the counter is shown in the Figure below.
66
Registers
Registers: is a group of binary storage cells suitable for holding binary information.
O4
O3
O2
O1
I3
I2
Simple register
I1
Load
I4
Shift Registers: it is a register that capable of shifting its binary contents either to the left or
right.
O4
Serial in
O3
Q
O2
Q
O1
D
Serial Out
Shift right
Shift-right register
O4
O3
O2
Q
D
O1
CLK
Clear
S1
S0
41
41
41
41
3 2 1 0
3 2 1 0
3 2 1 0
3 2 1 0
SI
for shift right
I4
I3
I2
I1
SI
for shift left
DrOdayA.L.ARidha
67
Serial addition
Two binary numbers must be first loaded to the shift registers. Shift right signal must
be asserted for one word time. Otherwise incorrect results obtained.
CLK
Shift right
Load
Shift register A
Y
Z
Shift register B
F.A
C
Q
Clear
Exercises
1) Design a sequential circuit whose state table is shown below. Use JK flip-flops for the
design.
Present State
Q1 Q0
Next State
x=0
x=1
00
01
10
11
00
01
10
11
01
00
01
00
Output
x=0
x=1
0
0
0
0
0
1
0
1
a
Serial adder
Shift register B
Shift register C
3) Design a logic circuit that count the number of occurs of the sequence 00 11 10 01 11
DrOdayA.L.ARidha
68
Counters
Counters come in two categories: ripples counters and synchronous counters.
1) Ripple Counters
a) Binary ripple counter
A4
To next
Stage
A3
Q
A1
A2
Q
CLK
CLK
CLK
CLK
Count
Pulses
Q8
Q
J
CLK
Q1
Q2
J
CLK
J
CLK
CLK
Count
Pulses
DrOdayA.L.ARidha
Q8 Q4 Q2 Q1
Q8 Q4 Q2 Q1
Q8 Q4 Q2 Q1
BCD Counter
BCD Counter
BCD Counter
102Digit
101 Digit
100 Digit
Count
Pulses
69
2) Synchronous Counters
Synchronous counters are distinguished from ripple counters in that clock pulses are
applied to the CLK inputs of all flip-flops. The common pulse triggers all flip-flops
simultaneously, rather than one at a time in succession as in ripple counters.
a) Synchronous binary counter
A4
A3
A1
A2
CLK
Q
J
CLK
J
CLK
J
CLK
J
CLK
To next
stage
Count
enable
b) Universal binary up/down counters with a parallel load (see Morris Mano p.282)
A4
A3
A2
A1
Load
Clear
4-bit counter
Up/Down
Carry
Enable
CLK
I4
I3
I2
I1
Signal name
Function description
Load
Clear
Up/Down
Enable
Carry
DrOdayA.L.ARidha
70
A3
A2
A1
Load=0
Clear
4-bit counter
Up/Down=1
Max/Min
Enable=1
CLK
I4
I3
I2
I1
(a)
Johnson Counter
CLK
Content
0
1
2
3
4
0000
1000
1100
1110
1111
0111
0011
0001
0000
5
6
7
8
Ring Counter
O4
D
O3
D
O2
D
O1
D
Q
Q
CLK
CLK
Shift Right
Load
DrOdayA.L.ARidha
71
Register
CLK
Inputs
Combinational
circuit
Outputs
Register
ROM
CLK
Inputs
Outputs
3) Sequential logic circuit can be implemented using Programmable logic devices (PLD)
One of the most popular PLD in our university is generic array logic (GAL). This type
of PLD can be used to implement either combinational or sequential logic circuits. There are
number of GAL ICs, like PALCE20V8 and PALCE16V8, which can be erased and
reprogrammed electrically. The general structure of PALCE20V8 is shown in the figure
below:
DrOdayA.L.ARidha
72
GAL consists of micro cells (MC0-MC7). Each micro cell has a general structure is shown
below:
DrOdayA.L.ARidha
73
DrOdayA.L.ARidha
74
DrOdayA.L.ARidha
75
Control Logic
Input
Data
Data processor
Output
Data
The control sequence and data-processing tasks of a digital system are specified by a
mean of a hardware algorithm, a finite number of procedural steps that specify how to obtain
a solution to a problem. The most challenging and creative part of a digital design is the
formulation of hardware algorithms for achieving required objectives.
A flowchart is a convenient way to specify the sequence of procedural steps and
decision paths for an algorithm. A special flowchart that has been developed specially to
define digital hardware algorithms is called Algorithmic state machine (ASM) chart.
The chart is composed of three basic elements: the state box, the decision box, and the
conditional box. A state in the control sequence is indicated by state box. The shape of the
state box is rectangle within which are written register operations or output signal names that
the control generates while being in this state. The state is given a symbolic name, which
placed at the upper left corner of the box. The binary code assigned to the state is placed at
the upper right corner. Inside box is written register operations or output signals.
Binary code
Name
Register operations or
output signals
General description
Dr Oday A.L.A Ridha
001
T1
START
Example
76
The decision box describes the effect of an input on the control subsystem. It has a
diamond-shape box with two or more exit paths, as shown below.
Condition
Exit path
Exit path
The input condition to be tested is written inside the box. One exit path is taken if the
condition is true and another when the condition is false.
The third element of ASM chart is the conditional box. It has an oval shape. The
rounded corner is to differentiate it from state box. The input path of conditional box must
come from one of the exit paths of the decision box. The register operations or outputs listed
inside the conditional box are generated during a given state provided that the input condition
is satisfied.
Register operations or
output signals
ASM block is a structure consisting of one state box and all the decision and
conditional boxes connecting to its exit path. An ASM block has one entrance and any
number of exit paths represented by the structure of the decision boxes. An ASM chart
consists of one or more of interconnected blocks. Each ASM block describes the state of
logic circuit during one clock pulse interval.
ASM block
T1
001
A A+1
0
0
T2
010
T3
One clock
cycle
R 1
011
T4
100
77
001
A A+1
1
E
0
T2
T1
001
A A+1
1
010
T2
Invalid feedback
010
Valid feedback
T1
T1
001
A A+1
001
A A+1
1
0
I1
I2
R 1
I2
K 1
K 1
0
Parallel interconnection
I1
R 1
Serial interconnection
Description
AB
R0
Clear reg. R
AA+1
AA-1
AA+B
78
The ASM chart is very similar to a state diagram. Each state block is equivalent to a
state in sequential circuit. The decision box is equivalent to the binary information
written along the directed lines that connect two states in a state diagram. As
consequence, it is sometimes convenient to convert the chart to a state diagram and
then use sequential circuit procedures to design the control logic.
T1
001
A A+1
001
0
0
EF=00
R 1
E=1
EF=01
010
T2
010
T3
011
T4
100
100
011
The ASM chart gives all the information necessary to design digital system. The
requirements for the design of data-processor subsystem are specified inside the state
and conditional boxes. The control logic (circuit) is determined from decision boxes
and required state transitions.
The control section of a digital system is essentially a sequential circuit that can be
designed by the procedure used for previous lectures. However, in most cases this
method is impractical because of the large number of state and inputs that a typical
control circuit may have, except for small controllers. There are special methods for
control logic design. These methods may be considered as an extension of the
sequential method. One of these methods is design with multiplexers.
79
Example: design a digital system with two flip-flops (E and F) and one 4-bit binary counter
(A). A start signal (S) initiates the system by clearing the counter (A) and the flip-flop (F).
The counter is then incremented by one starting from the next clock pulse, and continues
counting until the operations stop.
operations as follows:
If A3=0, E is cleared to 0 and the counting continues.
If A3=1, E is set to 1; then if A4=0, the counting continues. But if A4=1, F is set to 1 on
the next clock pulse and the system stops counting.
Control
Circuit
T0
T1
Tn
Q
E
K
Combinational
circuit
F
A4 A3
CLK
A2
4-bit
Counter
A1
Clear
Count
80
Solution:
P.S
symbol
T0
T0
T1
T1
T1
T2
P.S.
Code
G 1G 2
00
00
01
01
01
11
I/Ps
S
0
1
X
X
X
X
A3
X
X
0
1
1
X
A4
X
X
X
0
1
X
N.S.
Code
G1G2
00
01
01
01
11
00
O/Ps
T0
1
1
0
0
0
0
T1
0
0
1
1
1
0
T2
0
0
0
0
0
1
T0
00
S
1
A0, F0
01
T1
AA+1
A3
1
E1
E0
J1=QG2A3A4 , K1=1,
J2=S, K2=QG1,
T0=QG2, T1=QG1.QG2, T2=QG1.
1 A
4
11
T2
F1
Clear=S.T0, Count=T1,
JE=T1.A3, KE=T1.A3,
JF=T2, KF=S.T0.
G2
Q
T0
T1
A4
A3
T2
G1
CLK
81
A3
A4
0
1 MUX
2
3
S0 S1
Input
conditions
S
S
A3
A3.A4
A3.A4
Multiplexer inputs
MUX1
MUX2
0
A3.A4
F.F.
G1
T0
T1
Decoder
S
1
0
S0 S1
0
1 MUX
2
3
G2
T2
F.F.
Control circuit
CLK
Dr Oday A.L.A Ridha
82
Exercises
1. A digital system consists of two registers (R1 and R2) and a flip-flop E (as shown in the
figure below). Draw the ASM chart of the control circuit that makes the digital system count
the number of 1s in the number loaded into register R1 and store the result in R2.
Input data
Inputs= All 1s
Load E
SI=0
Shift right
Load R1
Shift register R1
Count
Load R2
Counter R2
Output count
Z=1 if R1=0
Data processor subsystem of 1s counter
Solution
T0
00
S
1
R1input,
R2All 1s
01
T1
R2R2+1
1
T2
Z
0
10
P.S.
G1 G2
0
0
0
0
N.S.
Input
Multiplexer inputs
G1 G2 conditions MUX1
MUX2
0
0
S
0
S
0
1
S
1
1
1
1
1
0
0
1
0
Z
1
E
0
1 MUX
2
3 S0 S1
none
E
E
F.F.
G1
T0
Shift R1 to E
T1
11
T3
Decoder
T2
S
0
1
E
S0 S1
0
1 MUX
2
3
G2
T3
F.F.
Control circuit
CLK
83
84
Z
Register B
Load B
Cout
B - Multiplicand
Q - Multiplier
P - down counter,
initially hold the
length of Q (n)
Z=1 if P=0
Count
Load P
Parallel Adder
Counter P
Q1
Load E
Clear E
Register Q
Register A
E
Clear A
Load A
Shift right
Load Q
Shift right
Solution
T0
P.S.
G1 G2
00
S
T1 1
0
01
A0
Pn
N.S.
Input
Multiplexer inputs
conditions
G1 G2
MUX1 MUX2
none
none
10
T2
PP-1
Q1
AA+B, ECout
E0
1
Z
0
1 MUX
2
3 S0 S1
F.F.
G1
T0
T1
Decoder
11
T3
T2
Shift right AQ
0
Z
S
0
1
0
S0 S1
0
1 MUX
2
3
G2
T3
F.F.
Control circuit
CLK
85
3.Design a circuit that controls the process of mixing and heating two liquids (A and B).
The ratio between A and B in produced mixed liquid must be and at temperature of 100 C.
Design the control circuit in such away that the production is maximum.
M5
Pump
Size= 1 volume
M1
Full A
Sensor
Motor
M2
Empty
A
Size= 2 volume
100 C
M6
M3
Full B
M4
Empty C
Empty B
Heater
Start
Stop
86
T0
000
011
T3
0
Start
M5
1
001
T1
1 Stop
0
0
1 Stop
Heater
0
0
100 C
Full A
M1
T4
100
M5
Full B 1
Full B
0
1 Stop
M3
M3
0
T2
010
M5
0
1
100 C
0
M3
Empty
A
T1
Full A
M1
Heater
0
M6
1 Stop
0
Empty
C
Full B
Full B
0
M3
M2
Empty
B
Empty
B
0
M4
M4
T3
87
Calling Machine A
Calling Machine B
Idle state
Some states
ZA
ZA
ZB
Some states
ZB
Other states
88
X1
X2
Z1
Z2 m Output variables
Xn
y1
Combinational
Circuit
yk
Zm
Y1
Yk
Y1
k Secondary variables
(Present state)
Delay
k Excitation variables
(Next state)
Delay
DrOdayA.L.ARidha
88
Asynchronous operation
When an input variable changes its value, the secondary variables do not changed
instantaneously. It takes a certain amount of time for the signal to propagate from the input
terminals through the combinational circuit to the (Y) excitation variables where new values
are generated for the next state. These values propagate through delay elements and become
the new present state for secondary variables. For a given value of input variables the system
is stable if the circuit reaches a steady-state condition with yi=Yi for i=1, 2,, k. Otherwise
the circuit is in continuous transition and is unstable.
To ensure proper operation, asynchronous sequential circuit must be attaining a stable
state before the input is changed to a new value. Because of delays in the wires and the gate
circuit, it is impossible to have two or more input variables change at exactly the same instant
of time without uncertainty as to which one changes first. Therefore, simultaneously changes
of two or more variables are usually prohibited. This restriction means that only one input
variable can change at any one time and the time between two input changes must be longer
than the time it takes the circuit to reach a stable state. This type of operation is defined as
fundamental mode.
Analysis Asynchronous circuits
A procedure for analyzing asynchronous sequential circuit is explained through the following
example:
Example: analyze the following circuit using
transition table method.
Solution:
1) Determine all feedback loops in the circuit.
2) Designate the output of each feedback loop
with a variable Yi and corresponding input
with yi, where i represent the feedback loop
number.
3) Drive the Boolean expression for excitation variables.
Y1=x.y1+xy2, Y2=x.y1+x.y2
DrOdayA.L.ARidha
89
Y1=x.y1+xy2
y1y2
x
00
0 0
1 0
01
1
0
11
1
1
Y2=x.y1+x.y2
y1y2
x
00
0 00
1 01
y1y2
x
y1y2
x
00
0 0
1 1
10
0
1
00
00
00
01
01
11
01
01
11
11
10
11
1
0
10
0
0
10
00
10
10
11
11
11
11
01
01
10
10
10
Transition Table
01
1
1
00
Stable States
Flow table
A flow table is similar to transition table except that the internal states are symbolized
with letters rather than binary no.s. The flow table also includes the output values of the
circuit for each stable state.
Examples
x
x1x2
00
01
11
10
a,0
b,0
a a,0
a,0
a,0
b,0
c,0
b,0
b a,0
a,0
b,1
b,0
c,0
d,0
a,0
d,1
DrOdayA.L.ARidha
90
Race Condition
A race is said to exist in an asynchronous sequential circuit when two or more binary
state variables change value in response to a change in an input variable. When unequal
delays are encountered, a race condition may cause the state variables to change in an
unpredictable manner. For example, if the state variables must change 00 to 11, the
difference in delays may cause the variable to change faster than the second, with the result
that the state variables change in sequence from 00 to 10 and then to 11. If the second
variable changes faster than the first, the state variables will change from 00 to 01 and then to
11. Thus the order by which the state variables change may not be known in advance. If the
final stable state that the circuit reaches does not depend on the order in which the state
variables change, the race is called a noncritical race. If it is possible to end up in two or
more different stable states depending on the order in which the state variables change, then it
is a critical race. For proper operation, critical races must be avoided.
Examples of noncritical race
X
y1y2
00
01
11
10
0
00
1
11
11
11
X
y1y2
00
01
11
10
11
0
00
1
11
01
01
11
001101
0001
00101101
0011
000111
001011
y 1y 2
x 00
0 00
1 11
0011
0001
0010
DrOdayA.L.ARidha
X
y1y2
01
01
11
11
10
10
00
01
11
10
0
00
1
11
11
11
10
0011
000111
0010
91
Cycles
When a circuit goes through a unique sequence of unstable states, it is said to have a cycle.
X
y1y2
00
01
11
10
0
00
X
y1y2
1
01
00
01
11
10
11
10
10
00011110
0
00
1
01
11
11
10
000111
Care must be taken when using a cycle that it terminates with a stable state. If a cycle does
not terminate with a stable state, the circuit will keep going from one unstable state to
another, making the entire circuit unstable. This is demonstrated in the following example.
X
y1y2
00
01
11
10
0
00
1
01
11
10
01
011110
Stability Considerations
Consider the following circuit
Y=(y.X1).X2
x1x2
Y=X1.X2+X2.y
y 00 01 11 10
0 0 1 1 0
1 0 1 0 0
If X1X2=11 => y=0101
DrOdayA.L.ARidha
92
1
0
0
0
1
0
0
1
0
1
1
1
0
0
0
0
0
1
1
0
after SR=10
after SR=01
SR
y
00
0 0
01
0
11
0
10
1
Y=S+R.y.... (2)
Expression (2) represents reduced excitation function of SR latch.
Now, to analyze a circuit with an SR latch, we must first check that Boolean condition SR=0
holds all times. We then use the reduced excitation function to analyze the circuit. However,
if it is found that both S and R can be equal to 1 at same time, then it is necessary to use the
original excitation function (expression 1).
DrOdayA.L.ARidha
R
0
1
1
1
0
Q
0
0
1
1
1
Q
1
1
0
0
1
after SR=10
after SR=01
93
SR
y
00
0 1
01
1
11
0
10
0
Y=S+R.y.... (3)
We must have always S.R=0 to avoid critical race condition.
DrOdayA.L.ARidha
94
Solution:
1) Label each latch output with Yi and its external feedback path (if any) with yi for i=1,
2 k.
2) S1=X1y2,
S2=X1.X2,
R1=X1.X2
R2=X2.y1.
00
01
11
10
00
00
00
01
00
01
01
01
11
11
11
00
11
11
10
10
00
10
11
10
Transition table
From investigation of the transition table we deduce that the circuit is stable. There is a
critical race condition when the circuit is initially in total state y1y2X1X2=1101 and X2
changes from 1 to 0. If Y1 changes to 0 before Y2, the circuit goes to total state 0100 instead
of 0000.
Implementation Example
Implement the following transition table using NOR latch.
X1X2
y
00
0 0
01
0
11
0
10
1
DrOdayA.L.ARidha
95
Solution:
y
Map for S is
Map for R is
X1X2
y
00
0 0
01
0
11
0
10
1
X1X2
y
00
0 X
01
X
11
X
10
0
The circuit is
S=X1.X2
R=X1
Debounce circuit
Input binary information in a digital system can be generated manually by means of
mechanical switches. One position of switch produces a voltage equivalent to logic 1, and
the other position equivalent logic 0.
Mechanical switches are also used to start, stop, or reset the digital system. A common
characteristic of mechanical switch is that when arm is thrown from one position to the other,
the switch contact vibrates or bounces several times before coming to a final rest.
Vout
Vcc
Vout
DrOdayA.L.ARidha
96
In a typical switch, the contact bounce may take several milliseconds to die out. This may
cause the signal to oscillate between 1 and 0 because the switch is vibrating.
To overcome this problem, the following circuit is used.
A
B
Hazards
Hazards are unwanted switching transients that may appear at the output of a circuit because
different paths exhibit different propagation delays. Hazards occur in combinational circuits,
where they may cause a temporary false output value. When this condition occurs in
asynchronous sequential circuits, it may result in a transition to a wrong stable state.
Static 1
hazard
Static 0
hazard
Dynamic
hazard
X2X3
X1
00
0
01
1
11
10
Y=X1.X2+X2.X3
To solve hazard problem we must make a connection between all separated adjacent
groups in the K-map.
Y=X1.X2+X2.X3+X1.X3
This will make the circuit a more complex but hazard-free.
DrOdayA.L.ARidha
Hazard-free
circuit
97
Essential Hazard
It is another type of hazard that may occur in asynchronous sequential circuit. An essential
hazard is caused by unequal delays along two or more paths that originate from the same
input. An excessive delay through an inverter circuit in comparison to the delay associated
with feedback path may cause such a hazard. Essential hazard cannot be corrected by adding
redundant gates such as in static hazard. The problem that they impose can be corrected by
adjacent the amount of delay in the effected path. To avoid essential hazard, each feedback
loop must be handled with individual care to ensure that the delay in the feedback path is long
enough compared to delays of other signals that originate from the input terminals.
Exercise: Draw the logic circuit of the function F in such away that circuit is a hazard free
F = (2,5,6,7,10,13,15) .
Solution:
CD
AB
00
00
01
11
10
01
11
10
1
1
1
1
F=B.D+A.C.D+B.C.D+A.B.C
Asynchronous Circuit Design
To demonstrate the procedure of designing asynchronous circuit we use the following
example
Example: Design an asynchronous logic which detects the sequence 00 10 11 on two parallel
inputs lines, X1 and X2, and gives a one output during the final combination.
Step 1: Draw state diagram from design specification then generate primitive flow-table
00
1/0
01
01
00
3/0
11
11
00
01
5/0
10
2/0
01
11
10
10
11
4/1
00
6/0
P.S.
10
11
00
1,0
1,1,-,-,1,-
N.S.
01 11
3,- -,-,- 4,3,0 5,3,- 4,1
3,- 5,0
-,- 5,-
10
2,2,0
-,6,6,6,0
1
2
3
4
5
6
Primitive flow-table
10
DrOdayA.L.ARidha
97
DrOdayA.L.ARidha
98
combinations of compatible states. The maximal compatible can be obtained from a merge
diagram. This diagram is a graph in which each state is represented by a dot placed along the
circumference of a circle. Lines are drawn between any two corresponding dots that form a
compatible pair. An isolated dot represents a state that is not compatible to any other state.
The condition that must be satisfied merging is that the set of chosen compatibles must
be cover all the states and must be closed. The set will cover all the states if it includes all the
states of the original state table. The closure condition is satisfied if there are no implied
states or if the implied states are included within the state. To explain the closed covering
condition we use two examples:
Example a:
a
d,e
d,e
c,f
d,e
c,f
c,f
d,e
c,f
f
b
c
d
Merge diagram
Example b:
e
b b,c 3
c
d,e 3
d b,c 3
a,d 3
b,c 3
c
d
Merge diagram
DrOdayA.L.ARidha
99
(a,b)
(a,d)
(b,c)
(c,d,e)
Implied states
(b,c)
(b,c)
(d,e)
(a,d)
(b,c)
The set is covered because it contains all five states. Note that the same state can be
repeated more than once. The closure condition is satisfied because the implied states are
(b,c) (d,e) and (a,d), which are included in the set. An alternative satisfactory choice of closed
covered compatibles would be (a,b) (b,c) (d,e). In general there may be more than one
possible way of merging rows.
Coming back to our original example
P.S.
00
1,0
1,1,-,-,1,-
N.S.
01 11
3,- -,-,- 4,3,0 5,3,- 4,1
3,- 5,0
-,- 5,-
10
2,2,0
-,6,6,6,0
1
2
3
4
5
6
Primitive flow-table
4,5
4,5
5 2,6 2,6
4,5
6 2,6 2,6
2
1
3
4
Merge diagram
DrOdayA.L.ARidha
100
Now, primitive flow table can be reduced to merged table which consists of three rows
only. New rows renamed.
P.S.
(1,2)
(3,5,6)
(4)
00
1,0
1,-,-
N.S.
01 11
3,- 4,3,0 5,0
3,- 4,1
P.S.
10
2,0
6,0
6,-
00
a,0
a,-,-
N.S.
01 11
b,- c,b,0 b,0
b,- c,1
a
b
c
Merged flow table
10
a,0
b,0
b,-
b 01
0 1
0 a b
1 d c
P.S.
00
a,0
a,-,-,-
N.S.
01 11
b,- d,b,0 b,0
b,- c,1
-,- c,-
d 10
c 11
10
a,0
b,0
b,-,-
a 00
b 01
c 11
d 10
Flow table (race-free)
DrOdayA.L.ARidha
P.S.
00
N.S.
01 11
10
00,0
01,0
01,-,-
101
care must be taken when a new row is added especially when we use the dont-care condition.
New row must be didnt contain a stable state.
00
N.S.
01 11
00
N.S.
01 11
10
00 00 01 10 00
01 00 01 01 01
11 X 01 11 01
10 X X 11 X
Transition table
X1X2
Y1Y2
00
N.S.
01 11
00
01 0 0 0
11 X 0 X
10 X X X
S1=X1.X2.Y2
0
X1X2
Y1Y2
00
N.S.
01 11
00 0 1 0
01 0 X X
11 X X X
10 X X 1
S2=X1.X2+Y1
DrOdayA.L.ARidha
10
0
0
0
X
10
00,0
01,0
01,-,-
X1X2
Y1Y2
a 00
b 01
c 11
d 10
00
Output
01 11
10
Z=Y1
X1X2
Y1Y2
00
01
11
10
00
N.S.
01 11
10
R1=X1+X2
10
0
X
X
X
X1X2
Y1Y2
00
01
11
10
00
N.S.
01 11
10
R2=X1.X2
102
Special characteristics
Fan-out: specifies the number of standard loads that the output of a gate can
drive without impairing its normal operation. A standard load is usually
defined as the amount of current needed by an input of another gate on the
same IC family.
Noise margin: is the maximum noise voltage added to the input signal of a
digital circuit that does not cause undesirable change in the circuit output.
Propagation delay: The signals through a gate take a certain amount of time
to propagate from the inputs to the output. The average transition delay time
DrOdayA.L.ARidha
103
for a signal to propagate from the input to the output when the binary signals
change in value.
Power dissipation: is the supplied power required to operate the gate.
Digital IC families
Digital ICs are classified not only by their logic operation, but also
by the specific logic circuit family to which they belong. Each family has its
own basic electronic circuit upon which more complex digital circuits and
functions are developed. The basic circuit in each family is either NAND or
a NOR gate. The most popular families are:
- TTL Transistor-transistor logic, has an extensive list of digital
functions, propagation delay 3-10 ns, high level 2.4-5 volt, low level
0-.4 volt, fan-out 10-20 gates, power dissipation 2-22 mW, series
74xx, 54xx;
- ECL Emitter-coupled logic, used in systems required high-speed
operations, propagation delay < 1-2 ns, high level -0.95- -0.72 volt,
low level -1.9 - -1.6 volt, fan-out 25 gates, power dissipation 25 mW,
series 10xxx;
- CMOS Complementary Metal-oxide semiconductor, used in circuit
required low power consumption, propagation delay 25 ns, high level
VDD volt, low level 0 0.5 volt, fan-out 50 gates, power dissipation
0.1 mW, series 4xxx.
- Other families such as Integrated-injection logic (I2L), Diodetransistor logic (DTL), Resistor-transistor logic (RTL).
DrOdayA.L.ARidha
104
DrOdayA.L.ARidha
105
look similar as conventional programming languages, there are some important differences. A
hardware description language is inherently parallel, i.e. commands, which correspond to logic
gates, are executed (computed) in parallel, as soon as a new input arrives. A HDL program
mimics the behavior of a physical, usually digital system. It also allows incorporation of timing
specifications (gate delays) as well as to describe a system as an interconnection of different
components.
1. VHDL
VHDL stands for VHSIC (Very High Speed Integrated Circuits) Hardware Description
Language. In the mid-1980s the U.S. Department of Defense and the IEEE sponsored the
development of this hardware description language with the goal to develop very high-speed
integrated circuit. It has become now one of industrys standard languages used to describe
digital systems. The other widely used hardware description language is Verilog. Both are
powerful languages that allow you to describe and simulate complex digital systems. A third
HDL language is ABEL (Advanced Boolean Equation Language) which was specifically
designed for Programmable Logic Devices (PLD). ABEL is less powerful than the other two
languages and is less popular in industry.
106
input. On the other hand, sequential statements are executed in the sequence that they are
specified. VHDL allows both concurrent and sequential signal assignments that will determine
the manner in which they are executed. Examples of both representations will be given later.
3. Basic Structure of a VHDL file
A digital system in VHDL consists of a design entity (circuit) that can contain other entities
(sub circuits) that are then considered components of the top-level entity. Each entity is
modeled by an entity declaration and an architecture body. One can consider the entity
declaration as the interface to the outside world that defines the input and output signals, while
the architecture body contains the description of the entity and is composed of interconnected
entities, processes and components, all operating concurrently, as schematically shown in
Figure 3 below. In a typical design there will be many such entities connected together to
perform the desired function.
a. Entity Declaration
The entity declaration defines the NAME of the entity and lists the input and output ports.
The general form is as follows,
entity NAME_OF_ENTITY is [ generic generic_declarations);]
port (signal_names: mode type;
signal_names: mode type;
:
signal_names: mode type);
end [NAME_OF_ENTITY] ;
108
An entity always starts with the keyword entity, followed by its name and the keyword
is. Next are the port declarations using the keyword port. An entity declaration always
ends with the keyword end, optionally [] followed by the name of the entity.
For the example of Figure 2 above, the entity declaration looks as follows.
-- comments: example of the buzzer circuit of fig. 2
entity BUZZER is
port (DOOR, IGNITION, SBELT: in std_logic;
WARNING: out std_logic);
end BUZZER;
The entity is called BUZZER and has three input ports, DOOR, IGNITION and SBELT and
one output port, WARNING. Notice the use and placement of semicolons! The name BUZZER
109
is an identifier. Inputs are denoted by the keyword in, and outputs by the keyword out. Since
VHDL is a strongly typed language, each port has a defined type. In this case, we specified the
std_logic type. This is the preferred type of digital signals. In contrast to the bit type that
can only have the values 1 and 0, the std_logic and std_ulogic types can have nine values.
This is important to describe a digital system accurately including the binary values 0 and 1, as
well as the
1. unknown value X;
2. the uninitialized value U;
3. - for dont care;
4. Z for high impedance;
5. L for weak 0;
6. H for weak 1;
7. W for weak unknown;
8. 0 strong 0;
9. 1 strong l .
The std_logic type is defined in the std_logic_1164 package of the IEEE library. The type
defines the set of values an object can have. This has the advantage that it helps with the
creation of models and helps reduce errors. For instance, if one tries to assign an illegal value
to an object, the compiler will flag the error.
Example2:An example of the entity declaration of a D flip-flop with set and reset inputs is
entity dff_sr is
port (D,CLK,S,R: in std_logic;
Q,Qnot: out std_logic);
end dff_sr;
b.
Architecture body
The architecture body specifies how the circuit operates and how it is implemented. As
discussed earlier, an entity or circuit can be specified in a variety of ways, such as behavioral,
structural (interconnected components), or a combination of the above.
110
Behavioral model
The architecture body for the example of Figure 2, described at the behavioral level, is given
below,
architecture behavioral of BUZZER is
begin
WARNING <= (not DOOR and IGNITION) or (not SBELT and
IGNITION);
end behavioral;
The header line of the architecture body defines the architecture name, e.g. behavioral, and
associates it with the entity, BUZZER. The architecture name can be any legal identifier. The
main body of the architecture starts with the keyword begin and gives the Boolean expression
of the function. We will see later that a behavioral model can be described in several other
ways. The <= symbol represents an assignment operator and assigns the value of the
expression on the right to the signal on the left. The architecture body ends with an end
keyword followed by the architecture name.
Example3: The behavioral description of a two-input AND gate.
entity AND2 is
port (in1, in2: in std_logic;
out1: out std_logic);
end AND2;
architecture behavioral_2 of AND2 is
begin
out1 <= in1 and in2;
end behavioral_2;
111
entity XNOR2 is
port (A, B: in std_logic;
Z: out std_logic);
end XNOR2;
architecture behavioral_xnor of XNOR2 is
-- signal declaration (of internal signals X, Y)
signal X, Y: std_logic;
begin
X <= A and B;
Y <= (not A) and (not B);
Z <= X or Y;
End behavioral_xnor;
The statements in the body of the architecture make use of logic operators. Logic operators
that are allowed are: and, or, nand, nor, xor, xnor and not. In addition, other
types of operators including relational, shift, arithmetic are allowed as well.
Concurrency
It is worth pointing out that the signal assignments in the above examples are concurrent
statements. This implies that the statements are executed when one or more of the signals on
the right hand side change their value (i.e. an event occurs on one of the signals). For instance,
when the input A changes, the internal signals X and Y change values that in turn causes the
last statement to update the output Z. There may be a propagation delay associated with this
change. Digital systems are basically data-driven and an event which occurs on one signal will
lead to an event on another signal, etc. The execution of the statements is determined by the
flow of signal values. As a result, the order in which these statements are given does not matter
(i.e., moving the statement for the output Z ahead of that for X and Y does not change the
outcome). This is in contrast to conventional, software programs that execute the statements in
a sequential or procedural manner.
112
Structural description
The circuit of Figure 2 can also be described using a structural model that specifies what
gates are used and how they are interconnected. The following example illustrates it.
Following the header is the declarative part that gives the components (sub circuits, gates,)
that are going to be used in the description of the circuits. In our example, we use a two- input
AND gate, two-input OR gate and an inverter. These gates have to be defined first, i.e. they
will need an entity declaration and architecture body (as shown in the previous example). These
can be stored in one of the packages (like include in C language) one refers to in the header of
the file. The declarations for the components give the inputs (e.g. in1, in2) and the output (e.g.
out1). Next, one has to define internal nets or wires (signal names). In our example these
signals are called DOOR_NOT, SBELT_NOT, B1, B2 (see the figure above). Notice that one
always has to declare the type of the signal.
The statements after the begin keyword gives the instantiations of the components and
describes how these are interconnected. A component instantiation statement creates a new
level of hierarchy. Each line starts with an instance name (e.g. U0) followed by a colon and a
component name and the keyword port map. This keyword defines how the components are
113
connected. In the example above, this is done through positional association: DOOR
corresponds to the input, in1 of the NOT1 gate and DOOR_NOT to the output. Similarly, for
the AND2 gate where the first two signals (IGNITION and DOOR_NOT) correspond to the
inputs in1 and in2, respectively, and the signal B1 to the output out1. An alternative way is to
use explicit association between the ports, as shown below.
label: component-name port map (port1=>signal1, port2=> signal2, port3=>signaln);
U0:
U1:
U2:
U3:
U4:
NOT1
NOT1
AND2
AND2
OR2
port
port
port
port
port
map
map
map
map
map
(in1
(in1
(in1
(in1
(in1
=>
=>
=>
=>
=>
Notice that the order in which these statements are written has no bearing on the execution
since these statements are concurrent and therefore executed in parallel. Indeed, the schematic
that is described by these statements is the same independent of the order of the statements.
Structural modeling of design lends itself to hierarchical design, in which one can define
components of units that are used over and over again. Once these components are defined they
can be used as blocks, cells or macros in a higher level entity. This can significantly reduce the
complexity of large designs. Hierarchical design approaches are always preferred over flat
designs.
To illustrate the use of a hierarchical design approach for a 4-bit adder shown in Figure 4 below.
Each full adder can be described by the Boolean expressions for the sum and carry out signals,
sum = (A B) C
carry = AB + C(A B)
114
Notice that the same input names a and b for the ports of the full adder and the 4-bit adder were
used. This does not pose a problem in VHDL since they refer to different levels. However, for
readability, it may be easier to use different names. We needed to define the internal signals
c(4:0) to indicate the nets that connect the output carry to the input carry of the next full adder.
For the first input we used the input signal Cin. For the last carry we defined c(4) as an internal
signal since the last carry is needed as the input to the xor gate. We could not use the output
signal Cout since VHDL does not allow the use of outputs as internal signals! For this reason
we had to define the internal carry c(4) and assign c(4) to the output carry signal Cout.
115
I0
I1
Inputs
I3
0
1
.
.
.
3
161
MUX
BA
Select
hint: make use of the following circuit
116
Y1
Solution:
117
118
Process in VHDL
A process statement is the main construct in behavioral modeling that allows you to use
sequential statements to describe the behavior of a system over time. The syntax for a process
statement is
[process_label:] process [ (sensitivity_list) ] [is]
[ process_declarations]
begin
list of sequential statements such as:
signal assignments
variable assignments
case statement
exit statement
if statement
loop statement
next statement
null statement
procedure call
wait statement
end process [process_label];
------------------------------------------------------------------------------------------------A process is declared within an architecture and is a concurrent statement. However, the
statements inside a process are executed sequentially. Like other concurrent statements, a
process reads and writes signals and values of the interface (input and output) ports to
communicate with the rest of the architecture. One can thus make assignments to signals that
are defined externally (e.g. interface ports) to the process, such as the Q output of the flip- flop
119
in the above example. The expression CLKevent and CLK = 1 checks for a positive
clock edge (clock event AND clock high).
The sensitivity list is a set of signals to which the process is sensitive. Any change in the value
of the signals in the sensitivity list will cause immediate execution of the process. If the
sensitivity list is not specified, one has to include a wait statement to make sure that the process
will halt. Notice that one cannot include both a sensitivity list and a wait statement. Variables
and constants that are used inside a process have to be defined in the process_declarations part
before the keyword begin. The keyword begin signals the start of the computational part of the
process. The statements are sequentially executed, similarly as a conventional software
program. It should be noted that variable assignments inside a process are executed
immediately and denoted by the := operator. This is in contrast to signal assignments denoted
by <= and which changes occur after a delay. As a result, changes made to variables will be
available immediately to all subsequent statements within the same process.
The previous example of the D flip-flop illustrates how to describe a sequential circuit with the
process statement. Although the process is mainly used to describe sequential circuits, one can
also describe combinational circuits with the process construct. The following example
illustrates this for a Full Adder, composed of two Half Adders. This example also illustra tes
how one process can generate signals that will trigger other processes when events on the
signals in its sensitivity list occur. We can write the Boolean expression of a Half Adder and
Full Adder as follows:
S_ha = (AB)
and C_ha = AB
Figure 5: Full Adder composed of two Half Adders, modeled with two processes P1 and P2.
120
----------------------------------------------------library ieee;
use ieee.std_logic_1164.all;
entity FULL_ADDER is
port (A, B, Cin : in std_logic;
Sum, Cout : out std_logic);
end FULL_ADDER;
architecture BEHAV_FA of FULL_ADDER is
signal int1, int2, int3: std_logic;
begin
-- Process P1 that defines the first half adder
P1: process (A, B)
begin
int1<= A xor B;
int2<= A and B;
end process;
-- Process P2 that defines the second half adder and the OR -gate
P2: process (int1, int2, Cin)
begin
Sum <= int1 xor Cin;
int3 <= int1 and Cin;
Cout <= int2 or int3;
end process;
end BEHAV_FA;
--------------------------------------------------------------------------------------------One could simplify the behavioral model significantly by using a single process.
H/W: write VHDL code to model full adder using single process
121
a. Signal assignment
Signal assignments are event triggered and executed as soon as an event on one of the
signals occurs. There are three types of signal assignment
1) Simple Concurrent signal assignments.
The syntax is as follows:
Target_signal <= expression;
Examples
Sum <= (A xor B) xor Cin;
Carry <= (A and B);
Z <= (not X) or Y after 2 ns;
The target signal will receive the value of the first expression whose Boolean condition is
TRUE. If no condition is found to be TRUE, the target signal will receive the value of the
final expression. If more than one condition is true, the value of the first condition that is
TRUE will be assigned.
Example: 4-to-1 multiplexer using conditional signal assignments
entity MUX_4_1_Conc is
port (S1, S0, A, B, C, D: in std_logic;
Z: out std_logic);
end MUX_4_1_Conc;
architecture concurr_MUX41 of MUX_4_1_Conc is
begin
Z <= A when S1=0 and S0=0 else
B when S1=0 and S0=1 else
C when S1=1 and S0=0 else
D;
end concurr_MUX41;
The conditional signal assignment will be re-evaluated as soon as any of the signals in the
conditions or expression change. The when-else construct is useful to express logic function in
the form of a truth table.
122
The target is a signal that will receive the value of an expression whose choice includes the
value of the choice_expression. The expression selected is the first with a matching choice.
The choice can be a static expression (e.g. 5) or a range expression (e.g. 4 to 9). The
following rules must be followed for the choices:
123
The equivalent process statement would make use of the case construct. Similarly to the whenelse construct, the selected signal assignment is useful to express a function as a truth table, as
illustrated above.
The choices can express a single value, a range or combined choices as shown below.
target <= value1 when 000,
value2 when 001 | 011
value3 when others;
| 101 ,
In the above example, all eight choices are covered and only once. The others choice must the
last one used.
b. wait statements
The wait statement will halt a process until an event occurs. There are several forms
of the wait statement,
a)
b)
c)
Examples
wait
wait
wait
wait
until
until
until
until
CLK=1;
CLK=0;
CLKevent and CLK=1;
not CLKstable and CLK=1;
For the first example the process will wait until a positive-going clock edge occurs, while for
the second example, the process will wait until a negative-going clock edge arrives. The last
two examples are equivalent to the first one (positive-edge or 0-1 transitions). The hardware
implementation for these three statements will be identical.
It should be noted that a process that contains a wait statement can not have a sensitivity list.
If a process uses one or more wait statements, the Foundation Express synthesizer will use
sequential logic. The results of the computations are stored in flip-flops.
124
c. If Statements
The if statement executes a sequence of statements whose sequence depends on one or more
conditions. The syntax is as follows:
if condition then
sequential statements
[elsif condition then
sequential statements ]
[else
sequential statements ]
end if;
125
d. Case statements
The case statement executes one of several sequences of statements, based on the value of a
single expression. The syntax is as follows,
case expression is
when choices =>
sequential statements
when choices =>
sequential statements
-- branches are allowed
[ when others => sequential statements ]
end case;
no two choices can overlap (i.e. each choice can be covered only once)
if the when others " choice is not present, all possible values of the expression must
be covered by the set of choices.
Example
An example of a case statement using an enumerated type follows. It gives an output D=1 when
the signal GRADES has a value between 51 and 60, C=1 for grades between 61 and 75, B=1
for grades between 76 and 85, A=1 for grades between 86 and 100, the when others covers all
the other grades and result in an F=1.
entity GRD_201 is
port(VALUE: in integer range 0 to 100;
A, B, C, D: out bit);
end GRD_201;
architecture behav_grd of GRD_201 is
begin
process (VALUE)
A <= 0;
Dr. Oday A.L.A Ridha
126
B <= 0;
C <= 0;
D <= 0;
F <= 0;
begin
case VALUE is
when 51 to 60 =>
D <= 1;
when 61 to 70 | 71 to 75 =>
C <= 1;
when 76 to 85 =>
B <= 1;
when 86 to 100 =>
A <= 1;
when others =>
F <= 1;
end case;
end process;
end behav_grd;
We used the vertical bar ( | ) which is equivalent to the or operator, to illustrate how to
express a range of values. This is a useful operator to indicate ranges that are not adjacent
(e.g. 0 to 4 | 6 to 10).
The when others covers the cases when SEL=0X, 0Z, XZ, UX, etc. It should be
noted that these combinational circuits can be expressed in other ways, using concurrent
statements such as the With Select construct. Since the case statement is a sequential
statement, one can have nested case statements.
127
e. Loop statements
A loop statement is used to repeatedly execute a sequence of sequential statements. The
syntax for a loop is as follows:
[ loop_label :]iteration_scheme loop
sequential statements
[next [label] [when condition];
[exit [label] [when condition];
end loop [loop_label];
Labels are optional but are useful when writing nested loops. The next and exit statement are
sequential statements that can only be used inside a loop.
The next statement terminates the rest of the current loop iteration and execution will
proceed to the next loop iteration.
The exit statement skips the rest of the statements, terminating the loop entirely, and
continues with the next statement after the exited loop.
1)
This loop has no iteration scheme. It will be executed continuously until it encounters an exit
or next statement.
[ loop_label :] loop
sequential statements
[next [label] [when condition];
[exit [label] [when condition];
end loop [ loop_label];
The basic loop (as well as the while-loop) must have at least one wait statement. As an
example, lets consider a 5-bit counter that counts from 0 to 31. When it reaches 31, it will start
over from 0. A wait statement has been included so that the loop will execute every time the
clock changes from 0 to 1.
128
We defined a variable intern_value inside the process because output ports cannot be read
inside the process.
2)While-Loop statement
The while loop evaluates a Boolean iteration condition. When the condition is TRUE, the
loop repeats, otherwise the loop is skipped and the execution will halt. The syntax for the
whileloop is as follows,
[ loop_label :] while condition loop
sequential statements
[next [label] [when condition];
[exit [label] [when condition];
end loop[ loop_label ];
The condition of the loop is tested before each iteration, including the first iteration. If it is
false, the loop is terminated.
3) For-Loop statement
The for-loop uses an integer iteration scheme that determines the number of iterations. The
syntax is as follows,
[ loop_label :] for identifier in range loop
sequential statements
[next [label] [when condition];
[exit [label] [when condition];
end loop[ loop_label ];
129
The identifier (index) is automatically declared by the loop itself, so one does not need
to declare it separately. The value of the identifier can only be read inside the loop and
is not available outside its loop. One cannot assign or change the value of the index.
This is in contrast to the while-loop whose condition can involve variables that are
modified inside the loop.
The range must be a computable integer range in one of the following forms, in which
integer_expression must evaluate to an integer:
o integer_expression to integer_expression
o integer_expression downto integer_expression
condition];
The when keyword is optional and will execute the next statement when its condition evaluates
to the Boolean value TRUE.
The exit statement skips the rest of the statements, terminating the loop entirely, and continues
with the next statement after the exited loop. The syntax is as follows:
exit [label] [when
condition];
The when keyword is optional and will execute the next statement when its condition evaluates
to the Boolean value TRUE.
Notice that the difference between the next and exit statement, is that the exit statement
terminates the loop.
130
131
if X='1' then
Sreg0 <= S3;
elsif X='0' then
Sreg0 <= S0;
end if;
when S3 =>
if X='0' then
Sreg0 <= S2;
elsif X='1' then
Sreg0 <= S1;
end if;
when others =>
null;
end case;
end if;
end if;
end process;
-- signal assignment statements for combinatorial outputs
Z_assignment:
Z <= '0' when (Sreg0 = S0 and X='0') else
'0' when (Sreg0 = S0 and X='1') else
'0' when (Sreg0 = S1 and X='1') else
'0' when (Sreg0 = S1 and X='0') else
'0' when (Sreg0 = S2 and X='1') else
'0' when (Sreg0 = S2 and X='0') else
'0' when (Sreg0 = S3 and X='0') else
'1' when (Sreg0 = S3 and X='1') else
'1';
end myvhdl_arch;
------------------------------------------------------------------------------------------------------
H/W 1: Write necessary VHDL code for describing the synchronous sequential
circuit whose its state diagram is shown below
132
H/W 2: For the circuit of a multiplier, whose its data processor is shown below,
write necessary VHDL code for describing only the control circuit of it. Use
algorithmic state machine diagram shown below for your answer.
Z
Loa d B
Cout
Register B
Z=1 if P=0
Count
Parallel Adder
Cl ea r E
Register A
Loa d Q
Loa d A
Shi ft ri ght
T0
00
S
1
T1
0
01
A0
10
T2
PP-1
Q1
E0
AA+B, ECout
11
T3
Shift right AQ
0
Z
133
P - down counter,
Q1
Register Q
Cl ea r A
Q - Multiplier
Counter P
Loa d P
Loa d E
B - Multiplicand