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

Change tick value of timer compare event

Hello,

I'm using TIMER1 to generate a timer compare event. I connect the event with the sample task of the saadc like in the saadc example from the SDK. Everything works fine.

But now I want to change the tick value of the timer compare event after the saadc-sampling started. I thought I would have to disable the timer, set it with the new tick value to extended compare, enable it again and then assign the new event adress to the ppi channel like in the following code:

        nrf_drv_timer_disable(&gTimer);

        uint32_t ticks = nrf_drv_timer_us_to_ticks(&gTimer, newTickValue);

 	    nrf_drv_timer_extended_compare(&gTimer,
                                   NRF_TIMER_CC_CHANNEL1,
                                   ticks,
                                   NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK,
                                   false);

   	    nrf_drv_timer_enable(&gTimer);

    	uint32_t timer_compare_event_addr = rf_drv_timer_compare_event_address_get(&gTimer,
                                                                                NRF_TIMER_CC_CHANNEL1);
        uint32_t saadc_sample_task_addr   = nrf_drv_saadc_sample_task_get();

        errCode = nrf_drv_ppi_channel_assign(gPpiChannel,
                                          timer_compare_event_addr,
                                          saadc_sample_task_addr);

But it doesn't work, no saadc callback is called anymore. Also tried to free the ppi channel before giving the adress to it and I also tried to uninitialize the timer and ppi completely and init it again but I miss something because nothing seems to work.

I'm thankful for any advice.

Regards Lea

  • I think you forgot to start timer after re-enabling it.

  • But I don't need to start the timer the first time either. However I tried using the nrf_drv_timer_resume() function know but that changes nothing.

  • ah right. I have never used that driver. nrf_drv_timer_enable triggers start task for the timer. do you start saadc after each sampling? (probably by ppi). You sure you provide correct newTickValue? What is the timer frequency?

  • Yes I have connected the saadc end event and the start task over ppi. Just checked the newTickValue while debugging, seems to be correct. Frequency of the timer is 16MHz.

  • FormerMember
    0 FormerMember

    In nrf_drv_timer_extended_compare(..) you have disabled interrupt (set it to 'false'),try to enable interrupt and see if it changes anything.

1 2