cancel
Showing results for 
Search instead for 
Did you mean: 

How to select ADC Channels for different measurements?

HHarj.1
Senior

Hey,

I have a project where I need to do a sequence of measurements and be able to select which test will be done. I'm using the stm32f469-discovery board and cubeMx/cubeIDE. Let's say I have ADC1 channel in use and input 1,2 and 3 in use for measurement 1. I have set up a scan mode conversion with DMA and it works nicely. Then I would like to do an other measurement which has to use the same ADC1 channel but this time input channels 4 and 5. It's not quite clear to me how can I select only these two channels since the adc settings have been set up for measurement 1. Is this even possible with cubeMX or do I have to do those settings in some other way?

1 ACCEPTED SOLUTION

Accepted Solutions
berendi
Principal

You can perhaps use the injected conversion feature.

Each ADC controller supports two conversion sequences. There is the regular sequence, that's probably what you are using now, and there is the injected sequence.

The injected sequence can contain up to 4 channels, configured in the ADC->JSQR register. You can then start the injected sequence by setting ADC_CR2_JSWSTART, the regular sequence will be paused, the injected conversion results will be stored in ADC->JDR1 ... JDR4, and the ADC_SR_JEOC bit will set when the injected sequence is complete. Each channel gets its own data register, so the results can be read directly from the JDR registers, no need to use DMA.

I don't know how to set it up with Cube or HAL, but if the ADC is otherwise already running, using the registers above is straightforward.

View solution in original post

2 REPLIES 2
berendi
Principal

You can perhaps use the injected conversion feature.

Each ADC controller supports two conversion sequences. There is the regular sequence, that's probably what you are using now, and there is the injected sequence.

The injected sequence can contain up to 4 channels, configured in the ADC->JSQR register. You can then start the injected sequence by setting ADC_CR2_JSWSTART, the regular sequence will be paused, the injected conversion results will be stored in ADC->JDR1 ... JDR4, and the ADC_SR_JEOC bit will set when the injected sequence is complete. Each channel gets its own data register, so the results can be read directly from the JDR registers, no need to use DMA.

I don't know how to set it up with Cube or HAL, but if the ADC is otherwise already running, using the registers above is straightforward.

HHarj.1
Senior

Thank you! That worked.