6. Register File
This lab implements a register file in SystemVerilog and brings the design to the Urbana board. SystemVerilog has built-in features that let us implement whole registers in a few lines of code.
1module register_en( input logic i_clk,
2 input logic i_en,
3 input logic [63:0] i_d,
4 output logic [63:0] o_q );
5 always_ff @(posedge i_clk)
6 begin
7 if(i_en) o_q <= i_d;
8 end
9endmodule
For example, Listing 6.1 shows an enabled 64-bit register.
On the rising edge of i_clk, the register sets the internal 64-bit state to i_d when i_en is asserted.
Otherwise, the register holds its state and drives o_q.
These features accelerate development in production settings.
However, we aim for end-to-end understanding with a bottom-up approach.
So we build the register file from single-bit SR latches.
Fig. 6.1 Register file with two read ports and one write port. The register file contains four 4-bit registers.
Fig. 6.1 shows a register file with four internal 4-bit registers. External logic reads through two ports and writes through one port. An interactive implementation of the targeted register file is available on CircuitVerse.
6.1. Building Blocks
From the provided schematic, the building blocks are:
A single 2:4 decoder:
module decoder_2_4( input logic [1:0] i_binary, output logic [3:0] o_one_hot );
Two 4:1 multiplexers:
module mux_4( input logic [1:0] i_s, input logic [3:0] i_in0, input logic [3:0] i_in1, input logic [3:0] i_in2, input logic [3:0] i_in3, output logic [3:0] o_out );
Four enabled 4-bit registers:
module register_en_4( input logic i_clk, input logic i_en, input logic [3:0] i_d, output logic [3:0] o_q );
We implement the register file using SR latches. First, implement a standalone SR latch (module
sr_latch). Then use it to build a D latch (moduled_latch). Next, two D latches form a rising-edge triggered D flip-flop (moduled_flip_flop). From that, derive an enabled flip-flop (moduled_flip_flop_en). Four enabled D flip-flops make an enabled 4-bit register (moduleregister_en_4).
Hint
We implemented the modules sr_latch, d_latch and d_flip_flop together with fitting testbenches in the lectures.
You may use these implementations in this task.
Tasks
Implement the module
decoder_2_4indecoder_2_4.sv. Test it with the testbenchdecoder_2_4_tbindecoder_2_4_tb.sv.Implement the module
mux_4inmux_4.sv. You may reuse code from the ALU lab (see Section 5).Implement and test the following modules:
sr_latchinsr_latch.sv.d_latchind_latch.sv.d_flip_flopind_flip_flop.sv.d_flip_flop_enind_flip_flop_en.sv.register_en_4inregister_en_4.sv.
6.2. Four-bit Register File
This task combines the building blocks into the four-bit register file. We’ll use the following SystemVerilog declaration for the register file:
module register_file_4( input logic i_clk,
input logic [1:0] i_reg_read_0,
input logic [1:0] i_reg_read_1,
input logic [1:0] i_reg_write,
input logic [3:0] i_port_write,
input logic i_write_enable,
output logic [3:0] o_port_read_0,
output logic [3:0] o_port_read_1 );
An unfinished testbench is provided: register_file_4_tb.sv.
Tasks
Implement the module
register_file_4in the fileregister_file_4.sv.Provide the internal register values in the comments of the testbench
register_file_4_tb. Usexxxxif the register was never written. Uncomment and finish the assertions in the testbench.
6.3. Display Driver
In Section 4.3 and Section 5 we showed at most two different digits at a time: one on display 4 and one on display 3. This worked without a clock since the two display modules have separate segment signals. Deploying the register file requires six digits. Thus, we have to show different digits on the displays of the same module.
The trick is time multiplexing. At any point in time, the driver enables only one display per module and drives the module’s segment signals with the pattern for this display. Then it moves on to the next display, and so on. If the driver cycles through the displays fast enough, our eyes don’t notice the switching and we see all digits at once.
Our driver divides time into four slots.
In slot \(s\), it lights display \(s\) of the module driven by D1_SEG and display \(s+4\) of the module driven by D0_SEG.
For example, slot 0 lights displays 0 and 4 by setting D1_AN = 4'b1110 and D0_AN = 4'b1110.
A free-running 18-bit counter, clocked by the board’s 100 MHz clock, provides the slot through its two most significant bits.
Thus, the driver moves on to the next slot every \(2^{16}\) clock cycles, i.e., every 655.36 µs, and refreshes all displays about 381 times per second.
The driver has the following declaration:
module display_driver( input logic i_clk,
input logic [31:0] i_values,
input logic [7:0] i_enable,
output logic [7:0] o_d0_seg,
output logic [7:0] o_d1_seg,
output logic [3:0] o_d0_an,
output logic [3:0] o_d1_an );
i_values holds the eight hex digits: bits [4k+3:4k] belong to display \(k\).
For example, display 0 shows i_values[3:0] and display 7 shows i_values[31:28].
Setting i_enable[k] to 1 turns display \(k\) on.
Disabled displays stay off, i.e., their display-enable signals are always 1.
The outputs connect directly to the board’s signals D0_SEG, D1_SEG, D0_AN and D1_AN.
A template is provided: display_driver.sv.
Tasks
Implement the module
display_driverin the filedisplay_driver.sv. Use the template and your seven-segment decoder from Section 4.Test your implementation in the testbench
display_driver_tbin the filedisplay_driver_tb.sv. Use a 100 MHz clock. Check all eight displays and at least one configuration in which some of the displays are disabled.
6.4. Register File in Practice
Fig. 6.4.1 Picture of the deployed Register File. Shown on the left are the selected registers 3 and 1, which hold the mystery values 4 and 2. The write-port is set to F and is supposed to be written into register 1 when the button is used.
Now deploy the register file.
Use the 100 MHz board clock CLK_100MHZ for i_clk.
Use the first four switches to select the two read-register IDs.
The next two switches select the ID of the write-register.
The remaining four switches provide the 4-bit write data.
Wire SW[1:0] to i_reg_read_0, SW[3:2] to i_reg_read_1, SW[5:4] to i_reg_write, and SW[9:6] to i_port_write.
Use push-button BTN0 as the write-enable and treat high as asserted.
An example configuration can be seen in Fig. 6.4.1
Display the read-register IDs on display 0 and 1 and the write-register ID on display 2.
Show the write-port data on display 3 and the read-port data on display 6 and 7.
Use your display_driver from Section 6.3 and keep displays 4 and 5 off.
Lastly, drive LED[0] when the write-enable is asserted.
A template for register_file_top is provided: register_file_top.sv.
Tasks
Finish
register_file_topusing the template and write the correspondingregister_file.xdcscript.Program the FPGA of a Urbana board. Demonstrate the design to the teaching personnel. Include a scan of the tailored coversheet in your submission.