2024-09-13 03:41 AM
Hi I've been trying to read the current values from the 3 phases of my BLDC motor for doing FOC and i need to measure the current when the low side MOSFETs are on. I'm using TIM1 CH1 CH2 CH3 in Center aligned mode 1.
How do i configure the ADC so that the they start the conversion in the middle of the PWM signal.
2024-09-17 07:45 AM
Which STM32?
One way to tackle this might be to set TIM1_CCR4 to the same value as TIM1_ARR, so that there's a match at the center of the pulse, and then set TIM1_CR2.MMS to OC4REF to generate TIM1_TRGO upon that match, and use TIM1_TRGO to trigger the ADC, if in given STM32 the ADC supports this.
JW
2024-09-17 08:41 AM
Thanks for the reply @waclawek.jan
The MCU i'm using is STM32G431CBT6Right now i ended with ADC trigger as TIM1_TRGO and using the TIM1 CH4 as the ADC trigger also the i have set the TIM1_CR2.MMS to OC4REF
since timer1 is set to center alignment, the TRGO/CH4 will also be in the center
Although the ADC is triggered on rising edge, ADC sampling takes time,by adjusting the pulse width of TRGO and the adc sampling time, it can sample close to the center
Also your idea might be good setting the TIM1_CCR4 to the same value as TIM1_ARR, so that there's a match at the center of the pulse i'll try that