cancel
Showing results for 
Search instead for 
Did you mean: 

I need to Debounce Buttons with Press-Hold and Double-Tap detection. I'm using freeRTOS. Is it best to use a hardware timer interrupt, software freeRTOS timer or while(1) loop with osDelay(10) calls in a freeRTOS taks?

LMorr.3
Senior II

Using the while(1) with no timer seems like the simplest implementation and does not require a timer. Does using osDelay(10) inside a while(1) use more CPU than using software/hardware timer interrupt?

2 REPLIES 2
KnarfB
Principal III

osDelay is RTOS aware, see https://www.keil.com/pack/doc/CMSIS/RTOS2/html/group__CMSIS__RTOS__Wait.html#gaf6055a51390ef65b6b6edc28bf47322e.

It does not use substantially more CPU cycles than the other methods.

The accuracy of the delay depends on all tasks priorities.

I see no issues with using osDelay for that purpose.

hth

KnarfB

LMorr.3
Senior II

Thanks for the info. I'll use osDelay for now. I'm going with a freeRTOS task with osDelay loop. This frees-up a hardware timer and its interrupt overhead, but still tempted to use a freeRTOS software timer. Not sure if the software timer or osDelay has less overhead. I'm not sure yet what method is best, and will try to weigh pros/cons. Might be splitting hairs but the fewer CPU cycles the better!