Hi all,
I am trying to implement routines that allows me to measure frequency of a sine wave. I am trying to read grid frequency. My system clk is 80Mhz and I want to configure timer to run at 5 Mhz, so prescale timer clk by 16 .. I have checked that I an reading zero crossing correctly. My logic is to read timer value every half cycle and reset the counter. but TimerValueGet() is giving me totally off value. below is my code pls let me know if i am configuring timer right.
//
// Timer initi()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // enable peripheral
SysCtlDelay(5);
SysCtlPeripheralReset(SYSCTL_PERIPH_TIMER0);
SysCtlDelay(5);
TimerDisable(TIMER0_BASE, TIMER_A);
TimerConfigure(TIMER0_BASE, TIMER_CFG_A_PERIODIC_UP); // timer A half width and counting up, periodic
TimerPrescaleSet(TIMER0_BASE, TIMER_A , 16 ); // scaling timer in clk to 5 Mhz
TimerLoadSet(TIMER0_BASE,TIMER_A , 0xFFFF );
TimerEnable(TIMER0_BASE, TIMER_A);
}
when I detect zero crossing immediately I read timer value and reset it to run again, this way I can know time period of a half cycle
//
// below is code for reading timer and reset its counter
read_timer_and_reset()
{
timer_value = TimerValueGet(TIMER0_BASE, TIMER_A); // timer_value is my measure of frequency
HWREG(TIMER0_BASE + TIMER_O_TAV) = 0; // resetting counter to zero
}
please correct me if I am wrong in above implementation. Again I have checked my zero crossing it is working very well.
Regards,
IHS