I've got a project that is currently using a ½ second delay to check timing and other things.
The delay uses a ms counter provided by a timer. The delay code is,
Code:
void delay(uint32_t ms){
uint32_t time;
time=tickMs+ms;
while(tickMs<time);
}
tickMs is the interrupt variable.
It works fine most of the time but occasionally the delay is short.
I've got the code lighting an LED and clicking a solenoid.
I find I can hear irregularities much easier than see them.
From startup the short delay is the 5th on cycle which is a count around 9500.
If I set the variable to start at 1000 then the short tick is on the 3rd cycle..
If I set the variable to start at 4096 then the short tick is in the same place (5th cycle).
If I change from delay(500); to __delay_ms(500); then the problem goes away.
I've switched from timer 6 to timer 2.
I've ruled out WDT resets by putting a delay at startup.
I've rewritten the delay code from,
Code:
void delay(uint32_t ms){
uint32_t previous;
previous=tickMs;
while((tickMs-previous)<ms);
}
I'm completely stumped.
Anyone got any idea what may cause this or how to debug it?
Mike.