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

How to trigger 2 timers on same PPI event

I have the following code. I need to add a second counter attached to the spi_end_event. The first counter "count_task" is working, but can you tell me how to get "count_task2" to also count on every spi_end_event? I'm unclear on how to get multiple tasks to occur on the same event.

    // Configure PPI to toggle CS pin and start SPI transfer on timer event
    uint32_t period_event = nrf_drv_timer_event_address_get(&m_timer1, NRF_TIMER_EVENT_COMPARE0);
    uint32_t cs_task = nrfx_gpiote_out_task_addr_get(GPIO_SPI_CS);
    uint32_t spi_start_task = nrf_drv_spi_start_task_get(&m_spi0);
   
    status = nrfx_ppi_channel_assign(m_ppi_channel0, period_event, cs_task);
    APP_ERROR_CHECK(status);
    status = nrfx_ppi_channel_fork_assign(m_ppi_channel0, spi_start_task);
    APP_ERROR_CHECK(status);
    // Configure PPI to toggle CS pin and count task on SPI transfer end event
    uint32_t spi_end_event = nrf_drv_spi_end_event_get(&m_spi0);
    uint32_t count_task = nrf_drv_timer_task_address_get(&m_timer2, NRF_TIMER_TASK_COUNT);
    uint32_t count_task2 = nrf_drv_timer_task_address_get(&m_timer4, NRF_TIMER_TASK_COUNT);
    status = nrfx_ppi_channel_assign(m_ppi_channel1, spi_end_event, cs_task);
    APP_ERROR_CHECK(status);
    status = nrfx_ppi_channel_fork_assign(m_ppi_channel1, count_task);
    APP_ERROR_CHECK(status);

Parents Reply Children
  • I tried that previously with the following lines at the end of the code I showed above. The timer4 event handler never happens, but the timer2 event handler still does. Timer4 is set up just like timer2, except with different compare count value. This is why I figured I was doing something wrong.

        status = nrfx_ppi_channel_assign(m_ppi_channel2, spi_end_event, count_task2);
        APP_ERROR_CHECK(status);

  • I tried it and it works.

    uint32_t err_code = nrf_drv_ppi_init();
    APP_ERROR_CHECK(err_code);
    
    err_code = nrf_drv_ppi_channel_alloc(&m_adc.saadc_restart_ppi_channel);
    APP_ERROR_CHECK(err_code);
    
    err_code = nrf_drv_ppi_channel_alloc(&m_adc.timer_stop_ppi_channel);
    APP_ERROR_CHECK(err_code);
    
    // Make sure that the SAADC is always started when it ends a conversion
    err_code = nrf_drv_ppi_channel_assign(m_adc.saadc_restart_ppi_channel,
    									  nrf_saadc_event_address_get(NRF_SAADC_EVENT_END),
    									  nrf_saadc_task_address_get(NRF_SAADC_TASK_START));
    APP_ERROR_CHECK(err_code);
    
    // Stop the timer when SAADC finishes a conversion
    err_code = nrf_drv_ppi_channel_assign(m_adc.timer_stop_ppi_channel,
    									  nrf_saadc_event_address_get(NRF_SAADC_EVENT_END),
    									  nrf_drv_timer_task_address_get(&m_adc_timer, NRF_TIMER_TASK_STOP));
    APP_ERROR_CHECK(err_code);
    
    // Enable SAADC restart PPI channel
    err_code = nrf_drv_ppi_channel_enable(m_adc.saadc_restart_ppi_channel);
    APP_ERROR_CHECK(err_code);
    
    // Enable timer stop PPI channel
    err_code = nrf_drv_ppi_channel_enable(m_adc.timer_stop_ppi_channel);
    APP_ERROR_CHECK(err_code);

  • Thank you for posting your code. It made me go back and review mine and I found a mistake in the ppi channel enable for the new channel. It is working for me now.

Related