Updated Nov 2021 Robucci
Updated 2023 April Robucci - minor textual updates, added red values to hold state depiction
In this lab, students will verify the operation of a 4-bit bidirectional shift register, which features left shift and right shift capabilities, based on a D flip-flop (DFF), which is constructed using a JK flip-flop and an inverter.
Latches with an enable signal have a mode to hold a signal, and another mode for which inputs propagate to the output. In the case of a D latch (e.g. SR-latch with and ) when the enable signal is asserted the output follows the input (with some delay) in a so-called transparent mode.
Flip-flops wait for a clock signal transition to propagate any single pending change to the output. There is no transparent mode.
The JK flip-flop has data inputs J and K with associated effects controlled by the signal clk. A 7476 JK flip-flop (or substitute part 74LS112) also has active low PRESET and CLEAR signals that bypass the clk control, and are thus called asynchronous inputs.
The function table show below is taken from http://www.ti.com/lit/ds/symlink/sn5476.pdf (substitute part 74LS112 is functionaly similar). Therein is used to represent the value of Q before the condition input condition described.
A reduced version without and can be considered, which can created using a SN74LS76A by tieing and to the power supply (high). The effective basic JK flip-flop circuit is shown below.
When the clock signal, , is low, the circuit is an a hold state, sustaining the output or using positive feedback, a loop of two inversions.
Otherwise, after the falling edge of the clock signal the output changes based on the inputs J and K inputs. The Setup time is the amount of time that J and K must be stable at the desired values while the clock signal is high before the falling edge of the clock signal in order to see consistent behavior as described in the function table.
In your simulations, be sure to change the input signal and let it be stable for sufficient time before the falling edge of the clock.
While Verilog provides built-in combinational primitives (e.g. not,nand,or), Verilog does not provide built-in sequential primitives. Therefore designers may utilize simulation models based on descriptive procedural code or user-defined primatives. Learning these is outside the scope of this course, so you will be provided a model to use in your design.
Here is one approach for a basic simulation model using procedural code. It could be suitable for functional simulation. You won’t use this model, but it may be of interest to some students for examination. Learning this style of procedural code modeling is outside the scope of this course.
Here is the model that you will use for this lab. You will not be required to code a model like this for this course, but at least a cursory examination is useful. You may notice the definition of a Verilog user-defined primitive (UDP) using the keywords primitive
and table
. The model also includes a specify
block to generate a clk-to-q timing delay of 20 ns. specify
blocks are processed by Icarus Verilog when the -gspecifiy option is used and ignored otherwise.
The user-defined primative model also includes a specification of setup time violations, but unfortunately these are not implemented by Icarus Verilog at the time of this writing. If you perform the simulations on commercial simulations such as Cadence Xcelium (available via edaplayground.com ) warning can be generated. You will learn to use commercial simulators available at UMBC in later courses.
Here Example Warning Reported by Cadence Xcelium. This is not implemented in Icarus Verilog.
Here is a testbench that you can start with to verify your understanding of the operation of a JK Flip-Flop.
To compile the design including the specify block, use the sepcify flag by including the option -gspecify
. Additionally the option -Wall
displays more warnings than the default.
The following generates the executable jk_ff_tb:
(the -Wall option prints more warnings which can help catch common mistakes)
iverilog -gspecify -Wall -g2012 jk_ff_tb.sv jk_ff.sv -o jk_ff_tb
Depending on the platform, you may need to run vvp or just the executable directly.
./jk_ff_tb
If your environment is not setup correctly, you may need to run this command instead:
vvp ./jk_ff_tb
New Setting: use specify blocks
Don’t neglect to provide the option -gspecify
to iverilog. Otherwise the specify block in the provided model that provides the delay aspect of the model will be ignored.
A JK flip-flop can be used to build a 1-bit data storage element by connecting J to an a data signal and K to an inverted version of the signal.
J | K | |
---|---|---|
0 | 0 | |
0 | 1 | 0 |
1 | 0 | 1 |
1 | 1 |
input | intermediate | output | |
---|---|---|---|
D | J | K | |
0 | 0 | 1 | 0 |
1 | 1 | 0 | 1 |
The term register in digital logic can be used to generalize a collection of flip-flops used to store a digital word. Typically a register and word are distinguished by being associated with more than one bit, though a 1-bit register is conceptually valid.
In this lab you will make a shift register. A shift register is a cascade of flip-flops (can be any type; JK, D, T, etc…), where each flip-flop holds one bit of a binary number, and all of the flip-flops share the same clock signal. On every negative clock edge, the values held in the flip-flops will shift over to their neighboring flip-flops. The “Right/Left” wire determines which way they will shift. The value on the “Data In” wire is written to the empty flip-flop on the end.
Because this circuit allow
Here are some example behaviors, assuming that the stored binary number is denoted by Q[3,2,1,0].
Notice that we are wiring the K’s so that they are always the inverse of the J’s. When JK flip-flops are wired this way, they are synthesizing (or acting like) a D flip-flop.
Next, notice how the combinational logic gates control the bit shifts.
With attention to the 2nd circle, observe that both Q3 and Q1 are fed into the AND gates.
If R/L_n = 0 (left shift), then Q1 is chosen to fill the F2 flip-flop.
If R/L_n = 1, then Q3 is chosen.
When a shift register can either shift left or right (ability to perform both operations), it’s called a bidirectional shift register.
Build and demontrate the 4-bit bidirectional shift register.
CLK | Direction | DataIn | Data Out (Current) | Data Out (New) |
---|---|---|---|---|
LO–>HI | X | X | 1100 | 1100 |
HI–>LO | 1 (Right) | 1 | 1100 | 1110 |
HI–>LO | 1 (Right) | 0 | 1100 | 0110 |
HI–>LO | 1 (Right) | 1 | 1010 | 1101 |
HI–>LO | 1 (Right) | 0 | 1111 | 0111 |
HI–>LO | 0 (Left) | 1 | 0110 | 1101 |
HI–>LO | 0 (Left) | 0 | 1111 | 1110 |
HI–>LO | 0 (Left) | 1 | 0000 | 0001 |
HI–>LO | 0 (Left) | 0 | 1010 | 0100 |