2014-06-29 01:04 AM
hi guys i have discovery board (stm32f407) and in my code i have some tasks which have to execute in specific time . so i have to have a accuratedelay , i used to use this :
void
Delay(__IO uint32_t nCount)
{
while
(nCount--)
{
}
}
but i think it's not accurate , i need a function to specify this by millisecond.
can you explain how many methods is there to do that and make an example ??
thank
2014-06-29 03:32 AM
Well there are a lot of reasons it can be unpredictable, like interrupts and cache (tight loops probably not so much). To generate exact timing one should try to use hardware.
To make a spin loop more predictable consider using a free running counter, like DWT_CYCCNT Pass in clock ticks in processor clocks. 1 second = SystemCoreClock, 1 ms =SystemCoreClock / 1000, ideally using a constant You might want to calibrate the loop finely as it acts more like f(x) = mx + c