1、题目Consider a finite state machine with inputssandw. Assume that the FSM begins in a reset state calledA, as depicted below. The FSM remains in stateAas long ass 0, and it moves to stateBwhens 1. Once in stateBthe FSM examines the value of the inputwin the next three clock cycles. Ifw 1 in exactly two of these clock cycles, then the FSM has to set an outputzto 1 in the following clock cycle. Otherwisezhas to be 0. The FSM continues checkingwfor the next three clock cycles, and so on. The timing diagram below illustrates the required values ofzfor different values ofw.Use as few states as possible. Note that thesinput is used only in stateA, so you need to consider just thewinput.2、分析s0,进入号状态As1进入状态B接着观察三个时钟周期内w为1的个数如果三个时钟周期内刚好有2个w为1则在第四个时钟周期将z拉高其它时候z0.故可以四种状态A复位状态B第一个wC第二个wD第三个w第三个w结束后从第一个w开始三个时钟周期3、代码module top_module ( input clk, input reset, // Synchronous reset input s, input w, output z ); parameter A0,B1,C2,D3; reg [2:0]state,next_state; reg [2:0]cnt;//计算有多少个w为1 always(posedge clk)begin if(reset) stateA; else statenext_state; end always(*)begin case(state) A:next_states?B:A; B:next_stateC; C:next_stateD; D:next_stateB; default:next_stateA; endcase end always(posedge clk)begin if(reset) cnt3d0; else begin case(state) A:cnt3d0; B:cntw; C:cntcntw; D:cntcntw; default:cnt3d0; endcase end end assign z(stateBcnt2); endmodule