Skip to main content
mohamad_armoon
Associate III
June 29, 2014
Question

delay introduction and example stm32f407

  • June 29, 2014
  • 1 reply
  • 635 views
Posted on June 29, 2014 at 10:04

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
    This topic has been closed for replies.

    1 reply

    Tesla DeLorean
    Guru
    June 29, 2014
    Posted on June 29, 2014 at 12:32

    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

    https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/compensating%20latencies%20on%20STM32F4%20interrupts&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=2116

    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

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..