如何在 Verilog FSM 中实现时间延迟
How to implement time delay into Verilog FSM
always @(posedge clock)
case(state)
`STATE0: begin
state <= `STATE1;
// Code here
// Wait 5ms before advancing
end
`STATE1: begin
state <= `STATE2;
// Code here
// Wait 5ns before advancing
end
`STATE2: begin
state <= `STATE0;
// Code here
// Wait 5s before advancing
end
default:begin
state <= `STATE0;
// Code here
end
endcase
end
是否可以在设计中添加等待语句,使其必须等待 x 个时间单位才能进入下一个状态?
我知道它可以在我的测试台中使用 #
手动完成,但我的设计要求在我继续之前需要一定的等待时间。
对于短延迟(几个时钟周期),可能最容易实现几个 "dummy" 状态作为预期状态之间的中介。
对于更长的延迟,使用计数器作为使能信号在状态之间转换:
reg [31:0] count;
always@(posedge clock)
if (SOME RESET) count <=0;
else count <= count + 1;
always @(posedge clock)
//...
STATE_N: if (count == SOME_NUMBER_OF_CYCLES) state <= STATE_NPLUSONE;
else state <= STATE_N;
always @(posedge clock)
case(state)
`STATE0: begin
state <= `STATE1;
// Code here
// Wait 5ms before advancing
end
`STATE1: begin
state <= `STATE2;
// Code here
// Wait 5ns before advancing
end
`STATE2: begin
state <= `STATE0;
// Code here
// Wait 5s before advancing
end
default:begin
state <= `STATE0;
// Code here
end
endcase
end
是否可以在设计中添加等待语句,使其必须等待 x 个时间单位才能进入下一个状态?
我知道它可以在我的测试台中使用 #
手动完成,但我的设计要求在我继续之前需要一定的等待时间。
对于短延迟(几个时钟周期),可能最容易实现几个 "dummy" 状态作为预期状态之间的中介。
对于更长的延迟,使用计数器作为使能信号在状态之间转换:
reg [31:0] count;
always@(posedge clock)
if (SOME RESET) count <=0;
else count <= count + 1;
always @(posedge clock)
//...
STATE_N: if (count == SOME_NUMBER_OF_CYCLES) state <= STATE_NPLUSONE;
else state <= STATE_N;