Skip to main content
Graduate II
April 19, 2022
Question

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?

  • April 19, 2022
  • 2 replies
  • 2060 views

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?

    This topic has been closed for replies.

    2 replies

    Super User
    April 20, 2022

    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.3Author
    Graduate II
    April 20, 2022

    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!