Other Parts Discussed in Thread: SYSCONFIG
I am working on a custom board that has a methane sensor that needs to be heated for n seconds before an accurate reading can be taken. To do this I have a 1 second timer running. After the callback has been hit n times a flag is set and readings can be considered valid readings. The issues I am having is that the callback is being called much faster than every 1 second. This timing is a critical part of the system.
The timer is set as a 32 bit timer in the .syscfg. My understanding is that the largest time a 32 bit timer can do is just over 89 seconds (2^32 ticks / 48MHz), so I'm not entirely sure what the issue is. The timer period is well under the limit of the timer.
Initialization of timer:
Timer_Params methaneTimerParams; Timer_Params_init(&methaneTimerParams); //Set the timer parameters methaneTimerParams.period = 1000000; //1 second period methaneTimerParams.periodUnits = Timer_PERIOD_US; methaneTimerParams.timerMode = Timer_CONTINUOUS_CALLBACK; methaneTimerParams.timerCallback = HeaterTimeoutCb;
Trying to debug this I put "uint32_t testCount = Timer_getCount(handle);" at the beginning of the callback function. This was giving wildly inconsistent values, ranging from a few hundred to tens of millions. I would expect this to be a consistent value as it is the first line of the callback function.
Timer callback:
void HeaterTimeoutCb ( Timer_Handle handle, int_fast16_t status ) { uint32_t testCount = Timer_getCount(handle); timerSeconds.secondsWaited++; if (timerSeconds.secondsToWait <= timerSeconds.secondsWaited) { heaterWarmingComplete = true; Timer_stop(handle); } }
There is another timer in this project that controls LED blinking that has the same exact parameters except that its mode is Timer_ONESHOT_CALLBACK. This timer works as expected with the callback being called once a second. I swapped the timer peripheral between the two timers and they still both had their same behaviors.
I am at a loss as to why these two timers behave so differently and why the heating timer is not calling it's callback at the right interval. What could be causing this behavior? Is there something about the Timer_CONTINUOUS_CALLBACK mode that is causing the callback to be called faster than once a second, or is there a deeper issue?
Tim