Hi!
I'm trying to implement a "split lap timer"-function to count how much time each loop takes to complete. The algorithm is as followed:
I initialized the timer with:
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_INT | SYSCTL_XTAL_16MHZ); //set frequency to 50MHz
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
SysCtlDelay(3);
TimerDisable(TIMER0_BASE,TIMER_A); //Stop timer
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC_UP); //Full-width periodic timer that counts up.
TimerLoadSet(TIMER0_BASE, TIMER_A, 0x098967F); //Max value 9999999
TimerEnable(TIMER0_BASE, TIMER_A); //Start timer
The program goes the following way:
while(1)
{
time = TimerValueGet(TIMER0_BASE, TIMER_A);
retrieve values from sensor
do some calculation
send time and values over serial USB
}
After that, I convert the time values into float and divide them by 50e6. But the time values are far off the real ones. I have taken in account that the timer starts back from 0 after it reaches 9999999.
Has anyone any idea of what I am doing wrong? Thank you for your time!