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

how can i change RTC Interrupt calling time?

i m using pca10028.. and sdk12 with eclipse gcc tool chain setup on windows..im run Peripheral>rtc example successfully... interrupt call every 0.125sec but now i want to interrupt call every 1 sec... i m change config, prescaler value form 4095 to (4095*8) but.. now, not any solution.. so help me...

Parents
  • The COUNTER_PRESCALER is used to set the NRF_RTC0->PRESCALER register. The prescaler register of the RTC is a 12 bit wide register, which means that the maximum value the prescaler is capable of holding is 2^12 - 1 = 4095.

    The RTC uses the 32KHz (actually 32768Hz) clock, so the formula for calculating the prescaler value is:

    Prescaler value = 32768 / Frequency - 1
    

    So if we want a frequency of 1, we get an prescaler value of 32768 / 1 - 1 = 32767. This number is too big to fit inside the prescale register (16 bits is required to represent 32767), so we get an overflow.

    We can change the formula to calculate frequency instead:

    Frequency = 32768 / (Precsaler value + 1)
    

    Setting the prescaler value to the maximum value gives: 32768 / (4095 + 1) = 8 Hz. This is the lowest frequency possible in the RTC. (interrupt every 0.125sec)

    So to get an interrupt every 1 second, I would recommend to use either the timer or application timer.

    Take a look at e.g. the Timer example. Here you can set uint32_t time_ms in main.c to 1000 to get the interrupt timer_led_event_handler to trigger every 1 second.

Reply
  • The COUNTER_PRESCALER is used to set the NRF_RTC0->PRESCALER register. The prescaler register of the RTC is a 12 bit wide register, which means that the maximum value the prescaler is capable of holding is 2^12 - 1 = 4095.

    The RTC uses the 32KHz (actually 32768Hz) clock, so the formula for calculating the prescaler value is:

    Prescaler value = 32768 / Frequency - 1
    

    So if we want a frequency of 1, we get an prescaler value of 32768 / 1 - 1 = 32767. This number is too big to fit inside the prescale register (16 bits is required to represent 32767), so we get an overflow.

    We can change the formula to calculate frequency instead:

    Frequency = 32768 / (Precsaler value + 1)
    

    Setting the prescaler value to the maximum value gives: 32768 / (4095 + 1) = 8 Hz. This is the lowest frequency possible in the RTC. (interrupt every 0.125sec)

    So to get an interrupt every 1 second, I would recommend to use either the timer or application timer.

    Take a look at e.g. the Timer example. Here you can set uint32_t time_ms in main.c to 1000 to get the interrupt timer_led_event_handler to trigger every 1 second.

Children
Related