Design the next-state equations of a counter that steps 0, 3, 5, 6, so that every unused state finds its way back.
Hardware context: A countdown timer's 4-bit down counter built from T flip-flop cells, and a sequencer with no reset that steps 0, 3, 5, 6. Design next-state equations for a 0, 3, 5, 6 counter that never locks up.
A sequencer must visit the states 0, 3, 5 and 6 and repeat. It has no reset: after power-up, or after a noise hit, it can be in any of the eight states. It must never get stuck outside its sequence.
This is an Implement problem. Complete seq0356 with three D flip-flops: q is the state register. Write the next-state logic as equations from K-maps. Tables, case, if, ?:, arithmetic and shifts are refused before simulation.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
start | 3 | input of each check |
Full specification
module seq0356 (
input logic clk,
output logic [2:0] q // the state itself: q is the register, written in always_ff
);
...
endmodule
| Present state | Next state |
|---|---|
| 0 | 3 |
| 3 | 5 |
| 5 | 6 |
| 6 | 0 |
| 1, 2, 4 or 7 (unused) | any of 0, 3, 5, 6: you choose, but it must be one of them |
The bench loads a start state straight into q between edges, so q must be the register itself. A start in the sequence must follow it exactly. An unused start must enter the sequence at the first edge, then follow it.
Examples
Example 1
Start at 0- Input
start state 0
- Output
q_after_edge1 = 3, q_after_edge2 = 5, q_after_edge3 = 6, q_after_edge4 = 0, q_after_edge5 = 3, q_after_edge6 = 5, q_after_edge7 = 6, q_after_edge8 = 0, entered_the_sequence_at_edge1 = yes, edge2_took_the_next_state = yes, edge3_took_the_next_state = yes, edge4_took_the_next_state = yes, edge5_took_the_next_state = yes, edge6_took_the_next_state = yes, edge7_took_the_next_state = yes, edge8_took_the_next_state = yes
From 0 the counter must go 3, 5, 6, 0, 3, 5, 6, 0.
Example 2
Start at 5- Input
start state 5
- Output
q_after_edge1 = 6, q_after_edge2 = 0, q_after_edge3 = 3, q_after_edge4 = 5, q_after_edge5 = 6, q_after_edge6 = 0, q_after_edge7 = 3, q_after_edge8 = 5, entered_the_sequence_at_edge1 = yes, edge2_took_the_next_state = yes, edge3_took_the_next_state = yes, edge4_took_the_next_state = yes, edge5_took_the_next_state = yes, edge6_took_the_next_state = yes, edge7_took_the_next_state = yes, edge8_took_the_next_state = yes
The same loop, entered at 5: 6, 0, 3, 5, and so on.
Example 3
Start in Unused State 1- Input
start state 1 (unused)
- Output
q_after_edge1 = 0, q_after_edge2 = 0, q_after_edge3 = 0, q_after_edge4 = 0, q_after_edge5 = 0, q_after_edge6 = 0, q_after_edge7 = 0, q_after_edge8 = 0, entered_the_sequence_at_edge1 = yes, edge2_took_the_next_state = yes, edge3_took_the_next_state = yes, edge4_took_the_next_state = yes, edge5_took_the_next_state = yes, edge6_took_the_next_state = yes, edge7_took_the_next_state = yes, edge8_took_the_next_state = yes
From 1 the first edge may go to any of 0, 3, 5 or 6, your choice. After that each edge must take the next state of the loop. The result shows only these checks for an unused start.
Constraints and Contract
- Keep the module name and the port. Assign q in one always_ff block.
- No case, casez, casex, if or ?: anywhere in the module. No +, -, *, /, %, > or shifts right, and no number other than the bit numbers 0, 1 and 2.
Hints
Hint 1
Write the state table with three next-state columns, one per flip-flop. With D flip-flops, D is the next state itself.
Hint 2
Try the unused states as don't-cares first. Then work out where each unused state goes. Do they reach 0, 3, 5 or 6?
Hint 3
If they chase each other, give up some don't-cares: pick a next state for each unused state and minimize again.
What the grader checks: All eight start states, loaded straight into q. A start in the sequence is compared with the sequence after each of eight edges. An unused start must enter the sequence at the first edge and then take the next state at each later edge. Source rule: no case, if, ?:, arithmetic or right shift. No number but 0, 1 and 2, so no table of constants. Synthesis must report no latches.
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.
8 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