Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Measuring Frequency help

I need to measuring a signal frequency

i have a reference frequency of 100 MHz

i used the following code bu it didn't work properly

it counter right at the first but after that it got wrong:

process(n_reset,clk_ref100,clk)

begin

if n_reset='0' then

s_clk_ref100_counter<=(others=>'0');

elsif rising_edge(clk_ref100) then

if s_clk_ref100_counter>=10000 then

s_freq<=s_sys_clk_counter;

s_clk_ref100_counter<=(others=>'0');

else

s_clk_ref100_counter<=s_clk_ref100_counter+1;

end if;

end if;

if n_reset='0' then

s_sys_clk_counter<= (others=>'0');

elsif rising_edge(clk) then

if ((s_freq<=s_sys_clk_counter-5) and (s_sys_clk_counter/=x"000"))

then

s_sys_clk_counter<= (others=>'0');

else

s_sys_clk_counter<=s_sys_clk_counter+1;

end if;

end if;

end process;

Please advice me.

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    how fast is clk? the fact you are samplining a 100MHz counter in another clock domain and vice versa is probably your problem. You will need to transfer the counters across the clock domains safely, either with a double register or a dual clock fifo.