Unexpected behaviour of while loop
Posted: Sat Apr 07, 2018 7:24 am
When I use such a loop:
Then it behaves as expected. It consumes an integer multiple of CPU ticks of the parameter count. It's 6 times the count.
But if I add something more to this function, then it consumes maybe 10 times the count of CPU ticks, which wouldn't matter. But then there are also additional 320 CPU ticks, which disturb me. And often when there is a while in the code, then it often consumes 320 additional CPU ticks and sometimes not. Does somebody know why and how this may be avoided.
I would like to write an exact delay function, which consumes CPU ticks.
Code: Select all
volatile void ICACHE_RAM_ATTR delay_ticks(uint16_t volatile count) {
while(count--);
}
Then it behaves as expected. It consumes an integer multiple of CPU ticks of the parameter count. It's 6 times the count.
But if I add something more to this function, then it consumes maybe 10 times the count of CPU ticks, which wouldn't matter. But then there are also additional 320 CPU ticks, which disturb me. And often when there is a while in the code, then it often consumes 320 additional CPU ticks and sometimes not. Does somebody know why and how this may be avoided.
I would like to write an exact delay function, which consumes CPU ticks.