Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)

Measuring Frequency help

Altera_Forum
Honored Contributor II
1,270 Views

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.
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
438 Views

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.

0 Kudos
Altera_Forum
Honored Contributor II
438 Views

I tiried with triple register and it worked 

thanks
0 Kudos
Reply