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 still can't get this to work. I'm using the 0.92 SDK with pre-production silicon (Engineering A).

    We have a body of code that I'm getting working on the device. For this reason I'm using the HAL and NOT the drivers, this includes the PPI and RTC code.

    Everything works fine if I reset the RTC manually in my event handler by calling:

    nrf_rtc_task_trigger( rtc, NRF_RTC_TASK_CLEAR );

    But if I try to configure the PPI to reset the counter on a compare event, the clear never happens:

    uint32 hourEventAddress = nrf_rtc_event_address_get( rtc, compareChannelHourEvent );
    uint32 clearTaskAddress = nrf_rtc_task_address_get( rtc, NRF_RTC_TASK_CLEAR );
    nrf_ppi_channel_endpoint_setup( ppiChannel, hourEventAddress, clearTaskAddress );
    nrf_ppi_channel_enable( ppiChannel );
    
Reply
  • I still can't get this to work. I'm using the 0.92 SDK with pre-production silicon (Engineering A).

    We have a body of code that I'm getting working on the device. For this reason I'm using the HAL and NOT the drivers, this includes the PPI and RTC code.

    Everything works fine if I reset the RTC manually in my event handler by calling:

    nrf_rtc_task_trigger( rtc, NRF_RTC_TASK_CLEAR );

    But if I try to configure the PPI to reset the counter on a compare event, the clear never happens:

    uint32 hourEventAddress = nrf_rtc_event_address_get( rtc, compareChannelHourEvent );
    uint32 clearTaskAddress = nrf_rtc_task_address_get( rtc, NRF_RTC_TASK_CLEAR );
    nrf_ppi_channel_endpoint_setup( ppiChannel, hourEventAddress, clearTaskAddress );
    nrf_ppi_channel_enable( ppiChannel );
    
Children
No Data
Related