Forum Discussion
Altera_Forum
Honored Contributor
17 years agoCounter Problems
Hi, im trying to implement a counter which counts positive, negative, or both edges of an incoming signal. It works, but if I give 10000pulses to it it counts only between 9980...9997. The interna...
Altera_Forum
Honored Contributor
17 years agoYour code is too nested and complicated...
the following idea of counting may help
signal count : signed(32 downto 0);
signal temp : signed(1 downto 0);
process(reset,clk)
begin
if reset = '1' then
in_signal_d <= '0';
temp <= "00";
count <= (others => '0');
elsif rising_edge(clk) then
in_signal_d <= in_signal; -- your incoming signal
if count_up = '1' then
temp <= "01"; -- +1
else
temp <= "11"; -- -1
end if;
if in_signal /= in_signal_d then -- either edge
count <= count + temp;
end if;
end if;
end process;
cnt <= std_logic_vector(count);