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

saacd scan oversample

Hi, I'm trying to set up my SAADC to measure VDD and battery voltage on AIN3. According to this post, later versions of the SDK were modified so that one could use scan, burst, and oversample. But I'm using 14.1, and it seems like nrf_drv_saadc_channel_init() is written so that oversample is for 1 channel ONLY. What is the official word on oversampling multiple channels with burst at this time? Thanks.

I'm working on a custom board based on the nRF52832. I'm developing on Win 8.1 using SES and a J-Link Plus. SDK version 14.1.

Parents
  • Hi Jason,

    As described by Carsten in the thread you are linking, oversample will give correct sampling in scan mode only when burst is enabled for all active channels.

    Unfortunately, this is not supported by the SAADC driver in the SDK. It should however be quite simple to add this support if you want to use it. These instructions are for SDK 14.1.0, all changes in nrf_drv_saadc.c:

    Add an array called burst to the struct nrf_drv_saadc_cb_t, to keep track of the burst settings for each channel (add between line 93-94):

    uint8_t burst[NRF_SAADC_CHANNEL_COUNT];    ///< Burst configurations of SAADC channels.
    

    Add a check to make sure all enabled channels have burst enabled, in nrf_drv_saadc_channel_init() (replace line 314-316):

    // Oversampling can be used with only one channel, or if burst is enabled for all active channels.
    uint8_t allow_oversample = true;
    if(m_cb.active_channels != 0)
    {
    	for(int i = 0; i < NRF_SAADC_CHANNEL_COUNT; i++)
    	{
    		if ((m_cb.psel[i].pselp != NRF_SAADC_INPUT_DISABLED) && m_cb.burst[i] != NRF_SAADC_BURST_ENABLED)
    		{
    			allow_oversample = false;
    		}
    	}
    	if(allow_oversample && p_config->burst == NRF_SAADC_BURST_DISABLED)
    	{
    		allow_oversample = false;
    	}
    }
    ASSERT((nrf_saadc_oversample_get() == NRF_SAADC_OVERSAMPLE_DISABLED) || allow_oversample);
    

    Store burst setting in struct before initializing the channel in nrf_drv_saadc_channel_init() (add between line 344-345):

    m_cb.burst[channel] = p_config->burst;
    

    Clear burst setting in struct when uninitializing channel in nrf_drv_saadc_channel_uninit() (add between line 383-384):

    m_cb.burst[channel] = NRF_SAADC_BURST_DISABLED;
    

    I will report this internally, hopefully we can make the driver support this.

    Best regards,

    Jørgen

Reply Children
No Data
Related