True Dual Port RAM Collision Resolution
Two ports writing the same address in the same cycle is a collision. Without a rule for who wins, the stored value is undefined.
This module implements a 256-word by 8-bit True Dual-Port RAM with integrated collision resolution. Both Port A and Port B can independently read and write to the shared memory array. When both ports attempt to write to the identical address in the same clock cycle, a collision occurs. Port A has strict priority; its data must be written to the memory array, and Port B's write is discarded. Reads are synchronous and operate in a write-first (read-through) mode. If a port reads an address that is being written to in the same cycle by either port, the read output must immediately reflect the newly written data.
Timing and Reset Rules:
- Clock edge:
posedge clk - Reset: There is no reset signal; the memory array contents are uninitialized at power-up.
- Write-first forwarding: If Port X writes to address N,
dout_xupdates with the new data on the exact same clock edge. - Cross-port forwarding: If Port X writes to address N and Port Y reads address N simultaneously,
dout_yupdates with Port X's new data. - Collision forwarding: If Port A and Port B both write to address N simultaneously, Port A wins. Both
dout_aanddout_bmust output Port A's data.
Worked Trace:
- Cycle 1:
we_a=1,addr_a=8'h10,din_a=8'hAA,we_b=0,addr_b=8'h20. Port A writes8'hAAto8'h10.dout_abecomes8'hAA. - Cycle 2:
we_a=0,addr_a=8'h10,we_b=1,addr_b=8'h10,din_b=8'hBB. Port B writes8'hBBto8'h10, Port A reads8'h10.dout_bbecomes8'hBB(write-first),dout_abecomes8'hBB(cross-port forward). - Cycle 3:
we_a=1,addr_a=8'h30,din_a=8'hCC,we_b=1,addr_b=8'h30,din_b=8'hDD. Collision at8'h30. Port A wins.dout_abecomes8'hCC,dout_bbecomes8'hCC(collision forward). Memory at8'h30is8'hCC. - Cycle 4:
we_a=0,addr_a=8'h30,we_b=0,addr_b=8'h30. Both ports read8'h30. Both output8'hCC.
| Signal | Direction | Width | Description |
|---|---|---|---|
clk |
input | 1 | Positive-edge triggered clock |
we_a |
input | 1 | Port A write enable |
addr_a |
input | 8 | Port A memory address |
din_a |
input | 8 | Port A write data |
dout_a |
output | 8 | Port A read data; registered output |
we_b |
input | 1 | Port B write enable |
addr_b |
input | 8 | Port B memory address |
din_b |
input | 8 | Port B write data |
dout_b |
output | 8 | Port B read data; registered output |
Constraints
- Memory capacity must be exactly 256 words of 8 bits each.
- Outputs
dout_aanddout_bmust be registered and update exactly onposedge clk. - Port A strictly overrides Port B when
we_a=1,we_b=1, andaddr_a == addr_b. - Read-through (write-first) behaviour is required for both intra-port and cross-port read/write combinations.
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 9 of 26 in the Memory and Storage track.
Related problems
Browse all problems · Verilog practice problems · Learning tracks