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

ADC init problem

I have a question about ADC configuration。 If an ADC input is multiplexed in different ADC channels ,  is the ADC data still dependable?

for example, the init code is as below:

void user_saadc_init(void)
{
ret_code_t err_code;
nrf_saadc_channel_config_t channel_config0 =NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0);
nrf_saadc_channel_config_t channel_config1 =NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_DIFFERENTIAL(NRF_SAADC_INPUT_AIN0,NRF_SAADC_INPUT_AIN1);
channel_config1.gain=NRF_SAADC_GAIN1_6;
nrf_saadc_channel_config_t channel_config2 =NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_DIFFERENTIAL(NRF_SAADC_INPUT_AIN0,NRF_SAADC_INPUT_AIN1);
channel_config2.gain=NRF_SAADC_GAIN1_3;
err_code = nrf_drv_saadc_init(NULL, saadc_callback);
APP_ERROR_CHECK(err_code);
err_code = nrf_drv_saadc_channel_init(0, &channel_config0);
err_code = nrf_drv_saadc_channel_init(1, &channel_config1);
err_code = nrf_drv_saadc_channel_init(2, &channel_config2);
APP_ERROR_CHECK(err_code);

}

NRF_SAADC_INPUT_AIN0  is multiplexed。The only  difference between channel_config1 and channel_config2 is gain. In this case , does every channel work well?

Parents
  • Hello,

    If an ADC input is multiplexed in different ADC channels ,  is the ADC data still dependable?

    I would think this should be no problem at all. The channels are multiplexed, as you said, so the pins will not actually be sampled at the same time either way.
    So, I do not see any reason why this should not work.
    Are you getting any unexpected behavior when you run this initialization? If so, what are you observing, and how is it different from what you would have expected?

    I notice that you do not perform an APP_ERROR_CHECK on every returned error code. You should make sure that every returned error code is checked.

    For future reference, please use the "Insert -> Code" option when sharing code on the forum. This drastically increases readability.

    Best regards,
    Karl

  • Hi Karl,

    Thanks!

    I didn't find any problems in my use. I just want to confirm it from you.

    Best regards,

    Peaker

  • Hello Peaker,

    peaker2016 said:
    I didn't find any problems in my use. I just want to confirm it from you.

    Oh, I understand. Thank you for clarifying!
    As far as I can see your proposed implementation should work just fine - but I urge you to add the APP_ERROR_CHECKS that I mentioned in my previous comment.

    Please do not hesitate to open a new ticket in the future if you should encounter any issues or questions.

    Good luck with your development!

    Best regards,
    Karl 

Reply
  • Hello Peaker,

    peaker2016 said:
    I didn't find any problems in my use. I just want to confirm it from you.

    Oh, I understand. Thank you for clarifying!
    As far as I can see your proposed implementation should work just fine - but I urge you to add the APP_ERROR_CHECKS that I mentioned in my previous comment.

    Please do not hesitate to open a new ticket in the future if you should encounter any issues or questions.

    Good luck with your development!

    Best regards,
    Karl 

Children
Related