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

Question about stopping all the timers that are used in the application.

Hi Everyone

I have got 3 timers in my application. 

1 is repeated , and other two are Single shot which are ran from the inputs to the 1st Repeated timer.

The repeated keeps checking the UART for a byte , once the byte is received , One single shot timer is started , which on expiry turn One of my sensor OFF and inside the handler starts another single shot timer which again turns ON the sensor after 1 hour. 

If i stop the repeated timer when i turn OFF the Sensor , and start the Timer when I turn ON the sensor again. The whole thing just comes to a halt and it doesn't work anymore.

I have fixed this issue by using a timer of 10 seconds , which does literally nothing but keep repeating after 10 seconds, but i am not sure if the theory is correct or not.

""If all the timers have been turned OFF , the RTC goes to deep-sleep and it doesn't count anymore and to keep the RTC alive , i have used a repeated timer as desribed above.

It works in this configuration , but i am not sure if the reasoning is correct or not.""

Kindly help me understand this behavior.

Thanks 

Rajat

Parents Reply
  • Hello,

    Sorry. I was out of office for a few days.

    It didn't help to switch places on the scheduler and pwr mgmt in your main loop by the way?

    I still don't see where you have used your APP_TIMER_PRESCALER. It is only defined (twice), and not used anywhere else, as far as I can tell.

    Try these two steps:

    1: change your main loop to:

        while (1)
            {
                app_sched_execute ();
                nrf_pwr_mgmt_run ();
            }

    so that your application actually handles the scheduler before going to sleep.

    and 2:

    Change your APP_TIMER_CONFIG_RTC_FREQUENCY in sdk_config.h to something higher. E.g. 31 (1024Hz). You can of course tune this, but try this value first. Then your timeout values should be fine.

    BR,

    Edvin

Children
  • 1st method 

    doesn't work

    2nd method 

    does the job , but i have doubts on it . 

    If the frequency of RTC was previously 32kHZ and it was stopping after 10 minutes ,then freq of 1024hZ will stop at a time 32 times more than that , which is 320 minutes , around 5 hours.

    But As per my requirement , i should be able to configure it for atleast for a day(24 hours of interval).

  • Yes. It is possible. But changing the RTC frequency (or the prescaler) changes the way the timer behaves. But when you start a timer with an interval, one of your inputs is the number of ticks to timeout.

    From your project:

    app_timer_start (t1_timer_id, T1_INTERVAL, NULL);

    Where T1_INTERVAL is defined as:

    #define APP_TIMER_TICKS(30000)

    if you have not changed app_timer.c/h then this should be:

    #define APP_TIMER_TICKS(MS)                                \
                ((uint32_t)ROUNDED_DIV(                        \
                (MS) * (uint64_t)APP_TIMER_CLOCK_FREQ,         \
                1000 * (APP_TIMER_CONFIG_RTC_FREQUENCY + 1)))

    So it should calculate the number of ticks based on your APP_TIMER_CONFIG_RTC_FREQUENCY.

    Changing APP_TIMER_CONFIG_RTC_FREQUENCY should affect the number of ticks per second on your app_timer, but it should not effect the timeout length. 

    Can you try to debug, and see how many ticks you get on T1_INTERVAL when your APP_TIMER_CONFIG_RTC_FREQUENCY is set to 31 (which means 1024Hz?

    BR,

    Edvin

  • For 1024 frequency , number of ticks is 30720 for 30000 interval of timer t1

  • 983040 are the ticks for 32768 frequency for same interval

  • Is it possible for you to replicate your issue on one of the examples in the SDK without all the external HW, so that I can reproduce it?

    Changing the APP_TIMER_CONFIG_RTC_FREQUENCY should not change the time it takes for the timeout. Only the timer resolution. I have tested it in this example, but it works as intended.

    BR,

    Edvin

Related