2020-06-25 03:59 AM
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.
2020-06-25 06:53 AM
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.
2020-06-26 02:04 AM
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.