cancel
Showing results for 
Search instead for 
Did you mean: 

how to use systick timer to set flag every 40ms

JBonn
Associate III
 
3 REPLIES 3

Count in SysTick_Handler, perhaps have a simple dispatch engine?

static unsigned count = 0;

count++;

if (count == 40)

{

count = 0;

flag |= 1;

}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Piranha
Chief II

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

Pavel A.
Evangelist III

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;
}