← ProblemsCircuits / Sequential Logic / Finite State Machines
FSM from a spec: f and g
5%fsmfsm-designDesign an FSM with inputs x and y and outputs f and g, controlled by a synchronous, active-low reset resetn. The required behaviour, in order:
- While
resetn = 0(at clock edges), the machine sits in an initial state withf = 0andg = 0. - In the first clock cycle after
resetnis released (i.e., the cycle following the first rising edge at whichresetn = 1), assertf = 1for exactly one cycle.fis 0 at all other times. - Starting in the cycle after the
fpulse, monitorx: the machine searches for the patternx = 1, 0, 1in three successive cycles. While searching, track the longest useful prefix: a 1 always counts as a (possibly new) first bit; after1, 0, a 0 means the search restarts from nothing. - In the cycle immediately after the pattern
1, 0, 1completes, setg = 1. - With
gnow 1, examineyfor at most two clock cycles (the first two cycles in whichg = 1). Ify = 1in either of those cycles, keepg = 1permanently (until reset). Ifywas 0 in both, setg = 0permanently (until reset).
Equivalently, as a transition table (outputs are Moore-style: f = 1 only in FPULSE, g = 1 only in G1, G2, and GON):
| State | Meaning | Next state |
|---|---|---|
| IDLE | held by reset | FPULSE |
| FPULSE | f = 1 this cycle | SEEK0 |
| SEEK0 | no prefix of 101 yet | x ? SEEK1 : SEEK0 |
| SEEK1 | seen 1 | x ? SEEK1 : SEEK10 |
| SEEK10 | seen 1,0 | x ? G1 : SEEK0 |
| G1 | first g = 1 cycle | y ? GON : G2 |
| G2 | second g = 1 cycle | y ? GON : GOFF |
| GON | g = 1 forever | GON |
| GOFF | g = 0 forever | GOFF |