cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Delay

cool26happy
Associate II
Posted on October 31, 2014 at 16:29

Hello.

How to insert precision delay with timer or systick?

For example, 100 ns or 1 us.

Best regards,

CH
6 REPLIES 6
Posted on October 31, 2014 at 17:10

Placing at 100ns you'd really want to leave to hardware. DWT_CYCCNT can give you the granularity close to that of the processor clock, give or take the loop iteration and calling cycles.

For ~1us you'd be at SystemCoreClock/1000000 ticks

[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/compensating%20latencies%20on%20STM32F4%20interrupts&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=2439]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2Fcompensating%20latencies%20on%20STM32F4%20interrupts&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=2439
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
lac
Associate II
Posted on October 11, 2015 at 13:58

I have an STM32F4 Discovery board, and I use Eclipse with GDB, and I'm trying to setup a us SysTick delay, but if I try to set HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000000 it doesn't work. The last number still works with is the /400000 and then the delay is about 2.505us. If I write directly eg. 168000000/1000000 it works great.

I cannot understand what's wrong? 

Posted on October 11, 2015 at 17:47

I cannot understand what's wrong?

Perhaps you can look at the number involved? Interrupting at 1 MHz does strain practicality, which is why it's better to read a hardware counter, rather than a software one.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
lac
Associate II
Posted on October 11, 2015 at 18:55

Ok, so, how can I make a correct us delay?

Posted on October 11, 2015 at 19:12

Ok, did you actually look at the cited thread? The second post demonstrates the use of a hardware counter to achieve reasonably fine grained delays. It iterates processor cycles. You divide the SystemCoreClock by 1000000 to understand how my cycles occur in One Millionth of a second.

You could also use a 32-bit TIM, in a maximal mode, as the time base.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
lac
Associate II
Posted on October 11, 2015 at 20:34

Thanks, I'll check it!