Memory Initialization via Reset Block
A RAM doesn't clear itself on reset. Clearing it means walking every address and writing zero, one per clock, while normal access waits.
The solution module is a 16-word by 8-bit single-port synchronous RAM with an automatic initialization sequence. Upon reset, the module suspends normal memory operations and sequentially writes zero to every memory address. Once all 16 addresses are cleared, it asserts a ready flag and acts as a standard synchronous RAM, allowing normal reads and writes.
Timing and Reset Rules:
- Clock edge:
posedge clk - Reset type: Synchronous, active-high
rst - During reset and initialization (
readyis 0):data_outoutputs8'h00and any external writes (weis 1) are ignored. - Initialization sequence: When
rstis 1,readybecomes 0 on the next clock cycle and the internal initialization address resets to 0. Whenrstgoes low, the module writes8'h00to the current internal address and increments the address each cycle. After writing to address 15,readybecomes 1 on the next clock cycle. - During normal operation (
readyis 1): The module acts as a standard read first synchronous RAM. On the positive clock edge, ifweis 1,data_inis written toaddr; regardless ofwe,data_outupdates to the previous value stored ataddr. - If
rstis asserted at any time, the initialization process immediately restarts.
Worked Trace:
Cycle 1: rst=1 → (On posedge) ready=0, internal counter=0
Cycle 2: rst=0 → (On posedge) mem[0]=0, internal counter=1
Cycle 3: rst=0 → (On posedge) mem[1]=0, internal counter=2
...
Cycle 17: rst=0 → (On posedge) mem[15]=0, ready=1
Cycle 18: rst=0, we=1, addr=5, data_in=8'hAA → (On posedge) mem[5]=8'hAA, data_out=0
Cycle 19: rst=0, we=0, addr=5 → (On posedge) data_out=8'hAA
| Signal | Direction | Width | Description |
|---|---|---|---|
clk |
input | 1 | Positive-edge triggered clock |
rst |
input | 1 | Synchronous active-high reset |
we |
input | 1 | Write enable for normal operation |
addr |
input | 4 | Memory address for read and write operations |
data_in |
input | 8 | Data to be written to memory |
data_out |
output | 8 | Data read from memory; outputs 0 during initialization |
ready |
output | 1 | Status flag; 1 when initialization is complete |
Constraints
- The memory must be exactly 16 words deep and 8 bits wide.
rstis synchronous and active-high.- External reads and writes must be completely ignored while
readyis 0. data_outmust be strictly8'h00whilereadyis 0.data_outupdates synchronously onposedge clk.- The memory must exhibit read first behavior during normal writes.
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 Memory and Storage
Problem 26 of 26 in the Memory and Storage track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks