Build an SDRAM controller that reads two words per request inside tRCD, CL and tRP, and never misses a refresh.
Hardware context: An SDRAM controller for a display driver that fetches two pixels per request and refreshes the memory. Build the controller that schedules ACTIVATE, READ, PRECHARGE and REFRESH inside their waits.
A display driver fetches pixels from an SDRAM two at a time. The memory takes one command per clock edge. A command that comes too early returns garbage, and a memory that is not refreshed forgets.
This is an Implement problem. Write dram_ctl. For each request it reads two words and returns them as data_a and data_b. Between requests it must send a REFRESH command often enough.
The second word may be in the same row as the first one. Then the row is already open, and a second READ is enough. If it is in another row, the open row must be closed first.
The test connects your module to a model of the memory. The model checks every wait at every clock edge. The words in the memory are different in every test.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
reqs | 36 | input of each check |
Full specification
module dram_ctl (
input logic clk,
input logic rst, // synchronous, active high
input logic req, // 1 for one cycle while ready is 1: read two words
input logic [2:0] row_a, // the first word
input logic [1:0] col_a,
input logic [2:0] row_b, // the second word
input logic [1:0] col_b,
output logic ready, // 1: idle, a request is taken at the next rising edge
output logic [7:0] data_a, // the two words, valid when ready is 1 again
output logic [7:0] data_b,
// the SDRAM pins
output logic [2:0] cmd, // 0 NOP, 1 ACTIVATE, 2 READ, 3 PRECHARGE, 4 REFRESH
output logic [2:0] addr, // the row with ACTIVATE, the column with READ
input logic [7:0] dq // the data pins
);
// your design
endmodule
| Command | Effect | Rule |
|---|---|---|
| 1 ACTIVATE | Copies the row on addr into the row buffer. | No row is open, and the last PRECHARGE is 2 or more cycles back (tRP). |
| 2 READ | Reads the column on addr[1:0]. The word is on dq 2 cycles later (CL), for one cycle. | A row is open, and its ACTIVATE is 3 or more cycles back (tRCD). |
| 3 PRECHARGE | Closes the open row. | Allowed in any cycle. |
| 4 REFRESH | Refreshes the next row of the memory. | No row is open. tRP as for ACTIVATE. No command in the next 3 cycles (tRFC = 4). |
| 0 NOP | Nothing. | Always allowed. |
A wait of 3 cycles means: the later command is taken 3 clock edges after the earlier one, or later. The memory holds 8 rows of 4 words. It must see a REFRESH at least once in every 48 cycles, counted from the end of reset.
| Port rule | Definition |
|---|---|
| Request | req is 1 for one cycle while ready is 1. The four address inputs are valid in that cycle only. |
| ready | 1 while the controller can take a request. After a request it must be 1 again within 24 cycles. |
| data_a, data_b | The two words, valid when ready is 1 again. They stay until the next request ends. |
| Refresh | The controller may hold ready at 0 while it refreshes, for at most 8 cycles. |
| Reset | At a rising edge with rst = 1 the controller goes idle and sends NOP. |
Each test runs 160 cycles and sends two requests. The result has three fields.
| Field | Meaning |
|---|---|
| rules_broken | Rule numbers. 0: READ too early. 1: ACTIVATE on an open row. 2: tRP. 3: tRFC, or a REFRESH with a row open. 4: refresh too late. 5: data_a or data_b changed when the next request was taken. |
| late | The requests that were not taken or not answered in time. |
| wrong_words | A set: 0 and 1 are data_a and data_b of the first request, 2 and 3 of the second. |
Examples
Example 1
Two Rows, Then Two More Rows- Input
from cycle 2: row 1 column 2, then row 5 column 0; from cycle 60: row 7 column 3, then row 0 column 1
- Output
rules_broken = {}, late = {}, wrong_words = {}, requests = 2
Each request names two different rows. The controller opens the first row, reads, closes it, waits tRP, and opens the second row. A refresh must also fit somewhere in the 160 cycles, three times or more.
Example 2
Both Words in One Row- Input
from cycle 4: row 3 column 0, then row 3 column 3; from cycle 70: row 6 column 1, then row 6 column 2
- Output
rules_broken = {}, late = {}, wrong_words = {}, requests = 2
The second word is in the row that is already open. One more READ is enough: a page hit. Closing and opening the same row again is slower but also accepted.
Example 3
The Same Word Twice- Input
from cycle 1: row 2 column 2, then row 2 column 2; from cycle 40: row 0 column 0, then row 0 column 0
- Output
rules_broken = {}, late = {}, wrong_words = {}, requests = 2
Both words of a request are one word of one row. After the first READ the row is still open, so a second READ of the same column is a page hit. The two answers must be equal.
Example 4
A Request When a Refresh Is Due- Input
from cycle 23: row 4 column 1, then row 2 column 3; from cycle 72: row 5 column 2, then row 5 column 0
- Output
rules_broken = {}, late = {}, wrong_words = {}, requests = 2
The request arrives around the time a refresh is planned. Both must happen, and the refresh must still come inside its limit of 48 cycles.
Constraints and Contract
- Requests arrive only while ready is 1 and are known 0/1 values. Inputs change while the clock is low.
- Keep the module name and the ports. Any schedule that keeps the rules and the limits is accepted.
Hints
Hint 1
Draw the commands of one request on a time line first: ACTIVATE, READ, the data, then what the second word needs. Write the number of cycles under each gap.
Hint 2
One counter can time every wait. Send the command in the first cycle of a state and leave the state when the counter reaches the wait.
Hint 3
Keep a second counter of the cycles since the last REFRESH. When it reaches a threshold, go not ready and refresh before you take another request. A request that was just taken needs up to 16 cycles, so leave that much room below the limit.
What the grader checks: Twelve directed and ten seeded tests of 160 cycles run against a model of the memory. The model checks tRCD, tRP, tRFC, the single open row and the refresh limit at every edge. The four words are compared with a memory filled from JavaScript. Writes, bursts, several banks and tRAS are outside this problem.
The submitted design must synthesize with 0 latches and no combinational loop. Counts come from the pinned open-source synthesis flow. They are proxies for logic size and depth, not physical area or timing.
22 checks on Icarus Verilog + Yosys · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 2 steps and the final capstone