NRF52840 Timer channels with different periods.

Hi There, 

I have been looking for ways to have three channels of a hardware timer with the NRF52840 generate a compare interrupt at different time intervals, my understanding is that this is their functionality however I have not been able to implement it correctly. 

For instance I want to get the following chain of events:

 0----200us------300us-------1000us  (Not necessarily these values).

 -----CH0-------CH1---------CH2      (Timer interrupt events).

I have tried this: 

    nrfx_timer_compare(&timer,
                        NRF_TIMER_CC_CHANNEL0,
                        ticksToUs,
                        true);
    nrfx_timer_compare(&timer,
                        NRF_TIMER_CC_CHANNEL1,
                        ticksToUsOne,
                        true);
    nrfx_timer_compare(&timer,
                        NRF_TIMER_CC_CHANNEL2,
                        ticksToUsTwo,
                        true);

And I do get the interrupts to occur for every channel at the given interval but they only occur once. How could I make this sequence periodic ?

What would be the best way tp implement this ?

Thanks, 

Cheers 

Parents
  • Hi,

    When you get the last interrupt, call nrfx_timer_clear(), the timer will then 'restart' from the begin, 

    Alternatively, when you set up the last compare interrupt, use the function nrfx_timer_extended_compare() with a 'short mask' between the compare and the clear timer task

    nrfx_timer_extended_compare(&timer,
    NRF_TIMER_CC_CHANNEL2,
    nrfx_timer_ms_to_ticks(&timer, delay_ms),
    NRF_TIMER_SHORT_COMPARE2_CLEAR_MASK, //Shortcut for clearing the timer based on compare 2.
    true);

Reply
  • Hi,

    When you get the last interrupt, call nrfx_timer_clear(), the timer will then 'restart' from the begin, 

    Alternatively, when you set up the last compare interrupt, use the function nrfx_timer_extended_compare() with a 'short mask' between the compare and the clear timer task

    nrfx_timer_extended_compare(&timer,
    NRF_TIMER_CC_CHANNEL2,
    nrfx_timer_ms_to_ticks(&timer, delay_ms),
    NRF_TIMER_SHORT_COMPARE2_CLEAR_MASK, //Shortcut for clearing the timer based on compare 2.
    true);

Children
Related