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

how to stop a timer ?

I am using 2 counters, one to produce the 4MHz, and the other for the 62.5KHz, to drive I2S module.

I need to find a way to stop the first counter (4MHz) after it produces a certain number of ticks (for example 512 ticks).

If I use the code (attached), the 4MHz timer does not produce pulses.

    nrf_drv_timer_config_t Timer_0_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    Timer_0_cfg.frequency = NRF_TIMER_FREQ_8MHz;
    Timer_0_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;
    // Set up timer
    NRF_TIMER0->PRESCALER = 1;
    NRF_TIMER0->CC[0] = 1;
    NRF_TIMER0->CC[1] = 1;
    nrfx_timer_compare(&Timer_0, NRF_TIMER_CC_CHANNEL0, 1, false);
    nrfx_timer_extended_compare(&Timer_0, NRF_TIMER_CC_CHANNEL1, 512, NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK, false);

I am also not sure how to use the following:

NRF_TIMER0->CC[0], and would it be ignored if i use the function: nrfx_timer_extended_compare() ?

also:

NRF_TIMER_CC_CHANNEL1 and NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK in nrfx_timer_extended_compare(); how are the different from CHANNEL0/2/3 and COMPARE0/2/3_CLEAR_MASK

thanks

Parents
  • Hi,

    You have two options to do this:

    1. Enable interrupts for the timer events. Increment a counter in the event handler, when it reaches 512, stop the timer. This approach may not work well for high-frequency timers, as the interrupt latency may cause additional pulses to be clocked out before you are able to stop the timer.
    2. Use a second timer in COUNT mode. Connect the COMPARE event of the clock-generating timer to the COUNT task of the second timer. Set he CC register of the counting-timer to the number of clock cycles you want to stop the first timer at, then connect the COMPARE event from the counting timer to the STOP task of the clock-generating timer.

    Best regards,
    Jørgen

  • Hi Jorgen

    Thanks a lot for the advice. I am trying to do the connection between timer-0 counts and counter-1 using PPI channel-3 (assuming this is the right way to do it)

    I believe this line will monitor the compare event on timer-0.

    What is it the command to use to trigger the counts on counter-1 ?

    many thanks

    compare_event_addr_3 = nrf_drv_timer_event_address_get(&Timer_0, NRF_TIMER_EVENT_COMPARE0);
    

Reply Children
No Data
Related