AnsweredAssumed Answered

LPC4357 GP_CLKIN input singal frequence monitor

Question asked by sky sky on Jun 23, 2017
Latest reply on Jul 30, 2017 by sky sky

i want to use the LPC4357's GP_CLKIN fun--use pin-PF_4 as GP_CLKIN,the singal is Sin-Wave,the frequence is about 17MHZ. I use the Frequency monitor register,but i can not read the input singal frequence.

the code such as :

the PF_4 pin set as gp_clkin:

LPC_SCU->SFSPF_4 = (0 << 7) | (0 << 6) | (1 << 5) | (2 << 3) | 1; //GP_CLKIN

 

loop read some times,as follow:

for(i=0; i<FRE_NUM; i++)
{
fre[i] = freq_measure(4); //GP_CLKIN

for(j=0; j<10000; j++);
}

and then, function freq_measure(),as follow:

 

uint32_t freq_measure(uint32_t clk_sel)
{
volatile uint32_t fcnt, rcnt, fout;

/* Set register values */
LPC_CGU->FREQ_MON &= ~(1 << 23); /* Stop frequency counters */
LPC_CGU->FREQ_MON = (clk_sel << 24) | IRC_CNT; /* RCNT == 511 */
LPC_CGU->FREQ_MON |= (1 << 23); /* Start RCNT and FCNT */

while(LPC_CGU->FREQ_MON & (1 << 23))
{
fcnt = (LPC_CGU->FREQ_MON >> 9) & 0x3FFF;
rcnt = (LPC_CGU->FREQ_MON ) & 0x01FF;
if(fcnt == 0 && rcnt == 0)
{
return (0); /* No input clock present */
}
}

fcnt = (LPC_CGU->FREQ_MON >> 9) & 0x3FFF;
fout = fcnt * (12000000U/IRC_CNT); /* FCNT * (IRC_CLK / RCNT) */

return (fout);
}

 

when i debug,after the measure started,FREQ_MON's MEAS bit don't clear,and fcnt=0 always,but rcnt don't be 0.

the program is loop in the  while(LPC_CGU->FREQ_MON & (1 << 23))

 

So,is ther some initial error?

Outcomes