how to use systick timer to set flag every 40ms
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-01-27 12:57 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-01-27 1:05 PM
Count in SysTick_Handler, perhaps have a simple dispatch engine?
static unsigned count = 0;
count++;
if (count == 40)
{
count = 0;
flag |= 1;
}
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-01-27 2:43 PM
Generally this is a job for software timers. Typical RTOS has those integrated, but what astounds me, is the fact, that in a 21st century one still can't find a quality, flexible, small and simple open source C software timer libraries, which can be used with bare metal and cooperative schedulers. Google returns plenty of results, especially for Arduino, but all that I've seen are pretty badly designed and/or implemented. :(
As an example: https://electronics.stackexchange.com/questions/96537/deferred-callback-manager-software-timer-library-for-pic32
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2020-01-27 5:34 PM
A brainless variant, for the <pick your own expletive> ST "HAL" library:
/* This overrides HAL_IncTick somewhere in the library */
extern volatile uint32_t uwTick;
extern HAL_TickFreqTypeDef uwTickFreq; /* time increment per tick, 1 = 1KHz */
volatile int the_flag = 0;
static uint8_t count_to_40 = 0;
void HAL_IncTick(void)
{
if (++count_to_40 == 40) {
the_flag = 1;
count_to_40 = 0; // reset?
}
// Increment the HAL counter, like the default HAL_IncTick()
// Assume uwTickFreq is 1 (1 ms/tick)
uwTick += 1U;
}
