Module-4 VHDL & Flip Flops
Module-4 VHDL & Flip Flops
III Semester
2018 Scheme
Prepared By:
Dr. Jyothi A P
Assistant Professor,
Department of Computer Science and Engineering,
RVITM, Bengaluru – 560076
Email: [email protected]
[email protected]
RV Institute of Technology and Management®
Module 4
Introduction to VHDL; Latches and Flip-Flops
Syllabus:
VHDL description of combinational circuits, VHDL Models for multiplexers, VHDL Modules. Set Reset
Latch, Gated Latches, Edge-Triggered D Flip Flop, SR Flip Flop, J K Flip Flop, T Flip Flop, Flip Flop with
additional inputs, Asynchronous Sequential Circuits
INTROIDUCTION TO VHDL
The acronym VHDL stands for VHSIC-HDL (Very High Speed Integrated Circuit-Hardware Description
Language). VHDL is a hardware description language that is used to describe the behavior and structure of
digital systems. VHDL is a general-purpose hardware description language which can be used to describe
and simulate the operation of a wide variety of digital systems, ranging in complexity from a few gates to an
interconnection of many complex integrated circuits.
VHDL was originally developed to allow a uniform method for specifying digital systems. The VHDL
language became an IEEE standard in 1987, and it is widely used in industry. IEEE published a revised
VHDL standard in 1993. VHDL can describe a digital system at several different levels—behavioral, data
flow, and structural. For example,
o A binary adder could be described at the behavioral level in terms of its function of adding two binary
numbers, without giving any implementation details.
o The same adder could be described at the data flow level by giving the logic equations for the adder.
o Finally, the adder could be described at the structural level by specifying the interconnections of the gates
which make up the adder.
VHDL DESCRIPTION OF COMBINATIONAL CIRCUITS:
In VHDL, a signal assignment statement has the form: signal name <= expression;
The expression is evaluated when the statement is executed, and the signal on the left side is scheduled to change
after delay. The square brackets indicate that after delay is optional. If after delay is omitted, then the signal is
scheduled to be updated after a delta delay, Δ (infinitesimal delay). A VHDL signal is used to describe
a signal in a physical system. The VHDL language also includes variables similar to variables in
programming languages.
In general, VHDL is not case sensitive, that is, capital and lower case letters are treated the same by the
compiler and the simulator. Signal names and other VHDL identifiers may contain letters, numbers, and the
underscore character ( _ ). An identifier must start with a letter, and it cannot end with an underscore. Thus,
C123 and ab_23 are legal identifiers, but 1ABC and ABC_ are not. Every VHDL statement must be
terminated with a semicolon. Spaces, tabs, and carriage returns are treated in the same way. This means that
a VHDL statement can be continued over several lines, or several statements can be placed on one line. In a
line of VHDL code, anything following a double dash (--) is treated as a comment. Words such as and, or,
and after are reserved words (or keywords) which have a special meaning to the VHDL compiler.
The gate circuit of the following Fig 4.1 has five signals: A, B, C, D, and E. The symbol “ <= “ is the signal
assignment operator which indicates that the value computed on the right-hand side is assigned to the signal
on the left side.
Fig 4.2 inverter with the output connected back to the input
The following Fig 4.3 shows three gates that have the signal A as a common input and the corresponding
VHDL code. The three concurrent statements execute simultaneously whenever a changes, just as the three
gates start processing the signal change at the same time. However, if the gates have different delays, the
gate outputs can change at different times. If the gates have delays of 2 ns, 1 ns, and 3 ns, respectively, and
A changes at time 5 ns, then the gate outputs D, E, and F can change at times 7 ns, 6 ns, and 8 ns,
respectively. However, if no delays were specified, then D, E, and F would all be updated at time 5 + Δ.
Fig 4.3 three gates that have the signal A as a common input and the corresponding VHDL code
In these examples, every signal is of type bit, which means it can have a value of “0‟ or “1‟. (Bit values in
VHDL are enclosed in single quotes to distinguish them from integer values). In digital design, we often
need to perform the same operation on a group of signals. A one-dimensional array of bit signals is referred
to as a bit-vector. If a 4-bit vector named B has an index range 0 through 3, then the four elements of the bit-
vector are designated B(0), B(1), B(2), and B(3). The statement B <= “0110”, assigns “0‟ to B(0), “1‟ to
B(1), “1‟ to B(2), and “0‟ to B(3).
The following Figure shows an array of four AND gates. The inputs are represented by bit-vectors A and B,
and the outputs by bit-vector C. Although we can write four VHDL statements to represent the four gates, it
is much more efficient to write a single VHDL statement that performs the and operation on the bit-vectors
A and B. When applied to bit-vectors, the and operator performs the and operation on corresponding pairs
of elements.
Fig 4.4
Inertial delay model: Signal assignment statements containing “after delay” create what is called an inertial
delay model. Consider a device with an inertial delay of D time units. If an input change to the device will
cause its output to change, then the output changes D time units later. However, this is not what happens if
the device receives two input changes within a period of D time units and both input changes should cause
the output to change. In this case the device output does not change in response to either input change.
Example: consider the signal assignment C <= A and B after 10 ns; Assume A and B are initially 1, and A
changes to 0 at 15 ns, to 1 at 30 ns, and to 0 at 35 ns. Then C changes to 1 at 10 ns and to 0 at 25 ns, but C
does not change in response to the A changes at 30 ns and 35 ns; because these two changes occurred less
than 10 ns apart. A device with an inertial delay of D time units filters out output changes that would occur
in less than or equal to D time units.
Ideal (Transport) delay: VHDL can also model devices with an ideal (transport) delay. Output changes
caused by input changes to a device exhibiting an ideal (transport) delay of D time units are delayed by D
time units, and the output changes occur even if they occur within D time units. The VHDL signal
assignment statement that models ideal (transport) delay is signal name <= transport expression after delay
Example: consider the signal assignment C <= transport A and B after 10 ns; Assume A and B are initially
1 and A changes to 0 at 15 ns, to 1 at 30 ns, and to 0 at 35 ns. Then C changes to 1 at 10 ns, to 0 at 25 ns, to
1 at 40 ns, and to 0 at 45 ns. Note that the last two changes are separated by just 5 ns.
VHDL MODELS FOR MULTIPLEXERS:
The following Fig 4.5 shows a 2-to-1 multiplexer (MUX) with two data inputs and one control input.
First, expression_s is evaluated. If it equals choice1, signal_s is set equal to expression1; if it equals
choice2, signal_s is set equal to expression2; etc. If all possible choices for the value of expression_s are
given, the last line should be omitted; otherwise, the last line is required. When it is present, if expression_s
is not equal to any of the enumerated choices, signal_s is set equal to expression_n. The signal_s is updated
after the specified delay-time, or after if the “after delay-time” is omitted.
VHDL MODULES:
To write a complete VHDL module, we must declare all of the input and output signals using an entity
declaration, and then specify the internal operation of the module using an architecture declaration. As an
example, consider the following Fig 4.8.
very similar to the entity declaration for the full adder, and the input and output port signals correspond to
those declared for the full adder. Following the component statement, declare a 3-bit internal carry signal C.
In the body of the architecture, create several instances of the FullAdder component. Each copy of
FullAdder has a name (such as FA0) and a port map. The signal names following the port map correspond
one-to-one with the signals in the component port. Thus, A(0), B(0), and Ci correspond to the inputs X, Y,
and Cin, respectively. C(1) and S(0) correspond to the Cout and Sum outputs.
Note that the order of the signals in the port map must be the same as the order of the signals in the port of
the component declaration.
A simple latch can be constructed by introducing feedback into a NOR-gate circuit, as given in the
following Figure (a). As indicated, if the inputs are S = R = 0, the circuit can assume a stable state with Q =
0 and P = 1.
second gate are 0; therefore Q will change to 1, leading to the stable state.
These equations are mapped in the next-state and output tables as given in the following Table. The stable
states of the latch are circled. Note that for all stable states, P = Q except when S = R = 1. Making S = R =
1, a don‟t-care combination allows simplifying the next-state equation.
Fig 4.16
An equation that expresses the next state of a latch in terms of its present state and inputs will be referred to
as a next-state equation, or characteristic equation.
An alternative form of the S-R latch uses NAND gates, as shown in the following Fig 4.17.
change state. The timing diagram shows what happens when the switch is flipped from a to b. As the switch
leaves a, bounces occur at the R input; when the switch reaches b, bounces occur at the S input. After the
switch reaches b, the first time S becomes 1, after a short delay the latch switches to the Q = 1 state and
remains there. Thus Q is free of all bounces even though the switch contacts bounce.
GATED D LATCH:
A gated D latch (given in Fig 4.18 below) has two inputs—a data input (D) and a gate input (G). The D
latch can be constructed from an S-R latch and gates. When G = 0, S = R = 0, so Q does not change. When
G = 1 and D = 1, S = 1 and R = 0, so Q is set to 1. When G = 1 and D = 0, S = 0 and R = 1, so Q is reset to
0. In other words, when G = 1, the Q output follows the D input, and when G = 0, the Q output holds the last
value of D (no state change). This type of latch is also referred to as a transparent latch because when G = 1,
the Q output is the same as the D input. From the truth table, the characteristic equation for the latch is + = ′
+ GD
EDGE-TRIGGERED D FLIP-FLOP:
A D flip-flop has two inputs, D (data) and Ck (clock). The small arrowhead on the flip-flop symbol
identifies the clock input. Unlike the D latch, the flip-flop output changes only in response to the clock, not
to a change in D.
o If the output can change in response to a 0 to 1 transition on the clock input, we say that the flipflop is
triggered on the rising edge (or positive edge) of the clock.
o If the output can change in response to a 1 to 0 transition on the clock input, we say that the flipflop is
triggered on the falling edge (or negative edge) of the clock.
o An inversion bubble on the clock input indicates a falling-edge trigger (Fig 4.19 (b)), and no bubble
indicates a rising-edge trigger (Figure (a)).
The term active edge refers to the clock edge (rising or falling) that triggers the flip-flop state change.
Fig 4.19 D FF
Since, the Q output of the flip-flop is the same as the D input, except that the output changes are delayed
until after the active edge of the clock pulse, as illustrated in the following Fig 4.20.
Fig 4.23 propagation delay (tp) from the time the clock
S-R FLIP-FLOP:
An S-R flip-flop (following Fig 4.24) is similar to an S-R latch in that S = 1 sets the Q output to 1, and R =
1 resets the Q output to 0. The essential difference is that the flip-flop has a clock input, and the Q output
can change only after an active clock edge.
the clock changes from 0 to 1, the value of P is held in the master latch and this value is transferred to the
slave latch. The master latch holds the value of P while CLK = 1, and, hence, Q does not change. When the
clock changes from 1 to 0, the Q value is latched in the slave, and the master can process new inputs. Figure
(b) shows the timing diagram. Initially, S = 1 and Q changes to 1 at t1. Then R = 1 and Q changes to 0 at t3.
simultaneously to J and K, in which case the flip-flop changes state after the active clock edge. When J = K
= 1, the active edge will cause Q to change from 0 to 1, or from 1 to 0. The next-state table and
characteristic equation for the J-K flip-flop are given in Figure (b).
Fig 4.26
Figure 4.26 (c) shows the timing for a J-K flip-flop. This flip-flop changes state a short time (tp) after the
rising edge of the clock pulse, provided that J and K have appropriate values. If J = 1 and K = 0 when Clock
= 0, Q will be set to 1 following the rising edge. If K = 1 and J = 0 when Clock = 0, Q will be set to 0 after
the rising edge. Similarly, if J = K = 1, Q will change state after the rising edge. Referring to Figure 11-
20(c), because Q = 0, J = l, and K = 0 before the first rising clock edge, Q changes to 1 at t1. Because Q = 1,
J = 0, and K = 1 before the second rising clock edge, Q changes to 0 at t2. Because Q = 0, J = 1, and K = 1
before the third rising clock edge, Q changes to 1 at t3. One way to realize the J-K flip-flop is with two S-R
latches connected in a master-slave arrangement, as shown in the following Figure.
synchronization. Rather than gating the clock, a better way is to use a flip-flop with a clock enable (CE).
Such flip-flops are commonly used in CPLDs and FPGAs. Figure (b) shows a D flip-flop with a clock
enable, which we will call a D-CE flip-flop. When CE = 0, the clock is disabled and no state change occurs,
so Q+ = Q. When CE = 1, the flip-flop acts like a normal D flip-flop, so Q+ = D. Therefore, the
characteristic equation is Q+ = Q•CE’ + D•CE. The D-CE flip-flop is easily implemented using a D flip-
flop and a multiplexer (Figure (c)). For this circuit, the MUX output is Q+ = D + Q•CE + Din•CE. Since,
there is no gate in the clock line; this cannot cause a synchronization problem.
Characteristic Equations of Flip-Flop:
The characteristics equations of flip-flops are useful in analyzing circuits made of them. Here, next output,
Qn+1, is expressed as a function of present output Qn and the input to the flip-flops. Karnaugh map can be
used to get the optimized expression.
S R Flip Flop
to 1; the next-state table indicates the next state should be PQ will transition to state PQ = 11. The 1 to 0
change propagating through the x inverter, Gate 1 and Gate 4 will change P to 0. When P changes to 0, the
lower inverter output changes to 1 and, if line d at Gate 3 is still 1, Gate 3 and Gate 5 change to 1. With Q =
1, Gate 2 changes to 1 which causes Gate 4 to change back to 1. Note that this incorrect operation occurs
because the x change does not reach a portion of the logic for Q until after the change in P has propagated
back to the logic for Q. The potential for this incorrect operation can be detected by examining the next-
state table and determining whether the next state after a single change in an input is different from the next
state after three changes in that input. In the preceding example, starting in total stable state xPQ = 010 and
changing x to 1 produces next state PQ= 00. Changing x back to 0 produces next state PQ= 01. Finally,
changing xa third time to 1, produces next state PQ 11. The table is said to contain an essential hazard at
total state xPQ = 010.
Essential hazards are properties of the next-state table; they cannot be eliminated by modifying the circuit's
logic. To prevent incorrect operation due to essential hazards, it is necessary to control the delays in the
circuit. In general, it may be necessary to insert delays in the feedback loops of the circuit. For the above
example, this would require inserting delays at the outputs of Gates 4 and 5. Inserting delays in the feedback
loops, assures that input changes propagate through the next state logic before changes in the state variables
feedback to the inputs of the logic.
Both of the problems noted above are due to more than one signal in the circuit changing with the circuit’s
response depending on which signal(s) propagate through the circuit first. The static hazard causes a glitch
if an input change propagates over some path in the circuit more quickly than it propagates over another
path. For the essential hazard problem he two signals changing are an external input and a state variable. In
both cases there is a "race" between two signal changes with the circuit operation depending on which signal
wins the race. A similar problem can exist if two (or more) inputs to an asynchronous circuit can change at
the same time. Consider the next state table in Figure and consider starting in total state xyPQ= 1011 and
changing both x and y to 0 at the same time. The table indicates the next state should be PQ 11. If the y
change propagates through the cireuit first, then the circuit enters total state xyPQ= 1011. Then after the x
change propagates through the circuit, the total state becomes xyPQ = 0011. However, if the x change
propagates through the circuit first, the total state becomes xyPQ= 0100. Then, after the y change
propagates through the circuit, the total becomes xyPQ= 0000. The final state depends upon which input
change propagates fastest and, hence, the final state may not be PQ = 11, as indicated by the next-state table.