The complete timer
2%fsmdatapathtimerscountersshift-registersAssemble the complete timer from the pieces you have built: the controller FSM, the 4-bit shift/down-count register, and the modulo-1000 counter.
Operation. reset is synchronous and returns the controller to its search state. Then, repeatedly:
- Search
datafor the serial pattern1101(one bit per clock edge, same partial-match rules as before). - Shift in the delay — the 4 bits immediately following the pattern, MSB-first: the first of those four bits becomes
delay[3], the last becomesdelay[0]. This takes the 4 cycles starting the cycle after the edge that samples the pattern's final1. - Count — assert
countingfor exactly(delay + 1) × 1000clock cycles (sodelay = 0counts 1000 cycles anddelay = 15counts 16000 cycles). - Done — deassert
counting, assertdone, and hold until a clock edge whereack = 1; then return to searching.doneis 0 at all other times.
The count output is the remaining time, and to make grading deterministic its behavior is fully specified. count is the 4-bit shift/down-count register itself, updated at every clock edge by exactly one rule (the current phase decides; a simultaneous reset does not change which rule applies on that edge — it only changes the phase for later cycles):
- During each of the 4 shift cycles: shift left,
dataentering at bit 0 (so it holds the delay once shifting completes). - While
countingis asserted: decrement by 1 exactly on the clock edge that completes each block of 1000 counting cycles — except the edge completing the final block (whencountis already 0) leaves it at 0. Thuscountreadsdelayfor the first 1000 counting cycles,delay − 1for the next 1000, …, and 0 for the final 1000. - At all other times — searching, done, and whenever
resetis asserted — it holds its value.resetnever clears this register; it powers up at 0.
So between a completed count and the next shift-in, count stays at 0; after a reset that interrupts shifting or counting, it simply holds whatever it contained.