FSM通常情况下使用异步信号进行复位,如FSM1中的rst_n信号。当rst_n信号为低时,FSM进入空闲状态IDLE。
在某些特殊情况下有可能需要跟随某个外部信号强制切换到空闲状态,也即同步复位。下面给出了两种同步复位的写法,请各位指教。
如果有什么更好的实现方法,还望不吝赐教。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 |
//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 |
关于有限状态机FSM同步复位的问题,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/hujianhua/p/3735272.html