stop and start timer bug

Anna gravatar image

asked 2017-05-19 14:21:16 +0200

Hi all,

i'm using an app_timer. I need to use three timer for debounce of three button. In my case i have to discriminate the push of three button at same time. When all three buttons has release, my FSM sends an event (ALL_THREE_BUTTON_IS RELEASE).

This is my ButtonHandel:

   static void BUTTON_EventHandler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
       uint32_t err_code;
       BTN_Id_t lIdButton;



   switch (pin)
   {
      case BTN_CENTRAL_PIN:
         lIdButton = BTN_CENTRAL;
         err_code = TIMER_Stop(TIMER_BTN_DEBOUNCE_BUTTON_3);
         err_code = TIMER_Stop(TIMER_BTN_DEBOUNCE_BUTTON_2);
         err_code = TIMER_Stop(TIMER_BTN_DEBOUNCE_BUTTON_1);
         APP_ERROR_CHECK(err_code);
         err_code = TIMER_Start(TIMER_BTN_DEBOUNCE_BUTTON_1,TIMER_DEBOUNCE_DELAY,(void*)lIdButton);   
         APP_ERROR_CHECK(err_code);

         break;

      case BTN_SIDE_1_PIN:
         lIdButton = BTN_SIDE_1;
         err_code = TIMER_Stop(TIMER_BTN_DEBOUNCE_BUTTON_3);
         err_code = TIMER_Stop(TIMER_BTN_DEBOUNCE_BUTTON_2);
         err_code = TIMER_Stop(TIMER_BTN_DEBOUNCE_BUTTON_1);
         APP_ERROR_CHECK(err_code);
         err_code = TIMER_Start(TIMER_BTN_DEBOUNCE_BUTTON_2,TIMER_DEBOUNCE_DELAY,(void*)lIdButton);   
         APP_ERROR_CHECK(err_code);
         break;

      case BTN_SIDE_2_PIN:
         countrelese++;
         lIdButton = BTN_SIDE_2;
         err_code = TIMER_Stop(TIMER_BTN_DEBOUNCE_BUTTON_3);
         err_code = TIMER_Stop(TIMER_BTN_DEBOUNCE_BUTTON_2);
         err_code = TIMER_Stop(TIMER_BTN_DEBOUNCE_BUTTON_1);
         APP_ERROR_CHECK(err_code);
         nrf_delay_ms(10);
         err_code = TIMER_Start(TIMER_BTN_DEBOUNCE_BUTTON_3,TIMER_DEBOUNCE_DELAY,(void*)lIdButton);   
         APP_ERROR_CHECK(err_code);      
         break;

      default:
         break;
   }

}

So when a last button was release, a timer debounce starts and check if all three buttons was release. But sometimes, the callback of this timer debounce not expire. But the err_code = TIMER_Start(TIMER_BTN_DEBOUNCE_BUTTON_3,TIMER_DEBOUNCE_DELAY,(void*)lIdButton); is called, but don't wxpire.

It's possible that app_timer.h library have a bug releated to STOP and START the same Timer?

Thanks, Anna

edit retag flag offensive close delete report spam

Comments

Hi Anna,

Please describe a little bit more on your code. You get into the event when a button is pushed or when it's pressed ?

When do you set ALL_THREE_BUTTON_IS_RELEASE ? What do you have in the timeout handle of each timer ?

Hung Bui ( 2017-05-22 12:09:04 +0200 )editconvert to answer