In this lab, we are going to learn how to create a latch, and flip-flop as an introduction to sequential logic in VHDL, but first we will learn about composite literals, and how to manipulate bit strings.
A Composite Literals are an array of literals, but in this lab, we will focus on string literals, which we already used by using the std_logic_vector
.
We already learned how to assign a std_logic_vector
value using double quotes, and it's clear that you should use std_logic
values in that string.
We could also assign the value of m
using a hex
, oct
, or binary
value:
You could concatenate multiple string literals using the &
symbol, this will be very useful in expanding a literal (for example, to get the carry when using numric_std).
Note: You could select a subset of a string using range as an index.
In this section, we are going to create some memory elements using behavioural style code, which is way easier in describing sequential logic.
As you remember the SR latch will have the following truth table.
S | R | Q |
---|---|---|
0 | 0 | Previous State |
0 | 1 | 0 |
1 | 0 | 1 |
1 | 1 | Invalid |
Notice that we've created a signal called q_next
, which will hold the next value of q
, we couldn't use q
directly because it's an output, so we couldn't read it.
To create a flip-flop, we need a condition that is true only on a rising edge, we could check the two conditions clk'event
and clk='1'
, which mean that the clk must have an event, and its current value is 1
, so it's a rising edge.
Luckily VHDL offers functions like rising_edge
, which could check the edge for us.
J | K | CLK | |
---|---|---|---|
0 | 0 | ↑ | |
0 | 1 | ↑ | 0 |
1 | 0 | ↑ | 1 |
1 | 1 | ↑ |
Notice that the sensitivity list in our process only contains the clock.
You should design a D-Latch with Enable.
You should design a D-Flip-Flop, which has 3 inputs D
, clk
, clear
.
Notice that the clear is an asynchronous clear.
Create a testbench for your D-Flip-Flop
This should be a trivial task, you should create an 8-bit data register, it has 2 inputs data
, and clk
.
VHDL
IUG