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

SAADC acquisition time measurement

OS : Ubuntu

SDK: 15.3.0_59ac345

Base example : peripheral/saadc

HW : nRF52832 DK PCA10040 1.2.1 2017.49 682663245

Hello, i would like to make sure the ADC acquisition speed.

As seen in this post, it was recommended to use GPIOTE to toggle a pin on start and end of an sampling to measure precisely the acquisition frequency with a logic analyser.

  • I have updated the peripheral/saadc base example to attache two channels on EVENTS_DONE  and TASKS_SAMPLE
     to clear and set the GPIO 20.
  • I have changed the acquisition time to  NRF_SAADC_ACQTIME_3US
  • I have changed the timer to 100µS.

 

void saadc_sampling_event_init(void)
{
    ret_code_t err_code;

    err_code = nrf_drv_ppi_init();
    APP_ERROR_CHECK(err_code);

    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;
    err_code = nrf_drv_timer_init(&m_timer, &timer_cfg, timer_handler);
    APP_ERROR_CHECK(err_code);

    /* setup m_timer for compare event every 5µs */
    uint32_t ticks = nrf_drv_timer_us_to_ticks(&m_timer, 100);
    nrf_drv_timer_extended_compare(&m_timer,
                                   NRF_TIMER_CC_CHANNEL0,
                                   ticks,
                                   NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                   false);
    nrf_drv_timer_enable(&m_timer);

    uint32_t timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&m_timer,
                                                                                NRF_TIMER_CC_CHANNEL0);
    uint32_t saadc_sample_task_addr = nrf_drv_saadc_sample_task_get();

    /* setup ppi channel so that timer compare event is triggering sample task in SAADC */
    err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel_saadc);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_alloc(&m_ppi_channel_saadc_start);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_assign(m_ppi_channel,
                                          timer_compare_event_addr,
                                          saadc_sample_task_addr);

    APP_ERROR_CHECK(err_code);

    // err_code = nrf_drv_ppi_channel_fork_assign(m_ppi_channel, nrf_drv_gpiote_out_task_addr_get(LED2));
    err_code = nrf_drv_ppi_channel_assign(m_ppi_channel_saadc,
                                          (uint32_t)&NRF_SAADC->EVENTS_DONE,
                                          nrf_drv_gpiote_clr_task_addr_get(LED2));

    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_assign(m_ppi_channel_saadc_start,
                                          (uint32_t)&NRF_SAADC->TASKS_SAMPLE,
                                          nrf_drv_gpiote_set_task_addr_get(LED2));

    APP_ERROR_CHECK(err_code);
}

From my understanding, i expect a 3µs toggle every 100µs, but i have a nothing toggleing on the pin.

If now i change the events from :  EVENTS_DONE  and TASKS_SAMPLE to  : EVENTS_DONE  and EVENTS_STARTED i do have a toggeling ( so my PPI channeling is working ) but i still don't have the expected result ( i have 87.5µs every 0.4ms instead of the expected 3µs toggle every 100µs)

Am i understanding something wrong ?

Parents Reply Children
No Data
Related