Skip to main content
Associate III
September 13, 2024
Question

ADC synchronization motor control

  • September 13, 2024
  • 1 reply
  • 1523 views

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.

    1 reply

    waclawek.jan
    Super User
    September 17, 2024

    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

    Associate III
    September 17, 2024

    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 

    unnamed.jpg

    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