Forum Discussion
Altera_Forum
Honored Contributor
18 years agoCounter and time delay
Hi, I'm very new in Quartus, I just started a couple of days ago. The situation is that I've 4 inputs (only one of these can be active at time) and every time input changes to another, I n...
Altera_Forum
Honored Contributor
18 years agoHere's the code for counter that works fine. It resets the counter when reset goes from 0 to 1.
always @(posedge clk) begin if (reset) begin if (!oldReset) begin[/INDENT] count <= 0;[/INDENT][/INDENT] end[/INDENT] oldReset <= 1;[/INDENT] //increase counter[/INDENT] if (count_enable) begin[/INDENT] count <= count+1;[/INDENT][/INDENT] end[/INDENT] end else begin oldReset <= 0;[/INDENT] //increase counter[/INDENT] if (count_enable) begin[/INDENT] count <= count+1;[/INDENT][/INDENT] end[/INDENT] end end And here's the code for holding: always @ (posedge clk) begin if (in_pulse) begin counter <= 0; out_pulse <= 1;[/INDENT] end else begin counter <= counter +1; if (counter > 1250) begin[/INDENT] out_pulse <= 0; if (counter > 1000000000) begin[/INDENT][/INDENT] counter <= 1250;[/INDENT][/INDENT][/INDENT] end[/INDENT][/INDENT] end[/INDENT] else begin[/INDENT] out_pulse <= 1;[/INDENT][/INDENT] end[/INDENT] end end