ADC Polling for multiple channel not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-13 10:12 PM
i am trying to use multiple channel on a single ADC to measure certain voltages. what i have noticed is that let say i have selected 3 channels now in configuration of cube MX i select no of conversion to 3 and as soon as i do that Ranks get added below where i can select channel for each rank and choose that.
Code:
HAL_ADC_Start(&hadc1);
HAL_ADC_PollForConversion(&hadc1,HAL_MAX_DELAY);
float voltage1 = HAL_ADC_GetValue(&hadc1)*(3.3/4096);
HAL_ADC_PollForConversion(&hadc1,HAL_MAX_DELAY);
float voltage2 = HAL_ADC_GetValue(&hadc1)*(3.3/4096);
HAL_ADC_PollForConversion(&hadc1,HAL_MAX_DELAY);
float voltage3 = HAL_ADC_GetValue(&hadc1)*(3.3/4096);
now when i run this code i get same output for all the conversion. the output is of the channel with rank 3. If i set the channel with rank 3 to ground i get output as 0 for all the conversion as is the channel with last rank is dominating over other. Is there something wrong in my configuration or the coding part.
PS: i am using STM32F103ZGT6 which has 12 bit ADC resolution
cube MX configuration:
Solved! Go to Solution.
- Labels:
-
ADC
-
STM32F1 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-14 5:33 AM
Use DMA to convert multiple ADC channels. The CPU is not going to keep up with the rate of conversion in general, but especially when the sampling time is only 1.5 cycles.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-14 5:33 AM
Use DMA to convert multiple ADC channels. The CPU is not going to keep up with the rate of conversion in general, but especially when the sampling time is only 1.5 cycles.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-14 5:37 AM
is that the only way? DMA. i mean all want is to read data when i am asking it, I can change the sampling time if needed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-08-14 6:07 AM
> is that the only way?
That is what the reference manual says. It's certainly the most straightforward way and least likely to cause issues.
Possibly you could read ADC->DR quickly enough, with a slow enough sampling rate, with interrupts disabled, you could poll for the values.
Another method would be to convert a single channel and change which channel is being converted after each conversion.
