How to include time delay in synthesized verilog?

折月煮酒 提交于 2019-12-06 15:06:00

For switching the states after a time delay,I hope this code helps.

current_state=state_1;
for(i=0;i<=timedelay*freq;i=i+1)
@posedge;
current_state=state_2;

If you know your clock frequency is x Hz, and you want to wait y seconds, then simply use a counter and wait until you reach the number x*y.

e.g. for a clock of 1kHz and a delay of 3 seconds this code will trigger do_something after the time delay.

`define CLOCK_FREQ 1000
`define TIME_DELAY 3

reg [31:0] count=0;

assign do_something = (count==`CLOCK_FREQ*`TIME_DELAY);

always @(posedge clk)
begin
   count <= count + 1'b1;
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!