Skip to main content
rwils.1
Associate III
June 23, 2022
Question

I can read from any ADC port and output a reasonable value by changing the MX_ADC1 init code but I can't work out how to change the channel once the code is running. Is there an app note or firmware example showing how to change ADC channels? Thanks

  • June 23, 2022
  • 2 replies
  • 687 views

..

This topic has been closed for replies.

2 replies

rwils.1
rwils.1Author
Associate III
June 24, 2022

To answer my own question, you have to set the Rank and the Sampling Time after selecting a new channel.

 sConfig.Channel = ADC_CHANNEL_13;

 sConfig.Rank = ADC_REGULAR_RANK_1;

 sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;

 if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)

 {

   Error_Handler();

 }

I'd be interested if there are any other solutions, this seems cumbersome.

raptorhal2
Lead
June 24, 2022

The typical implementation for more than one channel is to use DMA and convert all channels with one start. Channel, Rank and SampleTime configuration initialization for each channel provides complete flexibility for such a sequence.

Is your application not typical?

Cheers, Hal

rwils.1
rwils.1Author
Associate III
June 27, 2022

Thanks for your reply Hal,

The application is a multi-channel logger with selective channels, nothing particularly unique. I think that I am just used to other controllers that require a channel selection and then a channel conversion , this is just a different way to think about sampling, i wasn't aware that this is how it is meant to work.

Cheers

Richard