This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Beginner's questions on nRF51822 timers

I have two questions:

Question 1: What is the timer timeout limit on nRF51822?

The reason I ask is that I want to update the advertising packet periodically. Below are part of the related code in main.c:

#define APP_TIMER_PRESCALER             0
#define APP_TIMER_MAX_TIMERS            (2+BSP_APP_TIMERS_NUMBER)    
#define APP_TIMER_OP_QUEUE_SIZE         4      

#define ADV_INTERVAL_IN_MS              (5*60000)
#define ADV_INTERVAL                    MSEC_TO_UNITS(ADV_INTERVAL_IN_MS, UNIT_0_625_MS) 
#define ADVDATA_UPDATE_INTERVAL         APP_TIMER_TICKS(ADV_INTERVAL_IN_MS, APP_TIMER_PRESCALER)

static app_timer_id_t m_advdata_update_timer;

static void timers_init(void)
{
    APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
    
    uint32_t err_code = app_timer_create(&m_advdata_update_timer, APP_TIMER_MODE_REPEATED, advdata_update_timer_timeout_handler);
    APP_ERROR_CHECK(err_code);
}

static void timers_start(void)
{
    uint32_t err_code = app_timer_start(m_advdata_update_timer, ADVDATA_UPDATE_INTERVAL, NULL);
    APP_ERROR_CHECK(err_code);
}


void advdata_update_timer_timeout_handler(void * p_context)
{
    advertising_init();
}

In this code I use the internal RC oscillator, and the timer timeout handler will execute once every 5 minutes. However, if the timer is 16 bit, and timer prescaler is set to 0, the timeout limit will be 2^16/32e3 ~ 2s, which is far less than 5 minutes. At the same time, if I change it to longer value (like 20 minutes), the advertising packet will not get updated and will remain the initial value when nRF51822 was first powered on. I am a little confused.

Question 2: I want to make nRF51822 only advertise for 1 minute every hour and sleep for the rest of the time. I read RTCs and timers may be able to do this while RTC is more power efficient. Is there any example available? Another question is, if the system is in deep sleep mode, can it be waken up by RTC rather than an external GPIO interrupt? (How?)

Parents
  • I don't understand your first question because I'm not sure you actually asked a question. The limits on RTC for a given prescalar are in table 149 of the nRF51 series reference manual and yes at 0 the max is 512 seconds. APP_TIMER_TICKS() doesn't check for overflow, and you're overflowing it.

    What do you mean by 'deep sleep' mode? No such mode is defined in the manual. There is System On - which has two different sleep modes, low power and low latency, both of which can be exited by a timer interrupt and there's System Off where the entire chip, including timers, is off and can only be woken up from a pin event or a reset.

Reply
  • I don't understand your first question because I'm not sure you actually asked a question. The limits on RTC for a given prescalar are in table 149 of the nRF51 series reference manual and yes at 0 the max is 512 seconds. APP_TIMER_TICKS() doesn't check for overflow, and you're overflowing it.

    What do you mean by 'deep sleep' mode? No such mode is defined in the manual. There is System On - which has two different sleep modes, low power and low latency, both of which can be exited by a timer interrupt and there's System Off where the entire chip, including timers, is off and can only be woken up from a pin event or a reset.

Children
  • Thanks for your reply. For the first question, I realize the RTC is 24-bit, which makes sense in terms of my observation. I am still a little confused about the RTC vs Timer. What timer sources do those application timers use? I think they are two different things. For the second question, I probably meant the System Off mode. I thought it could be waken up by some internal interrupt (e.g. RTC), but it seems the only option will be GPIO event or a reset.

  • Hi diode

    First question: the application timers use RTC1 in the background.

    Second question: Yes, that is correct, you can only wake up from System Off with reset, from GPIO or with the LPCOMP

Related