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

RTC Example - incorrect???? per the 51422 (6310 sdk) examples??

Thanks for all your help. From 30-yr programmer and new bit-banger.

Playing with the 6310 example, rtc_example, the following code makes no sense to us with the toggle directives in the source..

/** RTC0 interrupt handler. * Triggered on TICK and COMPARE0 match. */ void RTC0_IRQHandler() { if ((NRF_RTC0->EVENTS_TICK != 0) && ((NRF_RTC0->INTENSET & RTC_INTENSET_TICK_Msk) != 0)) { NRF_RTC0->EVENTS_TICK = 0; nrf_gpio_pin_toggle(GPIO_TOGGLE_TICK_EVENT); }

if ((NRF_RTC0->EVENTS_COMPARE[0] != 0) && ((NRF_RTC0->INTENSET & RTC_INTENSET_COMPARE0_Msk) != 0)) { NRF_RTC0->EVENTS_COMPARE[0] = 0; nrf_gpio_pin_write(GPIO_TOGGLE_COMPARE_EVENT, 1); } }

a. Note the last phrase - events_compare[0] = 0; Watching the code in the Keil debugger, we can't see that the value ever changes to 0.

b. Per Nrf512 ref, pg, 72, it's described that a Compare event is only triggered when Counter "transistions from N-1 to N", etc..

c. We don't see any provision to (a. reset Counter (to a value of less than CC[0]) or to modify the Counter to a value less than CC so subsequent triggers will occur.???

d. The code might imply that the second LED is supposed to Toggle ?? It does not, since there's no reset to the Counter nor CC[0] to enable counter to approach and reach it again.

e. Is there an example of how this should actually look to work correctly. What is the correct technique to get the lower (Compare) phrase to cycle???

tks again!

  • Hi,

    The EVENTS_TICK is set by the frequency of your RTC (32.768k/(prescaler+1)), which is 125 ms. This event will happen for each TICK of the clock, which you can see in the COUNTER register.

    The CC[0]-registers is set to a given value, lets say 20. This means that each time the COUNTER is 20, it will give an event on CC[0]. However, for the counter to overflow (2^24 ticks * 125 ms), it will take quite some time, so for all normal purposes, you will only see one EVENTS_COMPARE=1, which is after about 3 seconds after RESET.

    To make the compare event to be set every 20 TICKS, you will have to update the CC[0] register. It'll look something like this:

    
    ...
        if ((NRF_RTC0->EVENTS_COMPARE[0] != 0) && 
            ((NRF_RTC0->INTENSET & RTC_INTENSET_COMPARE0_Msk) != 0))
        {
            static uint32_t cmp0 = COMPARE_COUNTERTIME * RTC_FREQUENCY;
            cmp0 += COMPARE_COUNTERTIME * RTC_FREQUENCY;
            NRF_RTC0->CC[0] = cmp0;
            NRF_RTC0->EVENTS_COMPARE[0] = 0;
            nrf_gpio_pin_write(GPIO_TOGGLE_COMPARE_EVENT, 1);
        }
    ...
    
    

    This example lacks a proper description on how it works, so it's hard to tell without knowing how the hardware works.

  • Hi Håkon, Thanks for your comment - We're well on track.

    We have been working w/ NS for many months on a development project and have invested many $$ in the development of our PCB based on the 51422 platform - and have loved the chip, barring some difficulties that we can't find in documents.

    tks!!

  • Hi Roger,

    No problem. If you come across more strange behavior working with our devices, just post a thread here, and we'll help you out :-)

    -Håkon

Related