SYSCLK
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-11-16 8:00 AM
Posted on November 16, 2013 at 17:00
I read in system_stm32f4xx.c that after reset, sysclk is 168MHz. I want to creat a function delay 1s.
void Delay(void) { uint32_t i; for(i=0; i<0xA037A00; ++i) // A037A00 = 168.000.000 { } }.Who can explain for me: how many machine cycle for ++i and {}if you can, help me creat a function delay.thank for reading!
This discussion is locked. Please start a new topic to ask your question.
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-11-16 8:26 AM
Posted on November 16, 2013 at 17:26
Doesn't it reset to 16 MHz (HSI)? SystemInit() might set it to something else prior to main() being called.
Look at the code the compiler generates (listing or code file, or disassemble it). You might want i as volatile so the optimizer doesn't throw out the code. Using software delay loops like this is a fools choice, you are better to use timers and counter (TIMx, SysTick). If you must dwell in a loop, consider looking at a free running timer, or the core's cycle counter.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Up vote any posts that you find helpful, it shows what's working..
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-11-16 8:36 AM
Posted on November 16, 2013 at 17:36
Dear !
Thank for answer!After each device reset the HSI (16 MHz) is used as system clock source.*----------------------------------------------------------------------------- * SYSCLK(Hz) | 168000000 *----------------------------------------------------------------------------- * HCLK(Hz) | 168000000 *-----------------------------------------------------------------------------I just copy from system_stm32f4xx.c. STM32f4 is new MCU for me. I know if use timer is better than delay by for or while loop. but I want to know exactly. Thanks!Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2013-11-16 10:06 AM
Posted on November 16, 2013 at 19:06 The DWT_CYCCNT is also useful for benchmarking loops and code. If you compare to a value, interrupts and cycle variations (buses, contention, caching) shouldn't materially impact the total delay.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Up vote any posts that you find helpful, it shows what's working..
