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

nRF52832 how to use PPI to do a capture compare on a timer, and also disable that compare?

Hi. I am using timers and PPI to do frequency counting.

The basic process is for 1 PPI channel to incriment a timer, and then a second PPI on a second timer to stop the counter after 10mS.

The captured value is then read, and all the timers reset.

I would like to increase the time period to 15mS, but do another capture on the timers CC channel 1 after 5mS.

I have setup a second timer compare, but the problem is that this capture keeps happening after 5mS because it is not stopped.

How do I setup a capture to only fire once? The 'nrf_drv_timer_extended_compare' will allow me to stop the mask 'NRF_TIMER_SHORT_COMPARE1_STOP_MASK' but how do I start it again? Also will this stop mean that the PPI event not work.

Thanks

Parents
  • I think I have found an issue. I configure 2 compares for my timer4, but I read in another question that 'NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK' will clear the whole timer not just the compare?

    What is the point of 'NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK' if you can't clear individual compare channels? I don't want the clear the whole timer at this 5mS compare event, just the compare. Is there a way to do that?

    Basically how do you use a timer compare to trigger a capture only once, and then disable that capture which the timer carries on running?

    static void timer4_init(void)
    {
        // Check TIMER2 configuration for details.
        nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
        timer_cfg.frequency = NRF_TIMER_FREQ_31250Hz;
        
        ret_code_t err_code = nrf_drv_timer_init(&m_timer4, &timer_cfg, NULL);
        error_check(err_code);
    
        //compare 1
        nrf_drv_timer_extended_compare(&m_timer4,
                                       NRF_TIMER_CC_CHANNEL0,
                                       nrf_drv_timer_ms_to_ticks(&m_timer4, 15),  //15mS
                                       NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                       false);
    
        //compare 2
        nrf_drv_timer_extended_compare(&m_timer4,
                                       NRF_TIMER_CC_CHANNEL1,
                                       nrf_drv_timer_ms_to_ticks(&m_timer4, 5),  //5mS
                                       NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK,
                                       false);
    }

Reply
  • I think I have found an issue. I configure 2 compares for my timer4, but I read in another question that 'NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK' will clear the whole timer not just the compare?

    What is the point of 'NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK' if you can't clear individual compare channels? I don't want the clear the whole timer at this 5mS compare event, just the compare. Is there a way to do that?

    Basically how do you use a timer compare to trigger a capture only once, and then disable that capture which the timer carries on running?

    static void timer4_init(void)
    {
        // Check TIMER2 configuration for details.
        nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
        timer_cfg.frequency = NRF_TIMER_FREQ_31250Hz;
        
        ret_code_t err_code = nrf_drv_timer_init(&m_timer4, &timer_cfg, NULL);
        error_check(err_code);
    
        //compare 1
        nrf_drv_timer_extended_compare(&m_timer4,
                                       NRF_TIMER_CC_CHANNEL0,
                                       nrf_drv_timer_ms_to_ticks(&m_timer4, 15),  //15mS
                                       NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                       false);
    
        //compare 2
        nrf_drv_timer_extended_compare(&m_timer4,
                                       NRF_TIMER_CC_CHANNEL1,
                                       nrf_drv_timer_ms_to_ticks(&m_timer4, 5),  //5mS
                                       NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK,
                                       false);
    }

Children
Related