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
  • Can you please specify a few things:
    What is your LFCLK source? And what is your app_timer prescaler? 

    As you can see from the documentation of the RTC, the resolution is not necessarily even 10m:

    https://www.nordicsemi.com/DocLib/Content/Product_Spec/nRF52840/latest/rtc?664#concept_rvn_vkj_sr

    I don't think I fully understand your requirements, but you need to have a timer running at all times, or do you not?

    BR,

    Edvin

  • I am using BLE , so that by default would init the lfclk and app timer prescaler is 15 .

    No , i need restart the stopped timer after certain duration of expiry of a different timer. . Works well for less than 10 minutes , but for a greater duration , it doesn't.

  • /** @file timer_interra.c
    *
    * @brief A Timer used to generate the delay functionality, will later try to execute events.
    *
    * @par
    * NOTICE: Property of in-Terra Limited www.in-terra.ch .
    */
    
    
    #include "timer_interra.h"
    
    APP_TIMER_DEF(m_led_0_timer_id);
    
    uint8_t timer_exp_flag=0;
    
    void timer_0_handler(void * p_context)
    { 
        timer_exp_flag=1; 
        
           
    }
    
    
    /*!
     * @brief Delay using the app timer
     *
     * @param[in] None
     *
     * @return    None
     */
    
    uint8_t delay()
    {
    
        if (timer_exp_flag == 1)
            {
                timer_exp_flag = 0;
    
                return 1;
            }
        else
            {   
                return 0;
            }
    }
    
    
    /*!
     * @brief Delay using the app timer
     *
     * @param[in] None
     *
     * @return    None
     */
    
    uint8_t timer_ms(uint32_t time_miliseconds)
    {
    
    uint32_t err_code;
     
        err_code = app_timer_create(&m_led_0_timer_id,
                                    APP_TIMER_MODE_SINGLE_SHOT,
                                    timer_0_handler);
        APP_ERROR_CHECK(err_code);
    
        // Start timers
        err_code =app_timer_start(m_led_0_timer_id, APP_TIMER_TICKS(time_miliseconds), NULL);
        APP_ERROR_CHECK(err_code);
        
      while(delay()!=1);
    
     // while(timer_exp_flag!=1);
    }
    
    
    
    
    /*!
     * @brief Initilaize the Timer
     *
     * @param[in] None
     *
     * @return    None
     */
    
    void
    timer_init (void)
    {
        
    ret_code_t err_code;
    err_code=app_timer_init();
    
     SEGGER_RTT_printf(0,"Error Code is %ld\r\n", err_code);      
       
    }
    
    /*!
     * @brief start the Timer
     *
     * @param[in] milsecond to expire
     *
     * @return    None
     */
    
    void
    timer_start(uint32_t ms_time)
    {
        
    
            
       
    }
    timer_interra.h

  • Inside timer_interra.h , i have defined

    #define APP_TIMER_PRESCALER             15 

  • APP_TIMER_CONFIG_RTC_FREQUENCY 0

    or is it this value that decides everything ahead in the software?

    I am confused. :(

  • i am not able to upload the whole project , it says Error when i upload the zip file.

  • Where is APP_TIMER_PRESCALER used?

    It may be that the .zip file is too big. Try to delete everything inside the _build folder. I don't know what IDE you use (Segger Embedded Studio, Keil or IAR), but you can delete everything that is generated when you compile your project before zipping the project folder. Then it will be a much smaller file.

    If you want to send e.g. the ble_app_hrs project, and you use Segger Embedded Studio, then go to SDK\examples\ble_peripheral\ble_app_hrs\pca10056\s140\ses, and delete your Output folder. Then zip the ble_app_hrs folder.

    If you use Keil, the folder you should delete is SDK\examples\ble_peripheral\ble_app_hrs\pca10056\s140\arm5_no_packs\_build

    Best regards,

    Edvin

Reply
  • Where is APP_TIMER_PRESCALER used?

    It may be that the .zip file is too big. Try to delete everything inside the _build folder. I don't know what IDE you use (Segger Embedded Studio, Keil or IAR), but you can delete everything that is generated when you compile your project before zipping the project folder. Then it will be a much smaller file.

    If you want to send e.g. the ble_app_hrs project, and you use Segger Embedded Studio, then go to SDK\examples\ble_peripheral\ble_app_hrs\pca10056\s140\ses, and delete your Output folder. Then zip the ble_app_hrs folder.

    If you use Keil, the folder you should delete is SDK\examples\ble_peripheral\ble_app_hrs\pca10056\s140\arm5_no_packs\_build

    Best regards,

    Edvin

Children
  • 3034.Test.rar

    in-terra.rar

    Test.rar file contains the main.c file and sdk_config.h and in-terra.rar contains the .c and .h files being used.

    Path used for project is : C:\Nordic\nRF5_SDK_15.0.0_a53641a\examples\myprojects\Test

    Path used for in-terra folder for .c and .h files is : C:\Nordic\nRF5_SDK_15.0.0_a53641a\in-terra

  • Did you look into the project files i sent to you"?

  • 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

  • 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

Related