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

SAADC with

I need to measure with SAADC two channels in the same time (NRF_SAADC_INPUT_AIN6 and NRF_SAADC_INPUT_AIN4).

Is possible ?

Have you an code example?

Thanks

Marco

  • "seem work but sametime in the buffer I find the values exchanged between channels. WHY ?".

    I seem to have this issue as well when I have more than 1 channel getting saadc values. I explain more thoroughly in my question: https://devzone.nordicsemi.com/f/nordic-q-a/58861/saadc-multiple-channel-buffer-inconsistencies

  • Ok. I assume you will be followed up in your new ticket. The engineer who is assigned to that case will probably be interested in knowing how you trigger the sampling of the ADC, and about what frequency you do that.

    BR,

    Edvin

  • hi, John.

    Unfortunately I never found a solution.

    The frequency of my saples are 2 mS. Each 2 mS I need to sample 2 channels.

    For now I set the ADC in order to make 2 different samples with one channel for time

    Marco

  • I've been playing around with this issue a bit today and I may have found a solution, but I have no clue why or how. I'd be interested to find out if it fixes your problem as well. 

    My solution:

    Change saadc_init() to the following:

    void saadc_init(unsigned char type)
    {
        ret_code_t err_code;
        
        nrf_saadc_channel_config_t channel_config =
            NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN6);
    
        err_code = nrf_drv_saadc_init(NULL, saadc_PULSE_INEX_callback);
        APP_ERROR_CHECK(err_code);
    
        err_code = nrf_drv_saadc_channel_init(0, &channel_config);
        APP_ERROR_CHECK(err_code);
        
        channel_config.pin_p = NRF_SAADC_INPUT_AIN4;
        err_code = nrf_drv_saadc_channel_init(1, &channel_config);
        APP_ERROR_CHECK(err_code);
        
        err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool_scann[0], SAMPLES_IN_BUFFER_SCANN);
        APP_ERROR_CHECK(err_code);
        err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool_scann[1], SAMPLES_IN_BUFFER_SCANN);
        APP_ERROR_CHECK(err_code);
    }

    Can you try it and let me know if it fixes the issue? Or you are done with this project?

  • Your code seem same at my old inizialization. When did not work. The problem is connected to the interrupt.

    Now I'm on new project and is difficult to come back on this.

    But to resolve the problem I used the ADC without interupt. Waiting the end of conversion for each cannel. The time lost between the 2 conversion is abot 30 uS.

        err_code = nrf_drv_saadc_channel_uninit(0);
        APP_ERROR_CHECK(err_code);
        err_code = nrf_drv_saadc_channel_init(0, &channel_config_PULSE);
        APP_ERROR_CHECK(err_code);
        nrfx_saadc_sample_convert(0, &value_1);
        adc_value_pulse = ADC_RESULT_IN_MILLI_VOLTS(value_1);      //
        if (adc_value_pulse>35000) adc_value_pulse=0;
        
        err_code = nrf_drv_saadc_channel_uninit(0);
        APP_ERROR_CHECK(err_code);
        err_code = nrf_drv_saadc_channel_init(0, &channel_config_INEX);
        APP_ERROR_CHECK(err_code);
        nrfx_saadc_sample_convert(0, &value_2);
        adc_value_inex = ADC_RESULT_IN_MILLI_VOLTS(value_2);      //
        if (adc_value_inex>35000) adc_value_inex=0;
    

Related