← ProblemsCircuits / Sequential Logic / Finite State Machines
FSM: count 1s in 3-cycle windows
5%fsmfsm-designDesign an FSM with two inputs, s and w, and one output z, that behaves as follows:
- After reset the machine is in state A. It stays in A as long as
s = 0. Whens = 1at a clock edge, it moves to state B. (Once in B it never returns to A except by reset —sis ignored from then on.) - In state B the machine examines
wover consecutive, non-overlapping windows of exactly 3 clock cycles. The first window consists of the first three cycles spent in B (i.e., it starts in the cycle after the cycle in whichs = 1was observed). - At the end of each 3-cycle window, if
wwas 1 in exactly two of the three cycles, thenz = 1for one clock cycle — the cycle immediately following the window. Otherwisez = 0in that cycle. - Windows are back-to-back: the cycle in which
zreports the result of one window is simultaneously the first cycle of the next window, and itswvalue counts toward that next window.
reset is synchronous and active-high, returning the machine to state A with z = 0.
You may implement the 3-cycle window with explicit states or with a small position counter plus a ones counter — both are fine as long as the timing above is met exactly.