2014-10-31 08:29 AM
Hello.
How to insert precision delay with timer or systick?For example, 100 ns or 1 us.Best regards,CH2014-10-31 09:10 AM
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¤tviews=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=24392015-10-11 04:58 AM
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?2015-10-11 08:47 AM
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.2015-10-11 09:55 AM
Ok, so, how can I make a correct us delay?
2015-10-11 10:12 AM
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.2015-10-11 11:34 AM
Thanks, I'll check it!