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. http://www.alteraforum.com/forum/attachment.php?attachmentid=13204&stc=1pulse_gen : process (clk) -- square generation from a given frequency
begin
if rising_edge (clk) then
if reset = '0' then
pulse_counter <= (others => '0');
pulse_tick <= '0';
pulse_toggle4 <= '0';
else
if ((en_in <= '1')) then
if pulse_counter = max_count then
pulse_counter <= (others => '0');
pulse_tick <= not pulse_tick;
counter_dir <= counter_dir +1;
if ((counter_dir = "00001000")) then -- 8 for 4 pulses
counter_dir <= (others => '0') ;
pulse_toggle4 <= not pulse_toggle4 ;
end if ;
else
pulse_counter <= pulse_counter + 1;
end if;
else
pulse_counter <= (others => '0');
pulse_tick <= '0';
end if;
end if;
end if;
end process pulse_gen;
pulse <= pulse_tick;
toggle4 <= pulse_toggle4; I would be grateful if you could have a look