Skip to main content
Jorgen1
Associate
June 25, 2020
Question

How can I read all the used ADC channels spread out on all three converters?

  • June 25, 2020
  • 2 replies
  • 788 views

I have a configuration where I have 24 single-ended ADC channels distributed on all three ADC channels.

I have not found any example how to read more than one channel.

All channels should be read every 20ms, so there's enough time. But I don't know if it's best to setup three subsequent DMA operations to get a single sample for each channel on each converter, or if regular polling can be done in some kind of optimized way.

This is the way I made it work, but I guess it can be done better.

 sConfig.Rank = ADC_REGULAR_RANK_1;
 sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
 sConfig.SingleDiff = ADC_SINGLE_ENDED;
 sConfig.OffsetNumber = ADC_OFFSET_NONE;
 sConfig.Offset = 0;
 for (int i = 0 ; i < ADC_CHANNEL_COUNT ; i++)
 {
 sConfig.Channel = m_channels[i].channel;
 ASSERT( HAL_ADC_ConfigChannel(m_channels[i].p_handle, &sConfig) == HAL_OK );
 
 ASSERT( HAL_ADC_Start(m_channels[i].p_handle) == HAL_OK );
 ASSERT( HAL_ADC_PollForConversion(m_channels[i].p_handle, 10) == HAL_OK );
 ASSERT( HAL_ADC_Stop(m_channels[i].p_handle) == HAL_OK );
 *(m_channels[i].p_last_raw) = HAL_ADC_GetValue(m_channels[i].p_handle);
 }

Any help appreciated.

Cheers,

Jorgen.

This topic has been closed for replies.

2 replies

TDK
June 25, 2020

When converting more than 1 channel, you need to use DMA to avoid an overflow in ADC->DR. What chip? I'm sure there's an example in a CubeMX repository.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Jorgen1
Jorgen1Author
Associate
June 26, 2020

We are using STM32H750.

There are examples on using DMA, but I didn't find anything showing or explaining what to do when all three converters are used.