Build the controller of a serial sender. Its outputs are valid in the first cycle of each state and never move between clock edges.
Hardware context: The controller of a serial sender with load, shift, wait and done states and a bit counter; and a one-hot motor controller with a debug load port on its state register. Build the serial-send controller with registered outputs that arrive with no extra cycle.
A serial sender has a shift register and a controller. The controller tells it when to load a frame, when to shift each bit and when the frame is done. Its outputs go to another block as strobes, so they must hold still for the whole cycle. The first version met that by adding a flop after each output, and every strobe arrived one cycle late.
This is an Implement problem: write tx_ctrl from its brief. Each output must show its value in the first cycle of the state it belongs to, with no extra cycle. And no output may change between two clock edges, whatever the inputs do.
The tests check both. After every rising edge they read the outputs. They invert every input for 1 ns while clk is high, and read the outputs again. They also read the outputs during reset, before any clock edge.
Brief: rising-edge clk; rst_n asynchronous and active-low; the sequence of states is in the specification. start is taken only while idle, and len is read at that edge. ack is taken only while waiting. Synthesis check: the design must build on the site's synthesis flow with no latch. The cell and level counts come from an open-source flow and are a proxy for area and depth, not a foundry result.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
from | 4 | input of each check |
script | 80 | input of each check |
Full specification
module tx_ctrl (
input logic clk,
input logic rst_n, // asynchronous, active-low
input logic start, // send a frame; taken only while ready is 1
input logic [2:0] len, // the frame has len + 1 bits; read when start is taken
input logic ack, // the receiver has the frame; taken only while waiting
output logic ready, // 1 while idle
output logic load, // 1 for the one cycle after start is taken
output logic shift, // 1 for each of the len + 1 shift cycles
output logic done, // 1 for the one cycle after ack is taken
output logic [2:0] bit_idx // the number of the bit being shifted; 0 outside the shift cycles
);
// your design
endmodule
| State | Lasts | Outputs in every cycle of the state | Leaves when |
|---|---|---|---|
| idle | until start is 1 at an edge | ready = 1 | start is taken; len is stored |
| load | 1 cycle | load = 1 | always |
| shift | len + 1 cycles | shift = 1; bit_idx counts 0, 1, ... up to the stored len | bit_idx equals the stored len |
| wait | until ack is 1 at an edge | all outputs 0 | ack is taken |
| done | 1 cycle | done = 1 | always, back to idle |
An output that the table does not name for a state is 0 there. bit_idx is 0 outside the shift state. In reset the controller is idle: ready is 1 and the other outputs are 0, at once, with no clock edge.
| Edge | Inputs before it | Outputs after it |
|---|---|---|
| 0 | start = 1, len = 2 | load = 1 |
| 1, 2, 3 | none | shift = 1 with bit_idx 0, 1, 2 |
| 4 | none | all 0 (waiting) |
| 5 | none | all 0 (waiting) |
| 6 | ack = 1 | done = 1 |
| 7 | none | ready = 1 |
Each test runs a previous life, pulses rst_n low with no clock edge, then applies 16 steps of one edge each. 9 of the steps are recorded. For each one the result holds the five outputs 1 ns after the edge. The field still is 1 if the outputs did not move while every input was inverted.
The synthesis check also reads the netlist. Every bit of ready, load, shift, done and bit_idx must come straight from a flop's Q pin, or the design fails. A gate that decodes one state of the state register can still pass. This flow re-encodes the state one-hot, so that decode becomes a state flop.
Examples
Example 1
Idle After Reset- Input
idle x16; steps 0 to 8 are recorded
- Output
ready_in_reset = yes, ready_0 = yes, load_0 = no, shift_0 = no, done_0 = no, bit_idx_0 = 0, still_0 = yes, ready_1 = yes, load_1 = no, shift_1 = no, done_1 = no, bit_idx_1 = 0, still_1 = yes, ready_2 = yes, load_2 = no, shift_2 = no, done_2 = no, bit_idx_2 = 0, still_2 = yes, ready_3 = yes, load_3 = no, shift_3 = no, done_3 = no, bit_idx_3 = 0, still_3 = yes, ready_4 = yes, load_4 = no, shift_4 = no, done_4 = no, bit_idx_4 = 0, still_4 = yes, ready_5 = yes, load_5 = no, shift_5 = no, done_5 = no, bit_idx_5 = 0, still_5 = yes, ready_6 = yes, load_6 = no, shift_6 = no, done_6 = no, bit_idx_6 = 0, still_6 = yes, ready_7 = yes, load_7 = no, shift_7 = no, done_7 = no, bit_idx_7 = 0, still_7 = yes, ready_8 = yes, load_8 = no, shift_8 = no, done_8 = no, bit_idx_8 = 0, still_8 = yes
A frame was under way before the reset. After it the controller is idle: ready is 1 in reset and at every step, and nothing moves.
Example 2
A Frame of Three Bits- Input
start len=2, idle x5, ack, idle x9; steps 0 to 8 are recorded
- Output
ready_in_reset = yes, ready_0 = no, load_0 = yes, shift_0 = no, done_0 = no, bit_idx_0 = 0, still_0 = yes, ready_1 = no, load_1 = no, shift_1 = yes, done_1 = no, bit_idx_1 = 0, still_1 = yes, ready_2 = no, load_2 = no, shift_2 = yes, done_2 = no, bit_idx_2 = 1, still_2 = yes, ready_3 = no, load_3 = no, shift_3 = yes, done_3 = no, bit_idx_3 = 2, still_3 = yes, ready_4 = no, load_4 = no, shift_4 = no, done_4 = no, bit_idx_4 = 0, still_4 = yes, ready_5 = no, load_5 = no, shift_5 = no, done_5 = no, bit_idx_5 = 0, still_5 = yes, ready_6 = no, load_6 = no, shift_6 = no, done_6 = yes, bit_idx_6 = 0, still_6 = yes, ready_7 = yes, load_7 = no, shift_7 = no, done_7 = no, bit_idx_7 = 0, still_7 = yes, ready_8 = yes, load_8 = no, shift_8 = no, done_8 = no, bit_idx_8 = 0, still_8 = yes
start with len 2 gives load, then shift with bit_idx 0, 1 and 2. Two waiting cycles follow, then done after ack, then ready.
Example 3
A Frame of One Bit- Input
start len=0, idle, ack x3, idle x11; steps 0 to 8 are recorded
- Output
ready_in_reset = yes, ready_0 = no, load_0 = yes, shift_0 = no, done_0 = no, bit_idx_0 = 0, still_0 = yes, ready_1 = no, load_1 = no, shift_1 = yes, done_1 = no, bit_idx_1 = 0, still_1 = yes, ready_2 = no, load_2 = no, shift_2 = no, done_2 = no, bit_idx_2 = 0, still_2 = yes, ready_3 = no, load_3 = no, shift_3 = no, done_3 = yes, bit_idx_3 = 0, still_3 = yes, ready_4 = yes, load_4 = no, shift_4 = no, done_4 = no, bit_idx_4 = 0, still_4 = yes, ready_5 = yes, load_5 = no, shift_5 = no, done_5 = no, bit_idx_5 = 0, still_5 = yes, ready_6 = yes, load_6 = no, shift_6 = no, done_6 = no, bit_idx_6 = 0, still_6 = yes, ready_7 = yes, load_7 = no, shift_7 = no, done_7 = no, bit_idx_7 = 0, still_7 = yes, ready_8 = yes, load_8 = no, shift_8 = no, done_8 = no, bit_idx_8 = 0, still_8 = yes
len 0 gives one shift cycle with bit_idx 0. ack is held for three steps: the first is taken, and the later ones find the controller idle.
Constraints and Contract
- Inputs are known 0/1 values. Between two edges they may change at any time.
- Keep the module name and the ports. Internal names are yours.
Hints
Hint 1
Write the next-state logic as its own combinational block first, with a next value for the bit index beside it.
Hint 2
An output flop that loads a decode of the present state is one cycle late. What is known before the edge that tells you the state after it?
Hint 3
Load every output flop from the next state at the same edge as the state register. Give each one its reset value: ready is 1 in reset.
What the grader checks: Eight directed and ten seeded scripts of sixteen edges run after a previous life and a reset pulse. The outputs after nine of the edges are compared with an independent model. Every input is inverted between edges to catch a gate path from the inputs. The synthesis check requires every output bit to be driven straight by a flop in the netlist. A three-procedure version that decodes single states of state_q still passes. This flow re-encodes the state one-hot, so each decode is a state flop.
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.
18 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