关于有限状态机FSM同步复位的问题
FSM通常情况下使用异步信号进行复位,如FSM1中的rst_n信号。当rst_n信号为低时,FSM进入空闲状态IDLE。
在某些特殊情况下有可能需要跟随某个外部信号强制切换到空闲状态,也即同步复位。下面给出了两种同步复位的写法,请各位指教。
如果有什么更好的实现方法,还望不吝赐教。
//FSM1 localparam IDLE = 0, S1 = 1, S2 = 2; always@(posedge clk, negedge rst_n) begin if(!rst_n) cs <= IDLE; else if(reset) cs <= IDLE; else cs <= ns; end always@* begin ns = IDLE; case(cs) IDLE: if(a) ns = S1 else ns = IDLE; S1: if(b) ns = S2 else ns = S1; S2: ns = IDLE; default: ns = IDLE; endcase end //FSM2 localparam IDLE = 0, S1 = 1, S2 = 2; always@(posedge clk, negedge rst_n) begin if(!rst_n) cs <= IDLE; else cs <= ns; end always@* begin ns = IDLE; case(cs) IDLE: if(reset) ns = IDLE; else if(a) ns = S1 else ns = IDLE; S1: if(reset) ns = IDLE; if(b) ns = S2 else ns = S1; S2:if(reset) ns = IDLE; ns = IDLE; default: ns = IDLE; endcase end