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

SAADC Limit Monitoring

Hello,

I'm writing an application that uses the SAADC and would like to set up a high limit to trigger on.

If I use the following code, I'm able to trigger 1 ADC sample successfully:

errCode = nrf_drv_saadc_buffer_convert( &adcValue, 1 );
APP_ERROR_CHECK( errCode );

errCode = nrf_drv_saadc_sample();
APP_ERROR_CHECK( errCode );

And the registered callback when init'ing SAADC is:

static void _TriggeredEventCallback( nrf_drv_saadc_evt_tconst * inEvent )
{
    if ( inEvent->type == NRF_DRV_SAADC_EVT_DONE )
    {
        // Get the ADC conversion result
        nrf_saadc_value_t adcValue = inEvent->data.done.p_buffer[0];
        NRF_LOG_INFO( "Read ADC %d\n", adcValue );
    }
    else if ( inEvent->type == NRF_DRV_SAADC_EVT_LIMIT )
    {
        NRF_LOG_INFO( "Limit exceeded!\n" );
    }
}

Then I went further and tried to set the high limit by adding a call to nrf_drv_saadc_limits_set() right before the call to nrf_drv_saadc_buffer_convert()

// Set the high limit
nrf_drv_saadc_limits_set( kCurrentMonitorADCChannel, NRF_DRV_SAADC_LIMITL_DISABLED, 200 );

But I didn't see the behavior I was expecting when I increase the voltage that is connected to the pin. However if I boot up with an input voltage that exceeds the limit, I see the printout indicating the limit is exceeded.

My questions are:

  1. If I set up a limit and start a single conversion, would ADC conversions be triggered automatically internally until the limit is exceeded or some other part of the code stops the ADC?
  2. Does the event NRF_DRV_SAADC_EVT_DONE trigger for all ADC conversions when I have a limit set or am I only expecting the event NRF_DRV_SAADC_EVT_LIMIT to trigger?

Thanks!

Related