The F09 counter identifies the edge that completes the fourth reading. The sensor panel can now report a result. But can it begin the next batch while the receiver has yet to take this result? A new start clears the count. Starting before delivery would erase the boundary between the two jobs.
First decide which events the collector can accept at each stage. A finite state machine (FSM) stores the current stage in a register. The circuit uses that state to decide whether to act on each input.
Each stage waits for a different event
IDLE waits for start_i. An accepted start clears the previous count and moves the machine into COLLECT. Before that edge the machine is still in IDLE. Even if sample_take_i is already high, this edge only starts the job. The next rising edge is the first possible sample.
COLLECT accepts sample events and holds its progress through idle cycles. When the last-sample event from F09 occurs, the same edge records the fourth sample in the count and moves the machine to REPORT. The collector ignores another start_i during collection and continues the current job.
REPORT waits for report_taken_i, a synchronous event supplied by the receiver in this lesson. The design tracks whether a report is pending and how many samples have completed. Without acceptance the state and count hold. Delivery returns the machine to IDLE. The count stays at four until reset or the next accepted start.
Account for every hold and transition
The phase outputs appear below in the order can_start_o / collecting_o / report_valid_o. They describe the current state. The current phase, its relevant conditions, and reset determine what the registers save at the edge.
| Reset or state before edge | Condition | Phase outputs before | State after | Count after |
|---|---|---|---|---|
rst_ni=0, any state | Ignore other inputs | Decode the pre-edge state | IDLE | Clear |
| IDLE | start_i=0 | 100 | IDLE | Hold |
| IDLE | start_i=1 | 100 | COLLECT | Clear |
| COLLECT | sample_take_i=0 | 010 | COLLECT | Hold |
| COLLECT | Sample event with sample_last=0 | 010 | COLLECT | Add one |
| COLLECT | sample_last=1 | 010 | REPORT | Advance to four |
| REPORT | report_taken_i=0 | 001 | REPORT | Hold |
| REPORT | report_taken_i=1 | 001 | IDLE | Hold |
Reserved RTL encoding 11 | Any inputs | 000 | IDLE | Hold |
All rows after the first assume rst_ni=1. During normal operation the pre-edge count in COLLECT ranges from zero to three. Synchronous reset takes effect in the registers at the rising edge. Until that edge arrives, the decoded phase outputs may still reflect the previous state. Reset blocks starts and sample events. A report also transfers only on an edge where rst_ni && report_valid_o && report_taken_i is true.
How does the next state reach the register?
state_q is the stored state. Combinational logic computes state_d, the next state. The default state_d = state_q holds the current state until a transition condition selects a different value. It also gives the combinational output a value when no event occurs. On a rising edge the register selects either the reset state or state_d. A mux in the diagram shows that choice. Synthesis may use a different logic structure to implement it.
always_comb begin
state_d = state_q;
case (state_q)
IDLE: if (start_job) state_d = COLLECT;
COLLECT: if (sample_last) state_d = REPORT;
REPORT: if (report_taken_i) state_d = IDLE;
default: state_d = IDLE;
endcase
end
always_ff @(posedge clk_i) begin
if (!rst_ni)
state_q <= IDLE;
else
state_q <= state_d;
end
report_valid_o depends only on the current state. It is high in REPORT, which makes it a Moore output. The start action depends on both state and input. The combinational signal start_job follows start_i in IDLE with reset released, and clears the count when the machine starts a job. If exposed on the interface, it would be a Mealy output. The distinction tells us whether a signal depends only on entering a phase or can also change with the current cycle’s inputs.
The fourth sample makes the result available
E1 starts the job. E2 through E7 use the six sample event values from F09, 1, 0, 1, 0, 1, 1. They start an edge later because E1 accepts the start. Before E7 the count is three. With sample_last high, state_d selects REPORT. That edge updates the count to four and the state to REPORT.
| Rising edge | start | sample_take | report_taken | State before → after | Count after | Transfer? |
|---|---|---|---|---|---|---|
| E1 | 1 | 1 | 0 | IDLE → COLLECT | 0 | No |
| E2 | 0 | 1 | 0 | COLLECT → COLLECT | 1 | No |
| E3 | 1 | 0 | 0 | COLLECT → COLLECT | 1 | No |
| E4 | 0 | 1 | 0 | COLLECT → COLLECT | 2 | No |
| E5 | 0 | 0 | 0 | COLLECT → COLLECT | 2 | No |
| E6 | 0 | 1 | 0 | COLLECT → COLLECT | 3 | No |
| E7 | 0 | 1 | 1 | COLLECT → REPORT | 4 | No |
| E8 | 1 | 1 | 0 | REPORT → REPORT | 4 | No |
| E9 | 0 | 0 | 0 | REPORT → REPORT | 4 | No |
| E10 | 1 | 0 | 1 | REPORT → IDLE | 4 | Yes |
The machine ignores the early acceptance indication at E7 because report_valid_o is low before that edge. Before E10, both validity and acceptance are high, so a transfer occurs. After E10, report_valid_o falls as the machine goes back to IDLE. The high start_i at E10 also has no effect. The state before that edge still owns the old report.
Replay the transitions and inspect the synthesized encoding
Download the lab package, extract it on Linux or WSL and run bash run.sh. The directed test in Icarus Verilog 12.0 checks 23 edges. It covers every legal hold and transition, reset coinciding with other events, and a restart that clears the previous count. A deliberately faulty variant leaves REPORT unconditionally. With the same inputs, the test detects the wrong state at E8.
The test also forces the RTL state variable to 2'b11. All three phase outputs are zero. After the test releases the forced value, the next rising edge follows the default transition to IDLE. This result applies to the RTL model. Using the packaged synthesis flow, Yosys 0.33 extracts the FSM and recodes it from two bits to three one-hot bits, with one high bit for each legal state. The synthesized state register now uses different codes. Establishing how it recovers from an illegal value requires examining that netlist or testing it directly.
The run summary, raw waveform, and evidence and SHA-256 hashes are available separately.
Transfer question: what if start arrives during collection?
The current contract ignores start_i in COLLECT. Change it so a start discards the partial job, clears the count on that edge, and stays in COLLECT. Suppose start_i and sample_take_i are both high at E3. Give start priority. How would you change the expected result at E3? How would you test the new completion edge?
Answer
The collector holds one sample before E3. The changed rule clears the count, stays in COLLECT, and discards the concurrent sample. Keeping the original input events from E4 to E7 gives post-edge counts of 1, 1, 2, 3. The machine is still in COLLECT at E7 and no report transfers. Add one sample edge and check that this one enters REPORT. A contract that rejects a new start may also specify a response to the sender and test for it.
F11 defines the receiver interface. Entering REPORT tells us that a result is available. Valid and ready at the same edge tell us when it actually transfers.