Electronics · Digital logic and timing
Design and test a digital event sequence
A request should start one short sequence: output A for two clock intervals, B for one, then DONE for one. Holding the request high must not repeat it. Turning that sentence into a complete design requires decisions about sampling, memory, reset, ignored inputs and states that the intended path never visits.
Lesson preparation and course links
Use the digital-logic/timing introduction and read 0/1 truth tables. Clocked state, counter meaning, reset priority and wildcard rows are defined here. The request is assumed conditioned and in the clock domain; programming, HDL tools and equipment are not required.
Back to the Electronics chapterAfter reading, you can
Specify a complete synchronous controller with state, a duration counter, reset priority and unused-code behaviour. Derive its expected outputs from pre-edge values and test held, unexpected and reset inputs without requiring programming.
Write the task as a sampling contract
Use an already conditioned 100 Hz rising-edge clock, with period 10.0 ms. Inputs are active-high synchronous reset rst and a clean Boolean request req already in this clock domain. A Boolean value is 0 or 1. Raw button contacts, debouncing and asynchronous clock crossings are separate preparation problems, not properties silently solved by this controller.
One accepted request produces two complete A intervals, one B interval and one DONE interval. These are logic indicators, not direct actuator enables. There is no request queue. The controller accepts a high request only when armed in READY; requests while busy are ignored.
After completion or reset, require a sampled low request before rearming. A request held high through completion or reset therefore cannot start another sequence. A short pulse that never reaches an eligible READY sampling edge can be missed by design; an application that must preserve every event needs a different handshake/storage contract.
At each rising edge, use the current state, old counter and inputs valid around that edge to choose the next stored values. New state/counter and their outputs appear after propagation. The logical table assumes the corresponding setup/hold and clock conditions are satisfied. A raw switch is not the clock used in this model.
Name the stored state, including the counter
Use five named control states: READY, A, B, DONE and WAIT_LOW. Encode them with three state bits as shown below. Add one counter bit c to distinguish the first and second A intervals. In A,c=0 means first interval and A,c=1 means second; every other next state clears c to 0.
Outputs are Moore outputs: their settled values depend on the current control state. A is high only in control state A, B only in B, and DONE only in DONE. They do not depend on req or c in the output decoder. Before a qualified reset edge, state/counter are unspecified; no physical power-on initialization is assumed.
The duration counter is also memory. From reset, the reachable combined states are WAIT_LOW,c0; READY,c0; A,c0; A,c1; B,c0; DONE,c0: six, not five. The chosen three-plus-one-bit encoding has 16 possible bit patterns; the table defines behaviour even for unused/unreachable Boolean patterns.
The diagram expands the two A intervals into separate boxes to make that stored distinction visible. Reset and unused-control-code recovery are stated separately and are completed by the transition table.
| Control name | Code | A | B | DONE |
|---|---|---|---|---|
| READY | 000 | 0 | 0 | 0 |
| A | 001 | 1 | 0 | 0 |
| B | 010 | 0 | 1 | 0 |
| DONE | 011 | 0 | 0 | 1 |
| WAIT_LOW | 100 | 0 | 0 | 0 |
| Unused control codes | 101,110,111 | 0 | 0 | 0 |
Define one next state for every Boolean combination
In the table, “any” includes both Boolean values for an input/counter, or every control code when used in that column. The first row specifies reset priority: if rst=1 at a qualified rising edge, abort the sequence, enter WAIT_LOW and clear c regardless of all other fields. Every remaining row has rst=0.
WAIT_LOW stays put while req=1 and enters READY when req=0 is sampled. READY remains ready with req=0 and accepts req=1 by entering A,c=0. While busy, req is irrelevant to the transition. A,c=0 advances to A,c=1; A,c=1 advances to B,c=0; B advances to DONE; DONE always advances to WAIT_LOW.
Codes 101,110,111 decode all outputs low and recover to WAIT_LOW,c=0 at the next non-reset edge. A low request must still be sampled before restarting. This is logical recovery for the declared Boolean model, not proof of tolerance to arbitrary physical faults.
The four stored bits and two Boolean inputs give 16×2×2=64 combinations. A static relation check confirms exactly one specified transition for each. That coverage check and the supplied expected-row checks are not HDL simulation, synthesis, physical timing closure or formal verification of an implementation.
| rst | Current control | Old c | req | Next control | Next c |
|---|---|---|---|---|---|
| 1 | any | any | any | WAIT_LOW (100) | 0 |
| 0 | WAIT_LOW (100) | any | 0 | READY (000) | 0 |
| 0 | WAIT_LOW (100) | any | 1 | WAIT_LOW (100) | 0 |
| 0 | READY (000) | any | 0 | READY (000) | 0 |
| 0 | READY (000) | any | 1 | A (001) | 0 |
| 0 | A (001) | 0 | any | A (001) | 1 |
| 0 | A (001) | 1 | any | B (010) | 0 |
| 0 | B (010) | any | any | DONE (011) | 0 |
| 0 | DONE (011) | any | any | WAIT_LOW (100) | 0 |
| 0 | 101 | any | any | WAIT_LOW (100) | 0 |
| 0 | 110 | any | any | WAIT_LOW (100) | 0 |
| 0 | 111 | any | any | WAIT_LOW (100) | 0 |
Predict before comparing with the supplied record
The following 23 rows are hand-declared expected logic data. They are not a captured circuit trace or output from an HDL/FPGA tool. “Before” is the stored state/counter immediately before the edge; “after” is the state/counter after propagation. Output columns show settled values A,B,DONE for the interval that follows.
Begin by hiding the after/output columns and applying one transition row at a time. At edge 0, reset with req already high puts the controller in WAIT_LOW. At edge 2, a sampled low rearms READY. The high request at edge 3 then starts A,c=0. This makes the effect of initial reset and release explicit.
Continue beyond the normal path. The record includes a held-high request, a second accepted request at edge 10, reset at edge 12, and changes while busy at edges 16/17. Checking those rows prevents a design that demonstrates one intended sequence while leaving its recovery or input policy undefined.
| Edge | Time ms | rst | req | Before state,c | After state,c | A B DONE |
|---|---|---|---|---|---|---|
| 0 | 0 | 1 | 1 | unknown,c=unknown | WAIT_LOW (100),c=0 | 0 0 0 |
| 1 | 10 | 0 | 1 | WAIT_LOW (100),c=0 | WAIT_LOW (100),c=0 | 0 0 0 |
| 2 | 20 | 0 | 0 | WAIT_LOW (100),c=0 | READY (000),c=0 | 0 0 0 |
| 3 | 30 | 0 | 1 | READY (000),c=0 | A (001),c=0 | 1 0 0 |
| 4 | 40 | 0 | 1 | A (001),c=0 | A (001),c=1 | 1 0 0 |
| 5 | 50 | 0 | 1 | A (001),c=1 | B (010),c=0 | 0 1 0 |
| 6 | 60 | 0 | 1 | B (010),c=0 | DONE (011),c=0 | 0 0 1 |
| 7 | 70 | 0 | 1 | DONE (011),c=0 | WAIT_LOW (100),c=0 | 0 0 0 |
| 8 | 80 | 0 | 1 | WAIT_LOW (100),c=0 | WAIT_LOW (100),c=0 | 0 0 0 |
| 9 | 90 | 0 | 0 | WAIT_LOW (100),c=0 | READY (000),c=0 | 0 0 0 |
| 10 | 100 | 0 | 1 | READY (000),c=0 | A (001),c=0 | 1 0 0 |
| 11 | 110 | 0 | 0 | A (001),c=0 | A (001),c=1 | 1 0 0 |
| 12 | 120 | 1 | 1 | A (001),c=1 | WAIT_LOW (100),c=0 | 0 0 0 |
| 13 | 130 | 0 | 1 | WAIT_LOW (100),c=0 | WAIT_LOW (100),c=0 | 0 0 0 |
| 14 | 140 | 0 | 0 | WAIT_LOW (100),c=0 | READY (000),c=0 | 0 0 0 |
| 15 | 150 | 0 | 1 | READY (000),c=0 | A (001),c=0 | 1 0 0 |
| 16 | 160 | 0 | 0 | A (001),c=0 | A (001),c=1 | 1 0 0 |
| 17 | 170 | 0 | 1 | A (001),c=1 | B (010),c=0 | 0 1 0 |
| 18 | 180 | 0 | 0 | B (010),c=0 | DONE (011),c=0 | 0 0 1 |
| 19 | 190 | 0 | 0 | DONE (011),c=0 | WAIT_LOW (100),c=0 | 0 0 0 |
| 20 | 200 | 0 | 0 | WAIT_LOW (100),c=0 | READY (000),c=0 | 0 0 0 |
| 21 | 210 | 0 | 0 | READY (000),c=0 | READY (000),c=0 | 0 0 0 |
| 22 | 220 | 0 | 1 | READY (000),c=0 | A (001),c=0 | 1 0 0 |
Count full intervals rather than input changes
For the request accepted at edge 3, A is high from the settled state after edge 3 until the transition at edge 5. Those are two nominal clock periods, 20 ms. B is high over edges 5→6 for 10 ms and DONE over 6→7 for 10 ms. The chart shows ideal settled levels and omits propagation windows and decoder glitches.
At edge 4, the pre-edge pair is A,c=0, so the next pair must still be A,c=1. An implementation that increments c first and immediately treats the new 1 as completion could leave A at edge 4, shortening it to one interval. Derive implementation behaviour from the old-state table, not an informal ordering of assignments.
The clock’s nominal 100 Hz is an assumption in this logical task. Actual output widths depend on clock accuracy, jitter and propagation conditions. The table alone does not certify exact pulse widths on a board, and a slow clock does not remove all setup/hold or input-synchronization requirements.
Test reset and requests outside the happy path
Hold req high through edges 3–8 in the supplied record. Busy states complete once, then WAIT_LOW holds at edges 7/8. A sampled low at edge 9 rearms READY, and high at edge 10 accepts a second sequence. The high level itself is not repeatedly queued as an event.
At edge 12, rst=1 dominates the normal A,c=1 transition. State becomes WAIT_LOW,c=0 and all settled outputs are 0; B/DONE do not continue from that aborted sequence. Held-high req at edge 13 cannot restart. A fresh low at edge 14 rearms and high at edge 15 is accepted.
At edge 16 a low req during A is ignored for sequencing; edge 17’s new high is also ignored and is not queued. The old A,c=1 state advances to B. At edge 19, even with req low, DONE still goes to WAIT_LOW; the following sampled low at edge 20 rearms READY.
Because reset is synchronous, asserting it between rising edges does not immediately shut an output down. It must meet the stated sampling requirements at an edge. This logical reset policy does not implement an asynchronous safety shutdown.
Keep unused-code recovery separate from hardware guarantees
As a supplied fault case, set the pre-edge code to 111,c=1 with rst=0 and req=1. The current output decode is all 0. At the next qualified edge the table gives WAIT_LOW,c=0. Keeping req high there holds the controller; a sampled low is required before READY. No physical fault was injected to obtain this expectation.
Settled Moore outputs do not guarantee glitch-free combinational decoding at every instant. For example, the binary control transition 001→010 can briefly pass through a different decoded pattern when bits and gates propagate at different times. An implementation for actuator enables would need a separately derived registered/interlocked output design and its verification.
The Boolean table also does not cover metastable levels, clock glitches, broken storage or missed timing constraints. A future HDL implementation or synthesis tool may recode states or optimize unreachable patterns. Recheck the intended reset/unused-code contract and actual outputs in that implementation instead of treating this paper design as a physical fault-tolerance certificate.
Explain why one held request produces one sequence
Start after a qualified reset with WAIT_LOW,c=0 and req=1. The WAIT_LOW/req 1 row repeats WAIT_LOW, so a request already held at reset is not accepted. A sampled req=0 at edge 2 changes to READY; the req=1 at edge 3 then enters A,c=0.
Use old counter values. Edge 4 sees A,c=0 and enters A,c=1. Edge 5 sees A,c=1 and enters B,c=0. Edge 6 enters DONE and edge 7 enters WAIT_LOW. The A/B/DONE intervals are therefore 20/10/10 ms in the exact ideal-clock/settled-level model.
Because req remains 1, edge 8 stays WAIT_LOW. A low sampled at edge 9 changes to READY, and a later high at edge 10 can start the next sequence. Release and reassertion are part of the contract; there is no automatic repeat from the held level.
Now challenge that explanation with reset or an unused code. Reset takes priority at its qualified edge, and an unused code goes to WAIT_LOW on the next non-reset edge. Both paths require release before acceptance, which prevents an accidental automatic restart in the stated logic model.
Try the reasoning
How many named control states, chosen storage bits and reachable combined states does this design use?
Show the answer and reasoning
Five named control states use three encoding bits, plus one counter bit. That gives four chosen stored bits and 16 possible patterns. From reset there are six reachable state/counter pairs because A,c0 and A,c1 are distinct stored states.
For a request accepted at edge 3, identify the complete A/B/DONE intervals.
Show the answer and reasoning
A covers the two intervals from edge 3 to 5, nominally 20 ms; B covers 5 to 6 for 10 ms; DONE covers 6 to 7 for 10 ms. These are ideal settled-level intervals, excluding propagation windows and any physical decoder glitches.
Why does keeping req high after DONE fail to start a second sequence?
Show the answer and reasoning
DONE goes to WAIT_LOW, and WAIT_LOW requires a sampled req=0 before READY. Busy requests are ignored and not queued. A new eligible high in READY is needed after the sampled release.
At edge 4 the old pair is A,c=0. Why must next state remain A?
Show the answer and reasoning
The complete row says to enter A,c=1 for the second full A interval. Comparing an already incremented counter and immediately leaving A would consume that interval too early. The old state/counter define the transition.
At edge 12, rst=1, req=1 and the old pair is A,c=1. What happens?
Show the answer and reasoning
Reset dominates: enter WAIT_LOW,c=0 with settled outputs all 0. The normal transition to B is aborted, and no B/DONE continuation is specified. Held-high req cannot restart until a fresh sampled low rearms READY.
Does the req rise at edge 17 queue another sequence?
Show the answer and reasoning
No. The old pair is A,c=1, whose next pair is B,c=0 regardless of req. This controller deliberately has no queue. Preserving every event would require another contract and additional storage/handshake.
What is the declared result for unused code 111,c=1, rst=0 and req=1?
Show the answer and reasoning
The current decoder gives all 0 outputs, then the next edge enters WAIT_LOW,c=0. A high req holds it there; a sampled low is required before READY. This is a supplied logical expectation, not an observed hardware fault test.
Does a reset pulse entirely between qualified rising edges guarantee an immediate output shutdown?
Show the answer and reasoning
No. Reset is synchronous and is acted on at a qualifying rising edge. Its assertion between edges is not an asynchronous shutdown. Real sampling/timing and any independent safety mechanism need their own design.
What do the 64-combination table check and 23 expected trace rows establish?
Show the answer and reasoning
They establish coverage/consistency of the declared Boolean transition relation and these hand-specified expectations. They do not establish an HDL implementation, synthesis/netlist preservation, physical timing, glitch-free enables or fault tolerance. No program or hardware run is required for this design exercise.
What to carry forward
Write the sampling contract before implementing a sequence. State includes every stored counter, transitions use pre-edge values, and reset/unused/input policies need explicit rows. Test the intended path and the rejected or aborted paths, then keep logical expectations separate from physical implementation evidence.
References
Sources supporting this lesson’s explanations and examples.