Parameterized Serial In Parallel Out
SPI and UART receivers collect a word one bit at a time and then hand it over in parallel. A width parameter lets one shift register serve any word size.
This module accumulates a continuous stream of serial bits into a parallel output register. The width of the parallel output is defined by a parameter WIDTH. When the enable signal is asserted, the register shifts its current contents to the left. The existing Most Significant Bit (MSB) is discarded, and the new serial input bit is loaded into the Least Significant Bit (LSB) position. The parallel output continuously reflects the current state of the shift register.
Timing and Reset Rules
- Clock edge:
posedge clk - Reset type: asynchronous
- Reset polarity: active-low
rst_n - Output values on reset: all bits of
data_outgo to 0 - Priority rules: Asynchronous reset takes precedence over the clock and enable signals. When
enis 0, the register holds its current value regardless ofserial_in.
Worked Trace (WIDTH=4)
Cycle 1: rst_n=0 → data_out=4'b0000
Cycle 2: rst_n=1, en=1, serial_in=1 → data_out=4'b0001 (1)
Cycle 3: rst_n=1, en=1, serial_in=0 → data_out=4'b0010 (2)
Cycle 4: rst_n=1, en=0, serial_in=1 → data_out=4'b0010 (hold)
Cycle 5: rst_n=1, en=1, serial_in=1 → data_out=4'b0101 (5)
Cycle 6: rst_n=1, en=1, serial_in=1 → data_out=4'b1011 (11)
Diagrams
Port Table
| Signal | Direction | Width | Description |
|---|---|---|---|
clk |
input | 1 | Positive-edge triggered clock |
rst_n |
input | 1 | Asynchronous active-low reset; clears data_out to 0 |
en |
input | 1 | Shift enable; shifts data left and loads serial_in to LSB when 1 |
serial_in |
input | 1 | Serial data input |
data_out |
output | WIDTH |
Parallel data output |
Constraints
- The module must declare a parameter
WIDTHwith a default value of 8. - Clock must be
posedge clk. - Reset must be asynchronous and active-low.
- When
enis high, the register shifts left:data_out[0]receivesserial_in, anddata_out[WIDTH-1]is discarded. - When
enis low,data_outmust hold its current value.
Topics
Solve this problem
Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.
This problem is part of Codiode Pro. The statement above is free to read.
The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.
Part of Sequential RTL
Problem 12 of 26 in the Sequential RTL track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks