cancel
Showing results for 
Search instead for 
Did you mean: 

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

rwils.1
Associate III
 
3 REPLIES 3
rwils.1
Associate III

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

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

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