cancel
Showing results for 
Search instead for 
Did you mean: 

Brushless motor control using a STM32F302RB

OS'HI
Associate II

Hi!

I'm trying to control a brushless motor using a STM32F302RB and X-NUCLEO-IHM08M1.

But the motor is not spining!!

I need your help !

best regards!

I'm using mbed online compiler to configurate TIM1_CH1 pin (PA8)

�? TIM1_CH1N pin (PA7)

�? TIM1_CH2 pin (PA9)

�? TIM1_CH2N pin (PB0)

�? TIM1_CH3 pin (PA10)

�? TIM1_CH3N pin (PB1)

>>

PwmOut mypwmA(PA_8);  

PwmOut mypwmB(PA_9); 

PwmOut mypwmC(PA_10);

PwmOut mypwmA1(PA_7);  

PwmOut mypwmB1(PB_0); 

PwmOut mypwmC1(PB_1);

DigitalOut myled(LED1);

DigitalIn mybutton(USER_BUTTON);

DigitalOut EN1(PC_10);

DigitalOut EN2(PC_11);

DigitalOut EN3(PC_12);

DigitalOut ld2(PB_13);

int main()

{ EN1=1;

  EN2=1;

  EN3=1;

   

  mypwmA.period_us(20); 

  mypwmB.period_us(20);

  mypwmC.period_us(20);

   mypwmA1.period_us(20); 

  mypwmB1.period_us(20);

  mypwmC1.period_us(20);

while(1) {

  mypwmA.write(0.5f);

  mypwmB.write(0);

  mypwmC.write(0);

  mypwmA1.write(0.5f);

  mypwmB1.write(0);

  mypwmC1.write(0);

   wait_ms(2);

   mypwmA.write(0);

  mypwmB.write(0.5f);

  mypwmC.write(0);

  mypwmA1.write(0);

  mypwmB1.write(0.5f);

  mypwmC1.write(0);

      

   

  wait_ms(2);

  mypwmA.write(0);

  mypwmB.write(0);

  mypwmC.write(0.5f);

  mypwmA1.write(0);

  mypwmB1.write(0);

  mypwmC1.write(0.5f);

   

  wait_ms(2);

  }

  }

8 REPLIES 8

Hi! I already download x-cube-spn8 but the code has only libraries! I want build my own programme so I need to know what signals should I send In Tim1_CH (in 3 phases of the motor) to make it spin!!

Thank you!

john doe
Lead

there's examples with full source code included that use the libraries. the board support package has drivers with complete source code.

AFras
Associate II

Your example code above will not drive a brushless motor correctly. If you have hall effect sensors you need to monitor them to decide which phases to energise next. If your motor does not have hall effect sensors then you need sensorless determination of the rotor position which is quite complicated (requires detection of back EMF).

I need to know first what signals should I send In Tim1_CH (in 3 phases of the motor) and Tim1_CHN ( 3 complementry CH) to make the motor spin , then use the  hall effect sensors to send the signals in the correct order!

am i right ? if you have any information please I need help!

Fred V.
ST Employee

Hello...

I'm not sure I read your code well, I know nothing about MBED. However, your code suggests that you always close TIM_CHx and TIM_CHxN at the same time. This cannot make the motor spin. Actually, doing this is dangerous for your hardware (X-NUCLEO-IHM08M1) as you create a short circuit... TIM_CHx and TIM_CHxN shall never be on at the same time.

Spinning a motor will require a little more than this anyway. Two things you can do:

  • visit this page that will provide you with lots of information on motor control: https://www.st.com/content/st_com/en/applications/motor-control/pmsm-bldc-motors/3-phase-6-step-control.html
  • If you're not happy with x-cube-spn8, maybe can you try with x-cube-spn7 (https://my.st.com/content/my_st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-expansion-packages/x-cube-spn7.license=1543297075281.product=X-CUBE-SPN7.version=1.1.0.html) that comes with full source code. Analysing its code will let you understand what you should send to the phases of the motor.

Finally, the characteristics of your motor are important here. Do they fit with the board? You're trying to spin the motor at 10 000 rpm. Can this motor stand such a speed? Is an acceleration phase scheduled in your code?

Hi!

First Thank you for your reply !

I think the motor characteristics fit with the board cuz I already spin the motor with the binary file that I found in  x-cube-spn8.

 Analysing the source Code is a bit hard cuz there are lot of libraries calls that I dont understand !

My problem is I know the pins (Timer1 6 x pins) but I dont know what signals should I send on them and How!!

Ps: while spenning the motor with  x-cube-spn8 binary file and using an oscilloscope I found the folowing signals:

1) on TIM1_CH1,2 and 3

2) on TIM1_CH1N,2N and 3N

3)on motor's outs

I really need your Help!

Thank you0690X000006CUb5QAG.jpg

0690X000006CUbFQAW.jpg

0690X000006CUbKQAW.jpg

dlang
Associate

Hello oussama.shis1.5425675341255417E12 I am working on the same project and would like to know more about you and your project maybe we have useful information that we can exchange. You can just send me an email at dennislang369@gmail.com

LG Dennis from Germany

nochmal in Deutsch 🙂

Hallo oussama.shis1.5425675341255417E12 ich arbeite an demselben Projekt und würde gern mehr über dich und dein Projekt erfahren vielleicht haben wir nützliche Informationen die wir austauschen können. Du kannst mir einfach eine mail schreiben unter dennislang369@gmail.com

LG Dennis aus Deutschland