B-G431B-ESC Motor Not Spin, Help Please

Hi Everyone,

I’m new to this forum. I wish to drive a brushless motor(customized, already attached the motor specs) with the B-G431B-ESC.
I have properly set up the Arduino IDE but the motor is not spinning even with a very simple program… Here’s my code. Really need your help.
motor

#include <SimpleFOC.h>
#include <Arduino.h>

const int motorPolePairs = 4;

//Motor and driver instance
BLDCMotor motor = BLDCMotor(motorPolePairs);
BLDCDriver6PWM driver = BLDCDriver6PWM(PHASE_UH, PHASE_UL, PHASE_VH, PHASE_VL, PHASE_WH, PHASE_WL);
float targetSpeed = 20;
Commander command = Commander(Serial);

void doTarget(char *cmd) { command.scalar(&targetSpeed, cmd); }

void setup()
{

pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
sensor.init();
sensor.enableInterrupts(doA, doB, doC);

driver.voltage_power_supply = 12;
driver.init();

motor.phase_resistance = 0.1; // [Ohm]
motor.current_limit = 2;      // [Amps] - if phase resistance defined
                              //    motor.voltage_limit = 0.5; // [V] - if phase resistance not defined
motor.velocity_limit = 50;    // [rad/s] 5 rad/s cca 50rpm

//Control loop setup
motor.controller = MotionControlType::velocity_openloop;

//Init motor
motor.linkSensor(&sensor);
motor.linkDriver(&driver);
motor.useMonitoring(Serial);
motor.init();

// add target command T
command.add('T', doTarget, "target");
command.add('t', doTarget, "target");

Serial.println("Motor ready!");
Serial.println("Set target velocity [rad/s]");

delay(1000);

}

void loop()
{
//Motor loop, as quick as possible
motor.move(targetSpeed);

//User communication
command.run();

//Monitoring
//    motor.monitor();

}

Hi @shadowban

I would start trying to use BLDCDriver3PWM , if you use BLDCDriver6PWM is important that PHASE_UH and PHASE_UL belong to one timer, PHASE_VH and PHASE_VL to second timer and PHASE_WH and PHASE_WL to the last timer… each pair has to belong to the same timer as is explained here

Hi @JorgeMaker,
Thank you for your reply. Yes they are properly assigned to different timers for each pair. I played a bit with the driver.pwm_frequency still no results.
I followed Owen’s tutorial as https://www.youtube.com/watch?v=ufMs83Y3sXg&t=620s
But still no spinning…

Hey, could you post the output of the monitoring, in particular the motor initialisation? Not many users use 4PP motors I think.

Does the sensor output make sense, independent of the motor?

I’m afraid your motor specs image came out a little small, and I can’t read much of it…

Hi @runger,

Thank you for your reply. About the image, you can right click the image and select open in a new tab. I tried myself it works.
As for the monitoring, I will have a look when I get back to office tomorrow.
The motor comes with 3 hall sensors, but I didn’t enable them in the program. I just wish to spin it with the openloop velocity. I have stuck there for a couple of day and really frustrated…

@shadowban

Could you please check this thread it may help?

Hi @Valentine,
Thank you for your feed back. Yes, I followed that thread step by step finishing set-up.
But still failed.
By the way, when I run the ST Motor Profiler program, the motor can spin easily. So my motor and hall sensors are both working…

That’s interesting. It means the hardware is set up just alright.

Did you check with oscilloscope?

In that case it could be the Arduino IDE setup is not exactly right. These types of problems due to one’s development environment are extremely hard to debug that’s why you don’t see too many people giving you feedback. If you read my post, I spun up a virgin environment to eliminate any software or hardware interference. I had a similar issue where one small change in the STM32 target or optimization level halted the MCU. Very hard to debug remotely.

1 Like

You’re right, I could see it that way.

True enough, it should not matter, since you aren’t using it…

Your voltage_limit winds up being 0.2V (0.1Ω x 2A) - maybe this is a little low for the motor? I would not raise it much, but perhaps a little bit? How is the motor behaving? Does it shake and make noise, or is there no reaction at all?

@JorgeMaker @runger @Valentine @Owen_Williams
Hi Everyone,

Still not spining… My environment is fresh new Arduino IDE + STM32Duino v2.0.0 + Simple FOC
Tried: Flashing LED_BuiltIn (Success, means my arduino environment works), ST Motor Profiler(Motor spins and speed controllable, means my hardware works)

Here’s my Serial Monitoring results:

20.0000 -12345.0000 20.0000 5.5609
20.0000 -12345.0000 20.0000 5.7402
20.0000 -12345.0000 20.0000 5.9189
20.0000 -12345.0000 20.0000 6.1009
20.0000 -12345.0000 20.0000 6.2814
20.0000 -12345.0000 20.0000 0.1682
20.0000 -12345.0000 20.0000 0.3391
20.0000 -12345.0000 20.0000 0.5124
20.0000 -12345.0000 20.0000 0.6855
20.0000 -12345.0000 20.0000 0.8591
20.0000 -12345.0000 20.0000 1.0336
20.0000 -12345.0000 20.0000 1.2076
20.0000 -12345.0000 20.0000 1.3848

#include <BLDCMotor.h>
#include <StepperMotor.h>
#include <SimpleFOC.h>
#include <Arduino.h>

const int motorPolePairs = 4;

BLDCMotor motor = BLDCMotor(motorPolePairs);
BLDCDriver6PWM driver = BLDCDriver6PWM(PA8, PC13, PA9, PA12, PA10, PB15);
// BLDCDriver6PWM driver = BLDCDriver6PWM(A_PHASE_UH, A_PHASE_UL, A_PHASE_VH, A_PHASE_VL, A_PHASE_WH, A_PHASE_WL);
float targetSpeed = 20;
Commander command = Commander(Serial);

void doTarget(char *cmd) { command.scalar(&targetSpeed, cmd); }

void setup() {
pinMode(PC6, OUTPUT);
Serial.begin(115200);
driver.voltage_power_supply = 12;
motor.voltage_limit = 2; // [V] - if phase resistance not defined
motor.controller = MotionControlType::velocity_openloop;
motor.linkDriver(&driver);
motor.useMonitoring(Serial);
motor.init();
driver.init();
delay(1000);
// add target command T
command.add(‘T’, doTarget, “target”);
command.add(‘t’, doTarget, “target”);
Serial.println(" Motor ready!");
Serial.println(“Set target velocity [rad/s]”);
delay(1000);
}

void loop() {
// put your main code here, to run repeatedly:
// digitalWrite(PC6, HIGH);
// delay(50);
//// delay(200);
// digitalWrite(PC6, LOW);
// delay(50);
//// delay(200);

//Motor loop, as quick as possible
motor.move(targetSpeed);

//User communication
command.run();

//Monitoring
motor.monitor();

}

Are you enabling your driver ? You use BLDCDriver6PWM with only 6 parameters … not sure if you are enabling your driver.

// BLDCDriver6PWM( int phA_h, int phA_l, int phB_h, int phB_l, int phC_h, int phC_l, int en)
// - phA_h, phA_l - A phase pwm pin high/low pair
// - phB_h, phB_l - B phase pwm pin high/low pair
// - phB_h, phC_l - C phase pwm pin high/low pair
// - enable pin - (optional input)

@Valentine @Owen_Williams @JorgeMaker @runger
I think I found the bug. PA_10 was commented in this peripheral file variants/STM32G4xx/G431C(6-8-B)U_G441CBU/PeripheralPins_DISCO_B_G431B_ESC1.c
I’m not sure if it’s on purpose but I uncommented PA-10 for myself.

Have you tried providing an enable pin or pulling up the pin connected to your controller anable be yourself?