The hardware elements which can store data can be implemented through sequencial circuits called flip-flops. They store the values depending on the input value and the clock cycle; the stored value can be changed only when the clock has reached another positive transition ( the rising edge of the signal, the moment where a signal goes from low to high). There are 4 major flip-flop types: D, T, SR and JK. Our target is the first one, since it is the one we will use later in our implementations. It is the most important and it is mainly used for the implementation of the registers inside CPUs (the smallest and the fastest memory unit inside the hierarhy).
Block diagram for the D flip-flop
The inputs and the outputs are:
D
- the value (data) to be storedclk
- the clock signal, considered as 'active' on the rising edge of the signalQ
- the current state / value!Q
- the inverted value
The functional equation for the flip-flop is Qnext ⇐ D
, meaning that the next state (Qnext
) of the flip-flop will only be dependent on the D
input, the current state (Q
) being ignored, as we can notice from the table below:
D | Q | Qnext |
---|---|---|
0 | 0 | 0 |
0 | 1 | 0 |
1 | 0 | 1 |
1 | 1 | 1 |
Transition table for the D flip-flop
along with the transition tables, we can have a better overview of our system's behavior by monitoring the waveform (timing diagrams), as illustraded in the next snapshop. Here we can observe how the output Q
changes only on the front edge of the clock and takes the value of the input D
.
Waveform
The flip-flop can store 1 bit of data. In order to extend the memory capacity, we can group several flip-flops together to store the data as a whole. When adding some controls and synchronizing the operations with the clock, we can call it a register. A register, like any other sequencial circuits, is sensitive to clk signal and shall also consider the reset, synchronus or asyncronus. In order to control the acces to a bus, the main operations shall be taken into consideration:
oe
(output enable);we
(write enable).The writing operation is synchronus; however, reading and reset can vary, depending on the usecase.
In order to implement the exercises, use the lab archive below, considering the simulator you have on your workstation. The files already have a Xilinx ISE / Vivado project that you are able to run; in addition, for this practice you already have a testing module; the checking will be performed visually during the lab practice. Follow the instructions and hints below and the zones marked with TODO in the corresponding files.
oe
is high, the out
shall imediatelly be activated with the stored data;we
is high, the input data found on the in
is stored; the effect are seen at the next clock cycle;NOTE: You can start the implementation using the files from the lab practice and modify them accordingly! The work files for this will be uploaded later this week, however they will not contain any major improvements.
clk
signal.⇐
enable
: 0 - counter is disabled (the value remains the same) 1 - counter is enabled (it counts up or down, depending on the direction
- see below)direction
: 0 - counter increments it's value; 1 - counter decrement it's value