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

RTC Clear task problem

I'm trying to setup the RTC in the nRF52 to count with a resolution of 1mS. As the count has only a 24 bit value, I wish to clear the count every hour to start again.

There doesn't seem to be a SHORTS register in the RTC which I would expect to be able execute the clear task on a COMPARE event.

I've tried using the PPI, but the count does not get cleared:

uint32 compare0Event = nrf_rtc_event_address_get( rtc, NRF_RTC_EVENT_COMPARE_0 );
uint32 clearTask = nrf_rtc_task_address_get( rtc, NRF_RTC_TASK_CLEAR );
nrf_ppi_channel_endpoint_setup( NRF_PPI_CHANNEL0, compare0Event, clearTask );
nrf_ppi_channel_enable( NRF_PPI_CHANNEL0 );

So I'm trying to manually clear the count every hour (COMPARE0 event):

nrf_rtc_task_trigger( rtc, NRF_RTC_TASK_CLEAR );

But when I do, my compare event each second (COMPARE1 event) just stops.

This seems like it should be the easiest thing in the world but has caused all sorts of problems!

Parents
  • You should be able to clear he counter using PPI. I did a quick test on nRF52 SDK 0.9.2 using the PPI driver and was able to get it to work with the following code snippet (I printed the counter value via RTT to verify that it was actually being cleared):

    err_code = nrf_drv_ppi_channel_alloc(&ppi_channel);
    APP_ERROR_CHECK(err_code);
    err_code = nrf_drv_ppi_channel_assign(ppi_channel,
                                          nrf_rtc_event_address_get(rtc.p_reg, NRF_RTC_EVENT_COMPARE_0),
                                          nrf_rtc_task_address_get(rtc.p_reg, NRF_RTC_TASK_CLEAR));
    

    Here ppi_channel is a nrf_ppi_channel_t defined globally (or rather with file scope).

    If you have not solved the issue yet, maybe you can post a bit more of your code so that it is easier to get the full picture?

  • I looked at it more and it turns out that it does not work properly on my side either. The RTC is cleared once, but after that it is never cleared again. I have not found the reason for this yet, but will update the answer when i find it.

Reply Children
No Data
Related