About 6 PWM drive board

I use fd228t to make a drive board, and use esp32’s 6 PWM to drive the motor. In the open loop, the speed and position are normal, but in the closed loop, both the position and the speed do not turn. In doubt, please have a look! thank you!

Open loop code:

// Open loop motor control example
#include <SimpleFOC.h>


// BLDC motor & driver instance
// BLDCMotor motor = BLDCMotor(pole pair number);
//BLDCMotor motor = BLDCMotor(11);
BLDCMotor motor = BLDCMotor(7);
// BLDCDriver3PWM driver = BLDCDriver3PWM(pwmA, pwmB, pwmC, Enable(optional));
//BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
BLDCDriver6PWM driver = BLDCDriver6PWM(25, 12, 26, 13, 27, 14);
// Stepper motor & driver instance
//StepperMotor motor = StepperMotor(50);
//StepperDriver4PWM driver = StepperDriver4PWM(9, 5, 10, 6,  8);


//target variable
float target_velocity = 0;

// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target_velocity, cmd); }

void setup() {

  // driver config
  // power supply voltage [V]
 //   driver.pwm_frequency = 50000;
 //  driver.dead_zone = 0.05;
   
  driver.voltage_power_supply = 8;
  driver.init();
  // link the motor and the driver
  motor.linkDriver(&driver);

  // limiting motor movements
  motor.voltage_limit = 1;   // [V]
  motor.velocity_limit =20; // [rad/s] cca 50rpm
 
  // open loop control config
  motor.controller = MotionControlType::velocity_openloop;

  // init motor hardware
  motor.init();

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

  Serial.begin(115200);
  Serial.println("Motor ready!");
  Serial.println("Set target velocity [rad/s]");
  _delay(1000);
}

void loop() {

  // open loop velocity movement
  // using motor.voltage_limit and motor.velocity_limit
  motor.move(target_velocity);

  // user communication
  command.run();
}

Closed loop code:

#include <SimpleFOC.h>

// BLDC motor & driver instance
//BLDCMotor motor = BLDCMotor(11);
BLDCMotor motor = BLDCMotor(7);
//BLDCDriver3PWM driver = BLDCDriver3PWM(9, 5, 6, 8);
BLDCDriver6PWM driver = BLDCDriver6PWM(25, 12, 26, 13, 27, 14);
// Stepper motor & driver instance
//StepperMotor motor = StepperMotor(50);
//StepperDriver4PWM driver = StepperDriver4PWM(9, 5, 10, 6,  8);

// encoder instance
Encoder encoder = Encoder(5, 18, 4096);
//Encoder encoder = Encoder(5, 18, 4096, A0);
// Interrupt routine intialisation
// channel A and B callbacks
void doA() {
  encoder.handleA();
}
void doB() {
  encoder.handleB();
}

// If no available hadware interrupt pins use the software interrupt



// velocity set point variable
float target_velocity = 0;
// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char* cmd) {
  command.scalar(&target_velocity, cmd);
}


void setup() {



  // initialize encoder sensor hardware
  encoder.init();
  encoder.enableInterrupts(doA, doB);
  // software interrupts

  // link the motor to the sensor
  motor.linkSensor(&encoder);

  // driver config
  // power supply voltage [V]
  // pwm frequency to be used [Hz]
  driver.pwm_frequency = 40000;
  driver.dead_zone = 0.04;
  driver.voltage_power_supply = 8;
  driver.init();
  // link the motor and the driver
  motor.linkDriver(&driver);

  // aligning voltage [V]
  motor.voltage_sensor_align = 1;
  // index search velocity [rad/s]
  motor.velocity_index_search = 3;

  // set motion control loop to be used
  motor.controller = MotionControlType::velocity;

  // contoller configuration
  // default parameters in defaults.h

  // velocity PI controller parameters
  motor.PID_velocity.P = 0.15;
  motor.PID_velocity.I = 10;
  motor.PID_velocity.D = 0;
  // 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;

  // use monitoring with serial
  Serial.begin(115200);
  // comment out if not needed
  motor.useMonitoring(Serial);

  // initialize motor
  motor.init();
  // align sensor and start FOC
  motor.initFOC();

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

  Serial.println(F("Motor ready."));
  Serial.println(F("Set the target velocity using serial terminal:"));
  _delay(1000);
}


void loop() {
  // main FOC algorithm function
  // the faster you run this function the better
  // Arduino UNO loop  ~1kHz
  // Bluepill loop ~10kHz
  motor.loopFOC();

  // Motion control function
  // velocity, position or voltage (defined in motor.controller)
  // this function can be run at much lower frequency than loopFOC() function
  // You can also use motor.move() and set the motor.target in the code
  motor.move(target_velocity);

  // function intended to be used with serial plotter to monitor motor variables
  // significantly slowing the execution down!!!!
  // motor.monitor();

  // user communication
  command.run();
}

Hey @feng,

we need a bit more info.
Did you test your encode?
Is the pole pairs number corrcet?
What does it mean that it is not normal?
Can you provide the monitor output of the initFOC so we can see if the align went well?

Hi@Antun_ Skuric

This is the schematic:

The motor is: https://www.bauer-modelle.com/epages/Bauer_ Uwe46269592.mobile/de_ DE/?ObjectPath=/Shops/Bauer_ Uwe46269592/Products/4.353635&ViewAction=ViewProduct


In the process of operation, electrode check error:

MOT: Monitor enabled!

MOT: Init

MOT: Enable driver.

MOT: Align sensor.

MOT: sensor_ direction==CCW

MOT: PP check: fail - estimated pp:26.6840

MOT: Zero elec. angle: 4.74

MOT: No current sense.

MOT: Ready.

Motor ready.

Set the target velocity using serial terminal:

Later, I directly annotated the library file check electrode detection:
“BLDCMotor.cpp”
/*
// check pole pair number
if(monitor_port) monitor_port->print(F("MOT: PP check: "));
float moved = fabs(mid_angle - end_angle);
if( fabs(moved*pole_pairs - _2PI) > 0.5 ) { // 0.5 is arbitrary number it can be lower or higher!
if(monitor_port) monitor_port->print(F(“fail - estimated pp:”));
if(monitor_port) monitor_port->println(_2PI/moved,4);
}else if(monitor_port) monitor_port->println(F(“OK!”));
*/
}else if(monitor_port) monitor_port->println(F(“MOT: Skip dir calib.”));
But the result is the same.
All the process is like this, I don’t know where to go wrong?Please help to solve it! Thank you!