Hi, I am new to the world of BLDC motors and am trying to get my project off the ground but am having problems and I don’t know where I’m going wrong. I am trying to use the B-G431B-ESC1 board to drive a motor using open loop velocity. I am using the BE1806 1400KV and need to get 15000 RPM and will later tune FOC to get the motor to run more quietly. My current code generates this wave form which I know is wrong but i do not know what it indicates.
I have tried following the setup guide on SimpleFOC’s website but haven’t been able to get the motor spinning. The code i currently have is some modifications to the code generated by the SimpleFOCGenerator.
This is my platformio config file.
[env:disco_b_g431b_esc1]
platform = ststm32
board = disco_b_g431b_esc1
framework = arduino
monitor_speed = 115200
upload_protocol = stlink
build_flags =
;-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC
-D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF
-D PIO_FRAMEWORK_ARDUINO_USB_HIGHSPEED_FULLMODE
lib_deps=
askuric/Simple FOC @ ^2.0.2
SPI
Wire
This is what i currently have written.
#include <SimpleFOC.h>
// BLDC motor instance BLDCMotor(polepairs, (R), (KV))
BLDCMotor motor = BLDCMotor(7);
// BLDC driver instance BLDCDriver6PWM(phA_h, phA_l, phB_h, phB_l, phC_h, phC_l, (en))
BLDCDriver6PWM driver = BLDCDriver6PWM(A_PHASE_UH, A_PHASE_UL, A_PHASE_VH, A_PHASE_VL, A_PHASE_WH, A_PHASE_WL);
// BLDCDriver3PWM driver = BLDCDriver3PWM(A_PHASE_UH, A_PHASE_VH, A_PHASE_WH, A_PWM);
// position / angle sensor instance MagneticSensorPWM(PWM pin, minimum pulse, maximum pulse)
MagneticSensorPWM sensor = MagneticSensorPWM(A_PWM, 15, 18.5);
// inline current sense instance InlineCurrentSense(R, gain, phA, phB, phC)
InlineCurrentSense currentsense = InlineCurrentSense(0.003, -64.0/7.0, A_OP1_OUT, A_OP2_OUT, A_OP3_OUT);
// commander instance
Commander command = Commander(Serial);
void doTarget(char* cmd){command.motion(&motor, cmd);}
void setup() {
// start serial
Serial.begin(115200);
// initialize sensor
sensor.init();
// link sensor to motor
motor.linkSensor(&sensor);
// set power supply voltage
driver.voltage_power_supply = 22.2;
// set driver voltage limit, this phase voltage
driver.voltage_limit = 22.2;
// initialize driver
driver.init();
// link driver to motor
motor.linkDriver(&driver);
// link driver to current sense
currentsense.linkDriver(&driver);
// set motion control type to velocity
motor.controller = MotionControlType::velocity;
// set torque control type to FOC current
motor.torque_controller = TorqueControlType::foc_current;
// set FOC modulation type to sinusoidal
motor.foc_modulation = FOCModulationType::SinePWM;
// velocity PID controller
motor.PID_velocity.P = 1;
motor.PID_velocity.I = 0;
motor.PID_velocity.D = 0;
// set motor voltage limit, this limits Vq
motor.voltage_limit = 14.8;
// set motor velocity limit
motor.velocity_limit = 2120;
// set motor current limit, this limits Iq
motor.current_limit = .5;
// use monitoring
motor.useMonitoring(Serial);
motor.monitor_downsample = 1000;
// initialize motor
motor.init();
// initialize current sensing and link it to the motor
// https://docs.simplefoc.com/inline_current_sense#where-to-place-the-current_sense-configuration-in-your-foc-code
currentsense.init();
motor.linkCurrentSense(¤tsense);
// align sensor and start FOC
motor.initFOC();
motor.enable();
// add command to commander
command.add('M', doTarget, "target");
_delay(1000);
}
void loop() {
// main FOC algorithm function
// the faster you run this function the better
//motor.loopFOC();
// // this function can be run at much lower frequency than loopFOC()
motor.move(350);
// significantly slowing the execution down
motor.monitor();
// user communication
command.run();
}
Any help would be appreciated since I’m very new to this I am having trouble figuring out what is wrong.