This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Configuring a one-shot timer in TI-RTOS

I'm just finished the Introduction to the TI-RTOS class and I'm trying to apply what I learned about period clock interrupts to a one-shot timer.  I plan to use the one-shot timer to debounce switch inputs received from a GPIO port.  The idea is that I'll clear the GPIO interrupt once the one-shot timer has expired.  And I'll reuse the same timer whenever I receive the another GPIO interrupt on the same port.

I'm using a TM4C1294XL (Connected Launchpad) with Code Composer Studio Version: 6.0.0.00190 and TI RTOS 2.00.01.23.  I pulled my starter code from the "gpiointerrupt" example in the tirtos_tivac_2_00_01_23_examples folder.

I've attached my gpiointerrupt.c and gpiointerrupt.cfg file for info.  These are the only two files changed with respect to TI's "gpiointerrupt" example.  I also attached the EK-TM4C1294XLC.c file that was provided in the example.

7875.gpiointerrupt.c

7128.gpiointerrupt.cfg

0676.EK_TM4C1294XL.c

In the cfg file, I have attempted to set-up a timer (called debounce_timer) with a 10 ms time-out, at which point an ISR function (called debounceFxn) is to be called. 

The problem is that my ISR function is never being called and therefore I never clear the GPIO interrupt.  My timer's start mode is "timer will be started by user".  To start the timer, I'm using "Timer_start(debounce_timer)" within the callback function (called gpioButtonFxn1) that is kicked-off the the receipt of the GPIO switch input.

Any ideas on what I'm doing wrong?  Any help would be greatly appreciated!

  • Hi James,

    In the GPIO callback, you need to start the timer. Since you want to use a multiple of 1ms, you can use a one-shot clock function instead. I'm attaching an example of the debounce logic in the gpioInterrupt example. I created the one-shot timers in main() to make it obvious what is going on. (These could have been created statically also in the .cfg file...note, I had to enable a heap in the .cfg file since create allocates memory).

    So when the callback interrupt runs, it starts the one-shot clock. This way the last edge is the only one counted. Note: you don't need to stop and then start...the logic in the Clock_start handles this case. After 10ms from the last edge, the Clock function runs and increments the count and toggles the LED. I created 2 one-shot clocks functions. One handles toggling LED0 and the other does LED1. Using the Clock_setFxn and the arg variable, it can be done with only 1 one-shot clock function.

    I also enabled Swi in the .cfg file (I commented out //BIOS.swiEnabled = false;). The Clock module uses a Swi to run your Clock functions.

    8640.gpiointerrupt.cfg

    3808.gpiointerrupt.c

    Todd 

  • Todd,

    You solved my problem!  And I like your design approach better than what I was attempting.

    Keeping the two timers in place was very helpful in enabling me to A/B-compare different time-out values using the two Connected Launchpad user switches.  I ended up settling on 180 ms.  Seems like a lot, but the delay is not noticeable in my application and single-press/single-event switch presses are very reliable now.

    Next, I'll integrate my own external momentary switches and tweak the time-out for them.

    Thanks,

    James