题解 | #根据状态转移写状态机-二段式#
根据状态转移写状态机-二段式
https://www.nowcoder.com/practice/5b2ff27610d04993ae92374d51bfc2e6
这道的答案错了 ,能通过的都不是这道题目(状态转移图所描述的时序路逻辑)的正确答案
相信通过验证的答案 描述的都是下面这个状态转移图的逻辑(随手画的 勿喷)
大家大可尝试用三段式mealy写一下下面这个逻辑 就知道答案和题目是不匹配的
具体为什么这么多人理解错,还望大家认真思考
能通过检测的答案我就不发了,因为讨论区的都能通过
下面是题目本身时序图对应的答案(是通不过验证的):
`timescale 1ns/1ns module fsm2( input wire clk , input wire rst , input wire data , output reg flag ); //*************code***********// reg [2:0] c_state,n_state; parameter s0=3'b000,s1=3'b001,s2=3'b010,s3=3'b011,s4=3'b100; always @(posedge clk or negedge rst) begin if(!rst) begin c_state<=s0; end else begin c_state<=n_state; end end always @* begin case(c_state) s0:n_state=(data)?s1:s0; s1:n_state=(data)?s2:s1; s2:n_state=(data)?s3:s2; s3:n_state=(data)?s4:s3; s4:n_state=(data)?s1:s0; default:n_state=s0; endcase end always @(posedge clk or negedge rst) begin if(!rst) begin flag<=0; end else begin flag<=(c_state==s4)?1:0; end end //*************code***********// endmodule