S
Steffen Koepf
Guest
Hello,
what i need is a counter that counts from a preset value down to 0
with a clock outside of the system clock domain. The counter run
on a Cyclone III, 15 out of 16 of the counters work well, but one
counts much too slow. Here is the relevant part of the code:
-- transfer clock domain, fcntnext is in the system clockdomain
cntrclk: process (clk, rst)
begin
if (rst = '1') then
fcntnext <= '0';
fcnttoggle <= '0';
elsif falling_edge(clk) then
fcntnext <= '0';
if fcnttoggle /= fcounter then
fcnttoggle <= fcnttoggle xor '1';
if fcnttoggle = '1' then
fcntnext <= '1';
end if;
end if;
end if;
end process cntrclk;
delaycounter: process (clk, rst)
begin
if (rst = '1') then
dcntFin <= '0';
dcounter <= (others => '0');
elsif rising_edge(clk) then
if cntr_reload = '1' then
dcntFin <= '0';
-- Load counter with previous stored value
dcounter <= dcounterLoadVal;
elsif dcounter = std_logic_vector(to_unsigned(0, dcounter_bits)) then
dcntFin <= '1';
elsif fcntnext = '1' then
dcounter <= std_logic_vector(unsigned(dcounter) - 1);
end if;
end if;
end process delaycounter;
all signals are std_logic, and dcounter, dcounterLoadVal are std_logic_vector.
The FPGA runs with a system clock (clk) of 100 MHz.
The fcntnext signal is one clock cycle high (from falling_edge to
falling_edge) after every rising clock edge of the fcounter clock.
The fcounter clock is much slower than the system clock (max 1 MHz
with a Duty-Cycle of 50%).
Has anyone advices?
Best regards,
Steffen
what i need is a counter that counts from a preset value down to 0
with a clock outside of the system clock domain. The counter run
on a Cyclone III, 15 out of 16 of the counters work well, but one
counts much too slow. Here is the relevant part of the code:
-- transfer clock domain, fcntnext is in the system clockdomain
cntrclk: process (clk, rst)
begin
if (rst = '1') then
fcntnext <= '0';
fcnttoggle <= '0';
elsif falling_edge(clk) then
fcntnext <= '0';
if fcnttoggle /= fcounter then
fcnttoggle <= fcnttoggle xor '1';
if fcnttoggle = '1' then
fcntnext <= '1';
end if;
end if;
end if;
end process cntrclk;
delaycounter: process (clk, rst)
begin
if (rst = '1') then
dcntFin <= '0';
dcounter <= (others => '0');
elsif rising_edge(clk) then
if cntr_reload = '1' then
dcntFin <= '0';
-- Load counter with previous stored value
dcounter <= dcounterLoadVal;
elsif dcounter = std_logic_vector(to_unsigned(0, dcounter_bits)) then
dcntFin <= '1';
elsif fcntnext = '1' then
dcounter <= std_logic_vector(unsigned(dcounter) - 1);
end if;
end if;
end process delaycounter;
all signals are std_logic, and dcounter, dcounterLoadVal are std_logic_vector.
The FPGA runs with a system clock (clk) of 100 MHz.
The fcntnext signal is one clock cycle high (from falling_edge to
falling_edge) after every rising clock edge of the fcounter clock.
The fcounter clock is much slower than the system clock (max 1 MHz
with a Duty-Cycle of 50%).
Has anyone advices?
Best regards,
Steffen