Hi Sir,
I am new with B-G431B-ESC1 to run SimpleFOC.
My testing environment is PlatformIO.
I reference B-G431B-ESC1 code from Github Arduino-FOC-dev
My platformio.ini is below
[env:disco_b_g431b_esc1]
platform = ststm32
board = disco_b_g431b_esc1
framework = Arduino
monitor_speed = 115200
lib_deps=
SPI
Wire
The problem I met is,
I can compile and program, but I found there are no PWM outputs from G431 MCU.
Here is the driver definition in my code.
BLDCDriver6PWM driver = BLDCDriver6PWM(A_PHASE_UH, A_PHASE_UL, A_PHASE_VH, A_PHASE_VL, A_PHASE_WH, A_PHASE_WL);
I can find A_PHASE_UH, A_PHASE_UL, A_PHASE_VH, A_PHASE_VL, A_PHASE_WH, A_PHASE_WL define, and aligned with B-G431B-ESC1 sch.
But after I programed the code, it does not work (even I choice motor.controller = MotionControlType::velocity_openloop;)
I donāt know why.
here is my code for your information.
/**
- B-G431B-ESC1 position motion control example with encoder
*/
#include <SimpleFOC.h>
#include<Arduino.h>
// Motor instance
BLDCMotor motor = BLDCMotor(7);
BLDCDriver6PWM driver = BLDCDriver6PWM(A_PHASE_UH, A_PHASE_UL, A_PHASE_VH, A_PHASE_VL, A_PHASE_WH, A_PHASE_WL);
LowsideCurrentSense currentSense = LowsideCurrentSense(0.003, -64.0/7.0, A_OP1_OUT, A_OP2_OUT, A_OP3_OUT);
// encoder instance
// Encoder encoder = Encoder(A_HALL2, A_HALL3, 1000, A_HALL1);
Encoder encoder = Encoder(A_ENCODER_A, A_ENCODER_B, 1000);
// Interrupt routine intialisation
// channel A and B callbacks
void doA(){encoder.handleA();}
void doB(){encoder.handleB();}
void doC(){encoder.handleIndex();}
// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.motion(&motor, cmd); }
void setup() {
// initialize encoder sensor hardware
encoder.init();
encoder.enableInterrupts(doA, doB);
// link the motor to the sensor
motor.linkSensor(&encoder);
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 12;
driver.init();
// link the motor and the driver
motor.linkDriver(&driver);
// link current sense and the driver
currentSense.linkDriver(&driver);
// current sensing
currentSense.init();
// no need for aligning
// currentSense.skip_align = true;
motor.linkCurrentSense(¤tSense);
// index search velocity [rad/s]
// motor.velocity_index_search = 3;
// aligning voltage [V]
motor.voltage_sensor_align = 1.8;
// if you are not using aligning voltage, you can set current limitation
motor.phase_resistance = 0.35; // [Ohm]
motor.current_limit = 2; // [Amps] - if phase res is defined
// set motion control loop to be used
motor.controller = MotionControlType::velocity_openloop;
// contoller configuration
// default parameters in defaults.h
// velocity PI controller parameters
motor.PID_velocity.P = 0.2;
motor.PID_velocity.I = 20;
// default voltage_power_supply
motor.voltage_limit = 1;
// jerk control using voltage voltage ramp
// default value is 300 volts per sec ~ 0.3V per millisecond
motor.PID_velocity.output_ramp = 1000;
// velocity low pass filtering time constant
motor.LPF_velocity.Tf = 0.01;
// angle P controller
motor.P_angle.P = 20;
// maximal velocity of the position control
motor.velocity_limit = 4;
// use monitoring with serial
Serial.begin(115200);
// comment out if not needed
motor.useMonitoring(Serial);
motor.monitor_downsample = 100; // setting sample rate, can up to 100+
motor.monitor_variables = _MON_TARGET | _MON_VEL | _MON_ANGLE;
// initialize motor
motor.init();
// align encoder and start FOC
// motor.initFOC();
motor.target = 1;
// add target command T
command.add(āTā, doTarget, ātarget angleā);
Serial.println(F(āMotor ready.ā));
Serial.println(F(āSet the target angle using serial terminal:ā));
_delay(1000);
}
void loop() {
// main FOC algorithm function
//motor.loopFOC();
// Motion control function
//motor.move();
// function intended to be used with serial plotter to monitor motor variables
// significantly slowing the execution down!!!
motor.monitor();
// user communication
command.run();
// Debug encoder, done, everything is correct
// iterative function updating the sensor internal variables
// it is usually called in motor.loopFOC()
// not doing much for the encoder though
// encoder.update();
// display the angle and the angular velocity to the terminal
// Serial.print(encoder.getAngle());
// Serial.print(ā\tā);
// Serial.println(encoder.getVelocity());
}
Added two pictures here, the motor is ok, my self driver board can run the motor well.