ET398 LAB 6 "Flip-Flops in VHDL" (PDFDrive)
ET398 LAB 6 "Flip-Flops in VHDL" (PDFDrive)
ET398 LAB 6 "Flip-Flops in VHDL" (PDFDrive)
“Flip-Flops in VHDL”
Flip-Flops
March 3, 2013
Tiffany Turner “ “
OBJECTIVE
The objectives of this lab are for you to begin the sequential and memory programming using
flip flops in VHDL program. Emphasis will be place on how you implement the device in your
code. Logical constructs, comments and demonstration will all be part of the grade (Kelly, 2013).
PROBLEM STATEMENT
Implement all four of the circuits below. It is only necessary to output Q to an LED (not ̅ ).
Each circuit should have its own logic file. Use the 1 second clock to run your flip flops and
output it to any LED as a check.
Circuit 1(D): Implement oneflip-flop using the function table from 74LS74.
Circuit 2 (JK): Implement one flip-flop using the function table for the 74LS112.
Circuit 4: Implement the dual JK 74LS78 with a common clock, common clear and
individual presets.
Demonstrate the implementation of each circuit to the instructor on the DE-1 board.
(Kelly, 2013)
DESIGN METHODOLOGY
For Lab 6, there were four different circuits that I was required to write code for and then
simulate using my DE-1 board. All four circuits were flip-flops, just different types applied
differently. The logic requirements for each design varied; below I have discussed the details of
each circuit implementation.
Flip-flops; not the sandals, but the logic gates, are the fundamental building blocks of sequential
logic. The D flip-flop is by far the most important of the clocked flip-flops as it ensures that
inputs S and R are never equal to one at the same time. D-type flip-flops are constructed from a
gated SR flip-flop with an inverter added between the S and the R inputs to allow for a single D
(data) input. This single data input D is used in place of the "set" signal, and the inverter is used
to generate the complementary "reset" input thereby making a level-sensitive D-type flip-flop
from a level-sensitive SR-latch as now S = D and R = not D as shown in the diagram below.
A simple SR flip-flop requires two inputs, one to "SET" the output and one to "RESET" the
output. By connecting an inverter (NOT gate) to the SR flip-flop you can "SET" and "RESET"
the flip-flop using just one input as now the two input signals are complements of each other.
This complement avoids the ambiguity inherent in the SR latch when both inputs are LOW,
since that state is no longer possible.
Thus the single input is called the "DATA" input. If this data input is HIGH the flip-flop would
be "SET" and when it is LOW the flip-flop would be "RESET". However, this would be rather
pointless since the flip-flop's output would always change on every data input. To avoid this an
additional input called the "CLOCK" or "ENABLE" input is used to isolate the data input from
the flip-flop after the desired data has been stored. The effect is that D is only copied to the
output Q when the clock is active. This then forms the basis of a D flip-flop.
The D flip-flop will store and output whatever logic level is applied to its data terminal so long
as the clock input is HIGH. Once the clock input goes LOW the "set" and "reset" inputs of the
flip-flop are both held at logic level "1" so it will not change state and store whatever data was
present on its output before the clock transition occurred. In other words the output is "latched"
at either logic "0" or logic "1".There are many different D flip-flop IC's available in both TTL
and CMOS packages with the more common being the 74LS74 which is a Dual D flip-flop IC,
which contains two individual D type bi-stables within a single chip enabling single or master-
slave toggle flip-flops to be made.
For this circuit, two logic files were required, one for the actual JK application and the other for
the one second clock. Being that there were two logic files, this meant that two components
were needed.
The components are the hardware assignments according to the various input/output
requirements. For the D flip-flop there were 4 inputs and 1 output. As for the clock (CLK), I
had 2 inputs and 1 output. The most important aspect of tying these two files together (in the
hardware template) was the usage of a signal.
The purpose of the signal implementation was to create a “bidirectional” data line in order to tie
in the clock to the D flip-flop logic. Without the signal, this would not be possible because all
other assignments were set to either “in” or “out”.
Above is my port map application for each logic file. The code above clearly shows my signal
utilization. My ‘D’ input was assigned to switch 9, Clear was assigned to switch 1 and preset
was assigned to switch 0. My final output is simply assigned to one of the red LEDs; LEDR (0),
while my clock pulse was demonstrated/checked using one of the green LEDs; LEDG(7).
The actual logic statement used for this design was an if/else statement. It was pretty easy to
implement and extremely straightforward as you can see below. All I did was follow the truth
table logic.
For this circuit not only was I to write the code for the actual decoder, but I was also to write
code for the clock logic associated with it. I was able to utilize the same clock code from
previous labs. The logic for this is shown below.
The diagram above shows the entire structure for the actual 74LS112 IC, however, for Lab 6 I
was only required to implement one of the JK flip flops shown on the chip.For this design I
implemented an if/else statement in my logic file. Although this type of logic statement seemed
to make the most sense at the time, in hind sight I feel as though a case statement may have been
a much simpler approach.
For this circuit I needed four inputs (denoted by the “in STD_LOGIC”) and one output (denoted
by the “out STD_LOGIC).
JK Logic Entity
The JK logic entity is necessary because this is where all inputs/outputs are declared to be used
in the actual logic statement (which is shown below).
The preset and clear inputs override the synchronous inputs. When preset is asserted, the flip-
flop is set and Q = 1. When clear is asserted, the flip-flop is cleared and Q = 0(the Xs denote
'don't care' conditions).
When the asynchronous inputs are both high: the synchronous inputs can affect the input but
only on the negative going clock edge, which is characterized by the down arrows in the truth
table (and by the “falling_edge” statement in the code); when J is high and K is low Q = 1, when
J is low and K is high Q = 0, for J and K both low the output will not change from any previous
state and when J and K are both high the output will change states on each triggering clock edge.
The condition for both asynchronous inputs low is not used as the output will be unpredictable
due to the nature of the flip-flop (both Q and Q would briefly be high and the feedback loop
would no longer function).
The condition for which all inputs (except clock) are high is what makes the counter possible. A
clock signal is applied to a flip-flop, all inputs are high and the output Q will alternate between
states on the negative edge of each clock pulse. Q is then showing exactly one half of the clock
frequency. This Q1 is delivered to the clock input of a second flip-flop with all other inputs tied
high. The second clock is receiving half the frequency of the original clock and Q2 becomes one
fourth the frequency of the original clock. This process can continue indefinitely and the
resulting circuit can be described as a frequency divider. The frequency division = 2n, n =
number of flip-flops.
As for the clock logic entity, two inputs and one output were utilized.
A signal was also implemented in order to allow bidirectional data flow inside the “clock”
execution.Without the signal, this would not be possible because all other assignments were set
to either “in” or “out”.
Seeing how there were two different logic files, one for the JK flip flop and the other for the
clock, it was necessary that I implement two components in my hardware template. Keep in
mind that the hardware file is what makes communication between the logic and the hardware
possible. The component files allow the hardware to know which inputs are to be called upon
for certain “duties”, which are executed within these logic files.
The component for each hardware file is the same as the Entity of the actual logic file utilized in
each design. Therefore, I am not going to paste my component for the JK logic, however keep in
mind that the two are implemented differently depending on the file it is used in. What I mean
by this is that the “component” is part of the architecture (which is the logic of the circuit) of the
hardware file and in the logic file, this same piece of code is implemented in the Entity (which
describes the actual interface; assigns the I/Os).
Now the actual pin assignments, or port map, implementation for this particular design was as
follows:
As with the components, I also needed two port maps due to the two logic files used in my
design. The most important aspect of tying these two files together (in the hardware template)
was the usage of a signal. The same signal implemented in the JK logic file was also
implemented in each of my port maps.
I used switches 9 and 8 for my J and K so that I could keep them separate from my Clear and
Preset. Having the four inputs separated by six switches made it easier for me to differentiate
between them when demoing in lab. I assigned my only output (Q) to LEDR(0) and my clock
pulse to LEDG(7).
This assignment was placed outside of the individual port maps but still inside of the actual port
map specifications.
For my third circuit I was to design the code for the 7475 IC (D Quad Latch). The difference
between a D-type latch and a D-type flip-flop is that a latch does not have a clock signal to
change state whereas a flip-flop always does. The D flip-flop is an edge triggered device which
transfers input data to Q on clock rising or falling edge. Data Latches are level sensitive devices
such as the data latch and the transparent latch.
The 7475 is a TTL MSI circuit that contains four D latches, also known as a 'quad bi-stable
latch.' These latches are ideally suited for use as temporary storage for binary information
between processing units and input/output or indicator units. Information present at a data (D)
input is transferred to the Q input when the enable (G) is high, and the Q output will follow the
data input as long as the enable remains high. When the enable goes low, the information (that
was present at the data input at the time the transition occurred) is retained at the Q output until
the enable is permitted to go high. The logic diagram and truth table for the 7475 IC is shown
below.
The logic for this circuit was fairly straight forward making it the easiest of the four designs to
implement. Basically, as you can see from the truth table above, as long as Enable is HIGH, ‘Q’
follows ‘D’. When Enable is LOW, there is no change. My logic statement for this design is
shown below.
I applied two simple ‘if’ statements in order to simulate the D Quad Latch. The code above is
fairly straight forward as it follows the truth table for this circuit; Q follows D as long as Enable
is HIGH.
For this circuit there was only one logic file required. While the logic fileis what creates the
actual simulation of this circuit, it would not be able to perform its functions had it not been for
the hardware template; which is used to communicate with the DE-1 board. For the architecture
of this circuit, only one component was needed rather than two, since this circuit did not have a
clock.
The components are the hardware assignments according to the various input/output
requirements. For the D Latch there were 6 inputs (D1 through D4 and Enable1, Enable2) and 4
outputs (Q1 through Q4).
Above is my port map application for my logic file. My inputs are set to switches 3 through 0,
with D4 (MSB) being assigned to switch 3 and D1 (LSB) being assigned to switch 0. My output
assignments were set up similar; Q4 (MSB) was assigned to LEDG 3 and Q1 (LSB) was
assigned to LEDG0. I assigned my two enables to switches 9 (enable2) and 8 (enable1) so that I
could more easily differentiate between them and my inputs.
My fourth and final design was the 74LS78 JK Flip-Flop. This chip contains two negative-edge
triggered flip-flops with individual J-K, preset inputs and common clock and common clear
inputs. The logic levels at the J and K inputs may be allowed to change while the clock pulse is
HIGH and the flip-flop will perform according to the function table as long as minimum setup
and hold times are observed. The preset and clear are asynchronous active-low inputs. When
LOW, they override the clock and data inputs forcing the outputs to the steady-state levels as
shown in the truth table below.
JK Truth Table
Pre Clr J K Clk Q
0 1 X X X 1
1 0 X X X 0
0 0 X X X UNUSED
1 1 0 0 Q0
1 1 1 0 1
1 1 0 1 0
1 1 1 1 TOGGLE
1 1 X X 1 Q0
The diagram above shows the entire structure for the actual 74LS78 IC, for this design I was
required to simulate both JKs, unlike with the 74LS112 design. For this design I implemented an
if/else statement in my logic file. Although this type of logic statement seemed to make the most
sense at the time, in hind sight (once again) I feel as though a case statement may have been a
much simpler approach.
For this circuit I needed seven inputs (denoted by the “in STD_LOGIC”) and two outputs
(denoted by the “out STD_LOGIC).
JK Logic Entity
The JK logic entity is necessary because this is where all inputs/outputs are declared to be used
in the actual logic statement (which is shown below).
The preset and clear inputs override the synchronous inputs. When preset is asserted, the flip-
flop is set and Q = 1. When clear is asserted, the flip-flop is cleared and Q = 0 (the Xs
denote'don't care' conditions).
When the asynchronous inputs are both high: the synchronous inputs can affect the input but
only on the negative going clock edge, which is characterized by the down arrows in the truth
table (and by the “falling_edge” statement in the code); when J is high and K is low Q = 1, when
J is low and K is high Q = 0, for J and K both low the output will not change from any previous
state and when J and K are both high the output will change states on each triggering clock edge.
The condition for both asynchronous inputs low in not used as the output will be unpredictable
due to the nature of the flip-flop (both Q and Q would briefly be high and the feedback loop
would no longer function).
The condition for which all inputs (except clock) are high is what makes the counter possible. A
clock signal is applied to a flip-flop, all inputs are high and the output Q will alternate between
states on the negative edge of each clock pulse. Q is then showing exactly one half of the clock
frequency. This Q1 is delivered to the clock input of a second flip-flop with all other inputs tied
high. The second clock is receiving half the frequency of the original clock and Q2 becomes one
fourth the frequency of the original clock. This process can continue indefinitely and the
resulting circuit can be described as a frequency divider. The frequency division = 2n, n =
number of flip-flops.
As for the clock logic entity, two inputs and one output were utilized.
A signal was also implemented in order to allow bidirectional data flow inside the “clock”
execution. Without the signal, this would not be possible because all other assignments were set
to either “in” or “out”.
Seeing how there were two different logic files, one for the JK flip-flop and the other for the
clock, it was necessary that I implement two components in my hardware template. Keep in
mind that the hardware file is what makes communication between the logic and the hardware
possible. The component files allow the hardware to know which inputs are to be called upon
for certain “duties”, which are executed within these logic files.
Clock Logic Component:
The component for each hardware file is the same as the Entity of the actual logic file utilized in
each design. Therefore, I am not going to paste my component for the JK logic, however keep in
mind that the two are implemented differently depending on the file it is used in. What I mean
by this is that the “component” is part of the architecture (which is the logic of the circuit) of the
hardware file and in the logic file, this same piece of code is implemented in the Entity (which
describes the actual interface; assigns the I/Os).
Now the actual pin assignments, or port map, implementation for this particular design was as
follows:
As with the components, I also needed two port maps due to the two logic files used in my
design. The most important aspect of tying these two files together (in the hardware template)
was the usage of a signal. The same signal implemented in the JK logic file was also
implemented in each of my port maps.
I used switch 9 for my clear, switches 5 and 2 for my presets,switches 4 and 3 for JK2 and
switches 1 and 0 for JK1. Once again I kept my Clear separate from all other inputs in order to
help differentiate between them in lab. I assigned my two outputs (Q2 and Q1) to LEDR(1) and
LEDR(0), while my clock pulse was assigned to LEDG(7).
This assignment was placed outside of the individual port maps but still inside of the actual port
map specifications.
D Flip-Flop
All inputs are HIGH When Preset, Clear = HIGH When CLEAR is LOW
at Rising Edge of and D = LOW (at rising edge Q is LOW
CLOCK, Q goesof CLOCK), Q goes LOW
HIGH
JK Flip-Flop (74LS112)
When all inputs are HIGH, When all inputs EXCEPT ‘J’ are HIGH, When all inputs EXCEPT ‘K’ are
Q TOGGLES at Q = LOW HIGH, Q=HIGH at falling edge
falling edge of CLOCK at falling edge of CLOCK of CLOCK
CONCLUSION
Aside from the fact that I was unable to demo all four of my circuits in lab on Friday, I would
consider this lab a success. I was able to successfully write and compile my code later that day
in order to upload all of my files and prepare for my next opportunity to demo. Although I had
to debug syntax errors on 2 out of 4 of my designs, I feel as though I am finally getting the hang
of VHDL after the last couple of labs. Especially since my last two designs were written in
notepad, opened up in Quartus and then successfully compiled without any errors.
I credit my surplus of syntax errors to my lack of preparation prior to lab. I realize how
important it is to have all of my code written and debugged prior to lab. I hope to be completely
caught up in all my classes by the end of this week, and am determined to keep it that way so that
I will not be turning in any more late assignments. With that said, I really enjoyed this lab and all
its challenges, and look forward to the next.
REFERENCES
5. http://www.electronics-tutorials.ws/sequential/seq_4.html