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

SAADC inconsistent buffer channnel

Good Day,

i´m want to use saadc with 7 channels. I´m using the ADC Driver with an interupt handler. All 10ms the sampling starts per cpu. I use the configuration followed:

------------------------------------------------------------------------------------------

 /* lokale Variablen */
    nrfx_saadc_config_t stADCCfg;
    nrf_saadc_channel_config_t stChCfg;
    /* generelle Konfiguration */
    nrfx_saadc_uninit();
    stADCCfg.resolution     = NRF_SAADC_RESOLUTION_12BIT;
    stADCCfg.oversample     = NRF_SAADC_OVERSAMPLE_2X;
    nrfx_saadc_init( &stADCCfg, HWADCEvent );
    /* Voreinstellungen alle Kanäle */
    stChCfg.acq_time    = NRF_SAADC_ACQTIME_20US;
    stChCfg.burst       = NRF_SAADC_BURST_ENABLED;
    stChCfg.gain        = NRF_SAADC_GAIN1_4;
    stChCfg.mode        = NRF_SAADC_MODE_SINGLE_ENDED;
    stChCfg.reference   = NRF_SAADC_REFERENCE_VDD4;
    stChCfg.resistor_n  = NRF_SAADC_RESISTOR_DISABLED;
    stChCfg.resistor_p  = NRF_SAADC_RESISTOR_DISABLED;
   
  
    /* PIR Sensor 1 (Sens1) */
    nrfx_saadc_channel_uninit(0);
    stChCfg.pin_p = NRF_SAADC_INPUT_AIN6;
    nrfx_saadc_channel_init( 0, &stChCfg );
    /* PIR Sensor 2 (Sens2) */
    nrfx_saadc_channel_uninit(1);
    stChCfg.pin_p = NRF_SAADC_INPUT_AIN7;
    nrfx_saadc_channel_init( 1, &stChCfg );
    /* PIR Sensor 3 (Sens3) */
    nrfx_saadc_channel_uninit(2);
    stChCfg.pin_p = NRF_SAADC_INPUT_AIN0;
    nrfx_saadc_channel_init( 2, &stChCfg );

    /* PIR Sensor 4 (Sens4) */
    nrfx_saadc_channel_uninit(3);
    stChCfg.pin_p = NRF_SAADC_INPUT_AIN1;
    nrfx_saadc_channel_init( 3, &stChCfg );
        /* Sensor variante detection (Sensor Variante) */
    nrfx_saadc_channel_uninit(4);
    stChCfg.pin_p = NRF_SAADC_INPUT_AIN5;
    nrfx_saadc_channel_init( 4, &stChCfg );
        /* Temperature sensor NTC (SensNTC) */
    nrfx_saadc_channel_uninit(5);
    stChCfg.pin_p = NRF_SAADC_INPUT_AIN4;
    nrfx_saadc_channel_init( 5, &stChCfg );
        /* Last variante detection (Last Variante) */
    nrfx_saadc_channel_uninit(6);
    stChCfg.pin_p = NRF_SAADC_INPUT_AIN2;
    nrfx_saadc_channel_init( 6, &stChCfg );
    /* buffering */
    nrfx_saadc_buffer_convert(m_buffer_pool[0], 7);
    nrfx_saadc_buffer_convert(m_buffer_pool[1], 7);
    nrfx_saadc_buffer_convert(m_buffer_pool[2], 7);
    nrfx_saadc_buffer_convert(m_buffer_pool[3], 7);
    nrfx_saadc_buffer_convert(m_buffer_pool[4], 7);
    nrfx_saadc_buffer_convert(m_buffer_pool[5], 7);
    nrfx_saadc_buffer_convert(m_buffer_pool[6], 7);
    /* calibration */
    nrfx_saadc_calibrate_offset();
-------------------------------------------------------------------------------------------------------
Periodically the sampling starts with:
------------------------------------------------
 nrfx_saadc_sample();
------------------------------------------------
If the conversation is finished, the interupt handler like followed starts...
-----------------------
void HWADCEvent( nrfx_saadc_evt_t const * p_event )
{
    switch ( p_event->type )
    {
        case NRFX_SAADC_EVT_DONE:
            nrfx_saadc_buffer_convert(p_event->data.done.p_buffer,7);  
            val1   = p_event->data.done.p_buffer[0];
            val2   = p_event->data.done.p_buffer[1];
            val3   = p_event->data.done.p_buffer[2];
            val4   = p_event->data.done.p_buffer[3];
            val5 = p_event->data.done.p_buffer[4];
            val6        = p_event->data.done.p_buffer[5];
            val7   = p_event->data.done.p_buffer[6];
            break;
        case NRFX_SAADC_EVT_LIMIT:
            break;
        case NRFX_SAADC_EVT_CALIBRATEDONE:
            break;
        default:
            break;
           
    }
}
----------------
If I starts the program, the values channels are  swapping in fiew minutes. For example val1 have got the value from channel 6, val2 frome channel 1 and so on.
Sometimes it runs 20 minutes good, then the channels are inconsistent. Sometimes it runs only 2minutes and the values are inconsistent. 
I don´t can find the mistake. My Buffer-Size is as long as the number of variables. What did I wrong?
I played with the interupt priority of the adc channels and with the aquitiontime without success. I spend a lot of time to find the mistake but i cant´t finde them. Can you help me?
Related