Hi,
I'm using the STM32F103ZD.
The TIM2_IRQHandler() interrupt handler decrements a value, checks for zero, if so does some action and (re-) sets this value to 1. So each call to this interrupt handler should execute some action. Also higher priority interrupts are active.
If the program execution fails I see in the debugger that 'value' has decremented through zero to 0xffff and lower. Is this some atomic problem? Or is the interrupt handler somehow re-entered while executing?
// variabele declaration volatile static unsigned short value=1; // timer 2 interrupt handler void TIM2_IRQHandler(void){ // an update event is detected if(TIM2->SR&TIM_SR_UIF){ // clear the update event interrupt flag TIM2->SR&=~TIM_SR_UIF; // decrement some value value--; // value is zero if (!value){ // do something DoSomething(); // preset value value=1; }//if }//if }//TIM2_IRQHandler
Who can help me out? Thanks Henk
The tricky part is that the spuriously lost flag may happen on average very 10 minutes. Or every 10 hours. Maybe even once/month. It's just a question of how often the flags gets set and how often some other flag gets serviced and cleared.
Dices can be dangerous around software, unless the intention is to use Monte Carlo methods to intentionally play with probabilities. In the majority of cases, we want our code to be as predictable as possible. Which means we want determinism.