- This topic has 1 reply, 2 voices, and was last updated 7 years, 11 months ago by .
Viewing 2 posts - 1 through 2 (of 2 total)
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.
Home › Forums › Mastering STM32 book support forum › Changing ADC channels in Single Channel Mode
Tagged: ADC Channel HAL
I am using a STM32F334C8 processor with STM32CubeMX and Keil uVision5 tool chain and need to measure a number of ADC voltages in a high speed state machine (10us loop time). I have successfully converted all of the channels using DMA into an array but prefer to convert the channels individually in the corresponding machine states. I can convert a single channel using HAL_ADC_Start(), HAL_ADC_PollForConversion, HAL_ADC_GetValue and HAL_ADC_Stop(). However, I have not found a way to select a different ADC channel using HAL_ADC_ConfigChannel to select a different channel number. It stays converting the first channel. Do you have an example of code to do a manual channel change?
Kind regards
Steve H
Your issues is generated by the fact that the HAL_ADC_ConfigChannel() function does not take care of disabling already enabled channels. This causes that the first channel is still enabled, and the ADC starts sampling from it. I don’t know if the HAL provides a macro to clear a channel configuration. I’ve to take a look. Otherwise you need to work at peripheral registers level.
You may easily reset the ADC entirely by gating its clock, using the macro __HAL_RCC_ADC12_CLK_DISABLE(), and then re-enabling it again. However, I don’t know how much time all these operation requires. Your requirement about 10uS sampling rate is not trivial, and I think that it is best to perform a scan conversion sequence and to extract individual channel values by hand.