Forum Discussion
Altera_Forum
Honored Contributor
9 years agopulse counting
Hello, I'd like to code a pulse counter : after X pulses from a signal, another signal toggles (I choose 4 in my example). I wrote this piece of code, and the behavior is not as i expected...
Altera_Forum
Honored Contributor
9 years agoThen just do a rising edge detection circuit on the pulse, and count 4 of them.
Rising edge detect compars the current value with the last value:
process(clk)
begin
if rising_edge(clk) then
pulse_r <= pulse;
if pulse_r = '0' and pulse = '1' then
toggle_cnt <= toggle_cnt + 1;
end if;
if toggle_cnt = 3 then
toggle_cnt <= 0;
toggle <= not toggle;
end if;
end if;
end process;