Codiode

Parameterized Serial In Parallel Out

EasyVerilog / SystemVerilogBuild3 solved

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_out go to 0
  • Priority rules: Asynchronous reset takes precedence over the clock and enable signals. When en is 0, the register holds its current value regardless of serial_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 WIDTH with a default value of 8.
  • Clock must be posedge clk.
  • Reset must be asynchronous and active-low.
  • When en is high, the register shifts left: data_out[0] receives serial_in, and data_out[WIDTH-1] is discarded.
  • When en is low, data_out must hold its current value.

Topics

sequentialshift-registerparameter

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

Solve this on a laptopSend yourself the link and continue there.