AnsweredAssumed Answered

STM32 ADC1 regular + ADC2 and ADC3 in injected mode

Question asked by Max on Aug 24, 2015
Latest reply on Aug 25, 2015 by Clive One
Hi All,
I've some problem configuring the ADCs of a STM32F407.
I have 2 motors connected to my board that I drive with 2 different pwm.
For the 1st motor I use a pwm from PE9 (TIM1 CH1)
For the 2nd motor I use a pwm from PE13 (TIM1_CH3)


I need to sample the bemf in the middle of the PWM Toff;
also I need to sample the current in the middle of the PWM Ton and in the middle of the Toff.


MOTOR1 bemf analog pin is connected to PC2 = ADC123_IN12;
MOTOR2 bemf analog pin is connected to PA0 = ADC123_IN0;
MOTOR1 current sensor analog pin is connected to PA5 = ADC12_IN5;
MOTOR2 current sensor analog pin is connected to PA3 = ADC123_IN3.


I also need to sample other analog pins connected to:
PB0 = ADC12_IN8
PB1 = ADC12_IN9
and also Vrefint, Temp, Vbat


I'd like to achieve that in the following way:
ADC1 in regular mode for PB0, PB1, PC2, PA0, PA5, PA3, Vrefint, Temp and Vbat
(in this way I'll use the bemf and current values from this ADC when the PWMs are 0% and 100%)


ADC2 in injected mode for PC2 (MOTOR1 bemf) and PA5 (MOTOR1 current)
ADC3 in injected mode for PA0 (MOTOR2 bemf) and PA3 (MOTOR2 current)


At the moment I'm ok with the ADC1 configuration.
How I can configure ADC2 and ADC3 to do this?
Also how I know when the sample is taken in the middle of the Ton or in the middle of the Toff?

Someone have some sample code?

Thanks

Outcomes