2015-07-08 04:50 AM
Does anyone know of a good delay function I could use with my STM32F4. I need delay in miliseconds and microseconds.
#nano-delay() #ns-delay2015-07-08 11:40 AM
Yes, but you can't do the comparison that way. The counter is 32-bit, and it wraps. Every 25.5 seconds at 168 MHz.
You do the delta measurement to compute the elapsed time, and exit when it exceeds that.What units is ''length'' expressed in?2015-07-08 11:44 AM
*DWT_CYCCNT is the equivalent to millis(), but it's unit of counting is several nano-seconds. If you want milliseconds configure a timer with a 1 MHz time base and use TIM2->CNT in place of millis().
unsigned int ontime = (SystemCoreClock/1000)*(unsigned int)length; // length in units of millisecondsComputing endtime and waiting for that is broken logic. It's a common coding error that breaks a lot of systems.2015-07-08 11:51 AM
[DEAD LINK /public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/%5bbug%20report%5d%20Bug%20in%20HAL%20%28SPL%29%20delay%20function&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=1421]https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2Fcortex_mx_stm32%2F%5Bbug%20report%5D%20Bug%20in%20HAL%20%28SPL%29%20delay%20function&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B¤tviews=1421
2015-07-09 03:07 AM
2015-09-23 01:44 PM
Hi Clive1,
In my configurationSystemCoreClock for STM32F4Discovery is 168Mhz.SystemCoreClock/1000000 = 168 (1 us)SystemCoreClock/1000 = 168000 (1 ms)SystemCoreClock/ X = Y (Z ns)What is the maximum number for X? Y=76 is the best number for best ns accuracy. Based on my experiment Z is not linear (with X and Y).I am using AHB1 (150MHz) for GPIO Port B using HAL lib.How does SystemCoreClock, cystic_config(), and ABH1 (GPIO) work together to measure the duration of a logic ''1'' pulse on GPIO Port B:0?How does difference between AHB1 and SystemCoreClock impact the accuracy in timing?My plan is to useHAL_GPIO_ReadPin() but not sure how how the different timing will work together.
Thank you!2015-09-23 01:46 PM
Hi Clive1,
In my configurationSystemCoreClock for STM32F4Discovery is 168Mhz.SystemCoreClock/1000000 = 168 (1 us)SystemCoreClock/1000 = 168000 (1 ms)SystemCoreClock/ X = Y (Z ns)What is the maximum number for X? Y=76 is the best number for best ns accuracy. Based on my experiment Z is not linear (with X and Y).I am using AHB1 (150MHz) for GPIO Port B using HAL lib.How does SystemCoreClock, cystic_config(), and ABH1 (GPIO) work together to measure the duration of a logic ''1'' pulse on GPIO Port B:0?How does difference between AHB1 and SystemCoreClock impact the accuracy in timing?My plan is to useHAL_GPIO_ReadPin() but not sure how how the different timing will work together.
Thank you!2015-09-23 01:49 PM
Hi Clive1,
In my configuration....SystemCoreClock for STM32F4Discovery is 168Mhz.SystemCoreClock/1000000 = 168 (1 us)SystemCoreClock/1000 = 168000 (1 ms)SystemCoreClock/ X = Y (Z ns)What is the maximum number for X? Y=76 is the best number I found for best ns accuracy. Based on my experiment Z is not linear (with X and Y). How do I achieve Z (in ns, us, ms)?I am using AHB1 (150MHz) for GPIO Port B using HAL lib.How does SystemCoreClock, cystic_config(), and ABH1 (GPIO) work together to measure the duration of a logic ''1'' pulse on GPIO Port B:0?How does difference between AHB1 and SystemCoreClock impact the accuracy in timing?My plan is to useHAL_GPIO_ReadPin() but not sure how how the different timing will work together.
Thank you!2015-09-23 01:50 PM
Hi Clive1,
In my configuration....SystemCoreClock for STM32F4Discovery is 168Mhz.SystemCoreClock/1000000 = 168 (1 us)SystemCoreClock/1000 = 168000 (1 ms)SystemCoreClock/ X = Y (Z ns)What is the maximum number for X? Y=76 is the best number I found for best ns accuracy. Based on my experiment Z is not linear (with X and Y). How do I achieve Z (in ns, us, ms)?I am using AHB1 (150MHz) for GPIO Port B using HAL lib.How does SystemCoreClock, cystic_config(), and ABH1 (GPIO) work together to measure the duration of a logic ''1'' pulse on GPIO Port B:0?How does difference between AHB1 and SystemCoreClock impact the accuracy in timing?My plan is to useHAL_GPIO_ReadPin() but not sure how how the different timing will work together.
Thank you!2015-09-23 01:51 PM
Hi Clive1,
In my configuration....SystemCoreClock for STM32F4Discovery is 168Mhz.SystemCoreClock/1000000 = 168 (1 us)SystemCoreClock/1000 = 168000 (1 ms)SystemCoreClock/ X = Y (Z ns)What is the maximum number for X? Y=76 is the best number I found for best ns accuracy. Based on my experiment Z is not linear (with X and Y). How do I achieve Z (in ns, us, ms)?I am using AHB1 (150MHz) for GPIO Port B using HAL lib.How does SystemCoreClock, cystic_config(), and ABH1 (GPIO) work together to measure the duration of a logic ''1'' pulse on GPIO Port B:0?How does difference between AHB1 and SystemCoreClock impact the accuracy in timing?My plan is to useHAL_GPIO_ReadPin() but not sure how how the different timing will work together.
Thank you!2015-09-23 02:09 PM
The forum is throwing all kinds of errors when posting, double check if your post actually succeeded by opening the forum in another tab.
Well you have to watch for it exceeding 32-bits, and doing the math in a way that preserves some of the precision. Could be rounded too, but the loop is going to take a few extra cycles. ticks = (SystemCoreClock * nano) / 1000000000; Not sure what you precise question is, I'm not using HAL, and you can't interrupt at MHz rates.