Systick delay weird behavior. [STM32F103CB] [GNUArmEclipse]
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-12-25 3:51 PM
Posted on December 26, 2015 at 00:51
I am experiencing weird behavior from my systick delay function.
The following code does not work.void delay_ms(int time_ms){ uint32_t time_done = SystemUptime+time_ms; while(SystemUptime < time_done) { }}However this one does:void dummy(void){ asm volatile(''NOP''); asm volatile(''NOP'');}void delay_ms(int time_ms){ uint32_t time_done = SystemUptime+time_ms; while(SystemUptime < time_done) { dummy(); }}If i use only one nop or do the nop without it being in a function it won't work. What am I doing wrong? #systick-stm32-f1
Labels:
- Labels:
-
SysTick
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
‎2015-12-25 4:23 PM
Posted on December 26, 2015 at 01:23
Perhaps optimization, make sure you use volatile variables appropriately, and uint32_t would be a better choice.
Also, a fundamental issue with the comparisons. You need to use the formvolatile uint32_t currenttime; // changed by tick interrupt
void delay(uint32 delaytime)
{
uint32_t starttime = currenttime;
while((currenttime - starttime) < delaytime);
}
as this doesn't fail in the number space wrapping condition
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
‎2015-12-25 4:34 PM
Posted on December 26, 2015 at 01:34
Thank you for your fast reply, now that I think about it not using volatile is most likely the problem. I'll check and report back when I get access to my box again.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2015-12-26 2:39 PM
Posted on December 26, 2015 at 23:39
Using volatile fixed it, my comparison code is working fine now. Thank you.
