2024-08-23 05:01 AM
Hello,
I am using ADC1 channel 1, 3 and 5. All these three inputs are connected to different sensors and I want to create a driver to read those sensors. The problem is that I don't want to read all input channels at once, I want to be able to select which channel value to get. Also I want to use DMA and conversion complete interrupt. Is this possible? Which mode should I use to be able to tell ADC1 which channel value to convert? I am using HAL library. Right now I enabled scan mode, so after running HAL_ADC_Start_DMA() I get all sensors data.
Solved! Go to Solution.
2024-08-26 01:22 AM - edited 2024-08-26 01:23 AM
but it just seems weird that it is not possible to get analog value of just 1 channel when (for example) 16 channels are configured, it seems like an overkill to do all this conversion for just 1 channel.
This is how the ADC was designed to be able to do some advanced operations.
Using Scan mode does not affect your application perf as the ADC is doing it automatically. Otherwise, you need to stop conversion/configure new channel/ start conversion but this would affect your application perf.
2024-08-23 06:16 AM
Hello,
Right now I enabled scan mode, so after running HAL_ADC_Start_DMA() I get all sensors data.
Why Scan mode is not suitable for you? As you can read all the channels but at final you use the value you need.
2024-08-23 06:20 AM
You can convert a single channel at a time. After conversion, stop the ADC and reconfigure it to convert the next channel. You will need to reconfigure it on every conversion.
Seems easier to convert all channels at the same time. What's the drawback there?
2024-08-25 10:20 PM
this seems like a bit of overkill. I need 1 channel data, but I read (for example) 16 channels. I just feels like there should be possibility to read just 1 channel at the certain time.
2024-08-25 10:26 PM
Yeah it seems like this is the only way. For my case it doesn't really matter if I read 1 channel or all channels, because ADC reading is going to be used in DMA, but it just seems weird that it is not possible to get analog value of just 1 channel when (for example) 16 channels are configured, it seems like an overkill to do all this conversion for just 1 channel.
2024-08-26 01:22 AM - edited 2024-08-26 01:23 AM
but it just seems weird that it is not possible to get analog value of just 1 channel when (for example) 16 channels are configured, it seems like an overkill to do all this conversion for just 1 channel.
This is how the ADC was designed to be able to do some advanced operations.
Using Scan mode does not affect your application perf as the ADC is doing it automatically. Otherwise, you need to stop conversion/configure new channel/ start conversion but this would affect your application perf.
2024-08-26 06:28 AM
> I just feels like there should be possibility to read just 1 channel at the certain time.
It is possible. To do so, configure the ADC to convert a single channel before calling HAL_ADC_Start_DMA. This is a few lines of code.
2024-08-26 06:56 AM
but which channel will it convert? If, for example, I enable channel 3, 5, 9 on Cubemx? Can you give a short example?
2024-08-26 07:07 AM
CubeMX is not set up to have multiple configurations for the ADC. You can implement the switching in user code.