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

How to predict how much CPU time the SAADC needs on the nRF52832?

I'm attempting to get a grasp on how much CPU time an SAADC conversion is taking. I'm running the SAADC sample code from the nRF52 v15.1.0 SDK on an nRF52832.
SAADC_CONFIG_RESOLUTION is set to 10.
SAADC_CONFIG_LP_MODE is not enabled.
SAADC_CONFIG_IRQ_PRIORITY is set to 7.
I'm using the default values from NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE.
Also, in the sample code I've set SAMPLES_IN_BUFFER to 1.
I'm toggling a GPIO pin in the main loop just to get an idea of much CPU time the SAADC is taking.
It looks like each increase in the SAADC_CONFIG_OVERSAMPLE doubles the amount of CPU time needed for the SAADC conversion.
I don't see anywhere in the datasheet where it talks about how much CPU time the SAADC needs. Is there a formula to calculate the CPU time for an SAADC conversion given the oversample rate, configured acquisition time, etc?

Parents
  • I am not sure how you are toggling the GPIOs but SAADC is a peripheral with its own EasyDMA, the CPU usage should be only to configure the peripheral and process any callbacks. It would give us a better view if we see exactly where you are toggling the GPIOs

  • In the main loop of the SAADC sample, I've added a toggle of GPIO 24:

    while (1)
    {
        nrf_pwr_mgmt_run();
        NRF_LOG_FLUSH();

        nrf_gpio_pin_toggle(24);
    }

    In saadc_sampling_event_init() of the SAADC sample, I've set the PPI timer to 1ms:

    /* setup m_timer for compare event every 1ms */
    uint32_t ticks = nrf_drv_timer_ms_to_ticks(&m_timer, 1);

    With this setup, GPIO 24 in the main loop toggles every 1 ms. If I set oversampling from OFF to 2x, GPIO 24 toggles every 2ms. If I set oversampling to 4x, GPIO 24 toggles every 4 ms. As I understand it, the SAADC sample is non-blocking, so I would expect GPIO 24 to toggle as fast as possible, and not be directly related to the SAADC configuration.

Reply
  • In the main loop of the SAADC sample, I've added a toggle of GPIO 24:

    while (1)
    {
        nrf_pwr_mgmt_run();
        NRF_LOG_FLUSH();

        nrf_gpio_pin_toggle(24);
    }

    In saadc_sampling_event_init() of the SAADC sample, I've set the PPI timer to 1ms:

    /* setup m_timer for compare event every 1ms */
    uint32_t ticks = nrf_drv_timer_ms_to_ticks(&m_timer, 1);

    With this setup, GPIO 24 in the main loop toggles every 1 ms. If I set oversampling from OFF to 2x, GPIO 24 toggles every 2ms. If I set oversampling to 4x, GPIO 24 toggles every 4 ms. As I understand it, the SAADC sample is non-blocking, so I would expect GPIO 24 to toggle as fast as possible, and not be directly related to the SAADC configuration.

Children
  • most probably you are using the burst mode then. I am not sure if the oversampling rate is linearly proportional to the time it takes to finish the full samples. But it definitely seems to take more. Here is the text from the PS

    The accumulator is controlled in the OVERSAMPLE register. The SAMPLE task must be set 2OVERSAMPLE number of times before the result is written to RAM. This can be achieved by:
    
    Configuring a fixed sampling rate using the local timer or a general purpose timer and PPI to trigger a SAMPLE task
    Triggering SAMPLE 2OVERSAMPLE times from software
    Enabling BURST mode
    CH[n].CONFIG.BURST can be enabled to avoid setting SAMPLE task 2OVERSAMPLE times. With BURST = 1 the ADC will sample the input 2OVERSAMPLE times as fast as it can (actual timing: <(tACQ+tCONV)×2OVERSAMPLE). Thus, for the user it will just appear like the conversion took a bit longer time, but other than that, it is similar to one-shot mode.

    If you have enabled Burst mode, then it seems that taking more time for the whole sample to finish seems reasonable.

Related