How to give delay when working gpio toggel?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-04-17 7:16 AM
Hello ,
I am using Standard Peripheral Library with STM32F3VCT6 mcu. I want give delay without using timer of it means want give delay by using RCC clock. Is there any thing by which it can be happen.
Solved! Go to Solution.
- Labels:
-
GPIO-EXTI
-
STM32F3 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-04-17 7:58 AM
RCC won't help you at counting elapsed clock cycles. There are a plenty of different timers on the STM32F3 series, depending on the exact model.
Basic timers, general purpose timers, advanced timer, a high-resolution timer, SysTick timer, DWT cycle counter, or the RTC for longer intervals. Pick one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-04-17 7:58 AM
RCC won't help you at counting elapsed clock cycles. There are a plenty of different timers on the STM32F3 series, depending on the exact model.
Basic timers, general purpose timers, advanced timer, a high-resolution timer, SysTick timer, DWT cycle counter, or the RTC for longer intervals. Pick one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-04-17 1:50 PM
If you want a delay of few microseconds you can use the cycle couter. Example:
bspTsMhzDiv is the MCU sysclk frequeny in MHz (168 if the sysclk is 168MHz)
#pragma GCC push_options
#pragma GCC optimize ("O3")
void bspDelayUs (uint32_t us)
{
volatile uint32_t cycles = (bspTsMhzDiv * us) - 10 ; // Remove some cycles for instructions
volatile uint32_t start = DWT->CYCCNT ;
do
{
} while ((DWT->CYCCNT - start) < cycles) ;
}
#pragma GCC pop_options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-04-27 11:37 PM
The cycles and start variables doesn't need to be volatile, which can potentially limit some optimization. And what's the point of using do-while in place where simple while does the same? :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-04-27 11:53 PM
When implementing a delay loop, you don't want certain optimizations to take place.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-04-28 12:22 AM
Loading and calculation of these variables is an overhead, which has to be minimized. But, if the order of these matters, then start should most likely be loaded first. Thought, as multiplication and subtraction takes constant time, the order doesn't matter as long as the compensation constant is appropriate.
