Hi, I hope everyone is fine. I’m trying to spin my X2216-5 2400KV motor with B-G431-ESC1, however the results are always the same. I have 3 boards, i have tried to spin my motor in every board, but result did not change. I’m using PlatformIO on VsCode. You can acces the files such as specs of my motor, digital oscilloscope image with the provided code and the code that i was trying to use, in the down below. Please help me about it, because I’m going to lose my mind over it. Once I’ve accomplished my goal “Spinning the motor via this esc”, i want to use AS5600 sensor for precision. After that i will try to make a custom pcb with this mcu or something else.
The code is nearly the copy of open_loop_velocity_example which is provided as an example.
// Open loop motor control example
#include <SimpleFOC.h>
// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(5, .029, 2400);
BLDCDriver6PWM driver = BLDCDriver6PWM(A_PHASE_UH, A_PHASE_UL, A_PHASE_VH, A_PHASE_VL, A_PHASE_WH, A_PHASE_WL);
// target variable
float target_velocity = 0;
// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char* cmd) {
float prev_target = target_velocity;
command.scalar(&target_velocity, cmd);
Serial.print("Target velocity changed from ");
Serial.print(prev_target);
Serial.print(" to ");
Serial.print(target_velocity);
Serial.println(" rad/s");
}
void doLimit(char* cmd) {
float prev_limit = motor.voltage_limit;
command.scalar(&motor.voltage_limit, cmd);
Serial.print("Voltage limit changed from ");
Serial.print(prev_limit);
Serial.print(" to ");
Serial.print(motor.voltage_limit);
Serial.println(" V");
}
void setup() {
// use monitoring with serial
Serial.begin(115200);
// enable more verbose output for debugging
SimpleFOCDebug::enable(&Serial);
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 12;
// limit the maximal dc voltage the driver can set
// as a protection measure for the low-resistance motors
// this value is fixed on startup
driver.voltage_limit = 6;
if(!driver.init()){
Serial.println("Driver init failed!");
return;
}
// link the motor and the driver
motor.linkDriver(&driver);
// limiting motor movements
// limit the voltage to be set to the motor
// start very low for high resistance motors
// current = voltage / resistance, so try to be well under 1Amp
motor.voltage_limit = 1.2; // [V]
// open loop control config
motor.controller = MotionControlType::velocity_openloop;
// init motor hardware
if(!motor.init()){
Serial.println("Motor init failed!");
return;
}
// add target command T
command.add('T', doTarget, "target velocity");
command.add('L', doLimit, "voltage limit");
Serial.println("Motor ready!");
Serial.println("Set target velocity [rad/s]");
_delay(1000);
}
void loop() {
// open loop velocity movement
// using motor.voltage_limit and set target_velocity
// to turn the motor "backwards", just set a negative target_velocity
motor.move(target_velocity);
// user communication
command.run();
}
platformio.ini file:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:disco_b_g431b_esc1]
board_build.f_cpu = 170000000L
platform = ststm32
board = disco_b_g431b_esc1
framework = arduino
monitor_speed = 115200
build_flags =
-D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF
-DCONFIG_DISABLE_DEBUG
-D USBCON
-D HAL_OPAMP_MODULE_ENABLED
-I driver
lib_archive = false
lib_deps =
https://github.com/simplefoc/Arduino-FOC
Motor Specs and the image of Motor:
I will be providing the image of the phases with my oscilloscope, if wanted.
Please help me about this situation.