Hi guys,
I want to control a PMSM motor iwth the FOC using an STM32F407. Just to test whether I can implementi it by myself, I don't want to use a library for that but I want to code it myself :-)
So far I have implemented the center aligned PWM signal generation and the encoder interface is also working. Using a three phase H bridge I still had on my bench is used as power stage, and with that, I can now rotate a motor using external commutation together with SVPWM. So far this was fairly easy. However for the next steps I have a few questions...
1) for the measurement of the phase current, I have added 2 shunt resistors and OpAmps to my H-bridge. To measure phase current, the ADC needs to be triggered in the phase where all 3 PWM signals are HIGH. How would you do that on STM32F4? I know there is a possibility to trigger the ADC on a PWM signal, but there are multiple possibilities to do it. Currently, I use TIM1 to generate the PWM signals on CH1, CH2 and CH3. I could either use CH4 as an internal signal to trigger the ADC or perhaps it is also possible to trigger the ADC when the timer overflows.
2) the motor which I want to use has both, an incremental encoder (1024 steps per turn) and hall sensors. On startup of the motor controller, I cannot know the rotor angle exactly, I can only read the hall sensors which gives a rough estimate of the rotor angle +/-30°. So at some point, I need to align the encoder to the hall sensors. How would I do that?