G7.3.3 Equations from a Transition List

MediumImplementIcarus · browser samples / server checksReview the topic

Write the next-state equations of a two-step lock straight from its transition list, so that the unused code goes back to S0.

Hardware context: A snack machine that sells a 20-cent item with change, and a washing-machine controller built from two JK flip-flops. Write a lock's next-state equations from its transition list, safe from its unused code.

A cabinet lock opens after button a and then button b. Its designer handed over a transition list, not a state table, and asked for equations that are safe after an upset.

This is an Implement problem. Write d1 and d0 as equations from the list. case, if and ?: are refused, so a table in code is not accepted.

The check runs streams of a and b and compares q and open_ with a model in every cycle. Some streams force the unused code 11 into q between edges.

Signals in the Timeline

SignalWidthRole
script32input of each check
Full specification
The module (keep the name and the ports)
module lock2 (
  input  logic       clk,
  input  logic       rst,    // synchronous reset, active high: S0
  input  logic       a,
  input  logic       b,
  output logic [1:0] q,      // the state register: S0 = 00, S1 = 01, S2 = 10 (open); 11 is unused
  output logic       open_   // 1 in S2 only
);
  ...
endmodule
FromConditionTo
S0 (00)aS1 (01)
S0 (00)a'S0 (00)
S1 (01)bS2 (10)
S1 (01)a b'S1 (01)
S1 (01)a' b'S0 (00)
S2 (10)aS2 (10)
S2 (10)a'S0 (00)
RuleDetail
Unused code11 must go to S0 (00) at the next edge, whatever a and b are.
Samplinga and b are set at the start of a cycle and seen at the edge that ends it. q and open_ are read in the middle.
Refusedcase, casez, casex, if and the ?: operator.

Examples

Example 1

A, Then b
Input
ab per cycle: 10 01 10 10 10 10 00 00 00 00 00 00 00 00 00 00
Output
q_cycle0 = S0 (0), open_cycle0 = no, q_cycle1 = S1 (1), open_cycle1 = no, q_cycle2 = S2 (2), open_cycle2 = yes, q_cycle3 = S2 (2), open_cycle3 = yes, q_cycle4 = S2 (2), open_cycle4 = yes, q_cycle5 = S2 (2), open_cycle5 = yes, q_cycle6 = S2 (2), open_cycle6 = yes, q_cycle7 = S0 (0), open_cycle7 = no, q_cycle8 = S0 (0), open_cycle8 = no, q_cycle9 = S0 (0), open_cycle9 = no, q_cycle10 = S0 (0), open_cycle10 = no, q_cycle11 = S0 (0), open_cycle11 = no, q_cycle12 = S0 (0), open_cycle12 = no, q_cycle13 = S0 (0), open_cycle13 = no, q_cycle14 = S0 (0), open_cycle14 = no, q_cycle15 = S0 (0), open_cycle15 = no

a takes S0 to S1. b then takes S1 to S2, where open_ = 1. S2 holds while a = 1 and falls back to S0 when a falls.

Example 2

A Held Without b
Input
ab per cycle: 10 10 10 10 01 00 00 00 00 00 00 00 00 00 00 00
Output
q_cycle0 = S0 (0), open_cycle0 = no, q_cycle1 = S1 (1), open_cycle1 = no, q_cycle2 = S1 (1), open_cycle2 = no, q_cycle3 = S1 (1), open_cycle3 = no, q_cycle4 = S1 (1), open_cycle4 = no, q_cycle5 = S2 (2), open_cycle5 = yes, q_cycle6 = S0 (0), open_cycle6 = no, q_cycle7 = S0 (0), open_cycle7 = no, q_cycle8 = S0 (0), open_cycle8 = no, q_cycle9 = S0 (0), open_cycle9 = no, q_cycle10 = S0 (0), open_cycle10 = no, q_cycle11 = S0 (0), open_cycle11 = no, q_cycle12 = S0 (0), open_cycle12 = no, q_cycle13 = S0 (0), open_cycle13 = no, q_cycle14 = S0 (0), open_cycle14 = no, q_cycle15 = S0 (0), open_cycle15 = no

S1 holds while a = 1 and b = 0: that is the line S1, a b' to S1. Without that line, S1 would fall back to S0.

Example 3

An Upset to 11 with a = 1 and b = 0
Input
ab per cycle: 10 10 10 10 10 10 00 00 00 00 00 00 00 00 00 00; 11 forced in cycle 2
Output
q_cycle0 = S0 (0), open_cycle0 = no, q_cycle1 = S1 (1), open_cycle1 = no, q_cycle2 = unused 11 (3), open_cycle2 = no, q_cycle3 = S0 (0), open_cycle3 = no, q_cycle4 = S1 (1), open_cycle4 = no, q_cycle5 = S1 (1), open_cycle5 = no, q_cycle6 = S1 (1), open_cycle6 = no, q_cycle7 = S0 (0), open_cycle7 = no, q_cycle8 = S0 (0), open_cycle8 = no, q_cycle9 = S0 (0), open_cycle9 = no, q_cycle10 = S0 (0), open_cycle10 = no, q_cycle11 = S0 (0), open_cycle11 = no, q_cycle12 = S0 (0), open_cycle12 = no, q_cycle13 = S0 (0), open_cycle13 = no, q_cycle14 = S0 (0), open_cycle14 = no, q_cycle15 = S0 (0), open_cycle15 = no

The bench forces 11 into q in cycle 2. The next edge must load 00, then a takes the lock to S1 again.

Constraints and Contract

  • All inputs are known 0/1 values and change only between edges.
  • Keep the module name and the ports. q is the state register: keep it in the always_ff, so the bench can force it.

Hints

Hint 1

A line adds a term to d1 only when its next code has q1 = 1. Lines into S0 add no term at all.

Hint 2

Write each term with the full present code, both state bits, ANDed with the line's condition.

Hint 3

Check 11 by hand: if every term needs q1' or q0', no term is 1 there and the next code is 00.

What the grader checks: Nine directed and ten seeded streams of 16 cycles after a reset. Several force the unused code 11, or a legal code, into q between edges. In every cycle q and open_ are compared with a JavaScript model of the transition list. case, if and ?: are refused before simulation.

19 checks on Icarus · browser samples / server checks. 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 3 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

A, Then b

Input
ab per cycle: 10 01 10 10 10 10 00 00 00 00 00 00 00 00 00 00
Expected output
q_cycle0 = S0 (0), open_cycle0 = no, q_cycle1 = S1 (1), open_cycle1 = no, q_cycle2 = S2 (2), open_cycle2 = yes, q_cycle3 = S2 (2), open_cycle3 = yes, q_cycle4 = S2 (2), open_cycle4 = yes, q_cycle5 = S2 (2), open_cycle5 = yes, q_cycle6 = S2 (2), open_cycle6 = yes, q_cycle7 = S0 (0), open_cycle7 = no, q_cycle8 = S0 (0), open_cycle8 = no, q_cycle9 = S0 (0), open_cycle9 = no, q_cycle10 = S0 (0), open_cycle10 = no, q_cycle11 = S0 (0), open_cycle11 = no, q_cycle12 = S0 (0), open_cycle12 = no, q_cycle13 = S0 (0), open_cycle13 = no, q_cycle14 = S0 (0), open_cycle14 = no, q_cycle15 = S0 (0), open_cycle15 = no

a takes S0 to S1. b then takes S1 to S2, where open_ = 1. S2 holds while a = 1 and falls back to S0 when a falls.

Run samples executes all 3 public checks. Check all tests runs 19 checks on the server.

Icarus · browser samples / server checks