This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

App timer issues

Hello everyone,

I've got strange behavior coming out of my app timer.

I'm using the timer to periodically turn on or off some LED's and since each LED pattern is different I want to incorporate a counter to set different stages of my pattern.

Now comes the fun part Slight smile

I have set breakpoints on my counter and I see that it increments, but the next time it enters the handler the counter is reset and it is incremented to 1 again.

Other times the upper 8 bits of the variable are set and it doesn't want to count.

static void DeviceLedHandler(void * p_context)
{

    static uint16_t counter = 0;

    counter++;
}

Even if  I declare the counter globally it still shows the same behavior. 

I do have a second app timer running as well but to my knowledge this shouldn't make a difference.

This is my declaration

APP_TIMER_DEF(m_DeviceLeds_timer);


APP_ERROR_CHECK(app_timer_create(&m_DeviceLeds_timer, APP_TIMER_MODE_REPEATED, DeviceLedHandler));
APP_ERROR_CHECK(app_timer_start(m_DeviceLeds_timer, APP_TIMER_TICKS(2.5), NULL));

PCA10056 S140

Anyone got a clue what is going on here?

Parents
  • Hi,

     What SDK version are you using?

    Are you setting the counter to 0 any other place in your code? Could you set a breakpoint right after the program steps out of the handler, is counter reset already then? What priority are you running the module at? Could you try disabling the second timer, does it makes a difference?

    regards

    Jared

  • SDK 15.0.0, sorry I forgot to mention.

    No I do not set the counter to 0 anywhere else, the counter is declared static inside the event handler.

    Disabling the other timer doesn't make a difference. 

    At the end of the handler the value is already reset back to 0.

    I've added breakpoints and screen captures of the action.

    And when the function is called again:

    Even if I declare the counter variable outside of the function it doesn't help.

    For some reason it seems that it doesn't want to store the value even though it is static.

Reply
  • SDK 15.0.0, sorry I forgot to mention.

    No I do not set the counter to 0 anywhere else, the counter is declared static inside the event handler.

    Disabling the other timer doesn't make a difference. 

    At the end of the handler the value is already reset back to 0.

    I've added breakpoints and screen captures of the action.

    And when the function is called again:

    Even if I declare the counter variable outside of the function it doesn't help.

    For some reason it seems that it doesn't want to store the value even though it is static.

Children
Related