Motor intialisation succses is depedent on UART baudrate

With the B-G431B-ESC1 driver, If I increase baudrate above 500000 bps, the ADC readings report close to 0 values. The serial output works, but the motor initialization fails:(I’ve added current logging during current sense alignment routine)

At baudrate of 500k:
11:27:53.991 → MOT: Init
11:27:54.475 → MOT: Enable driver.
11:27:54.992 → MOT: Align sensor.
11:27:57.184 → MOT: sensor_direction==CCW
11:27:57.184 → MOT: PP check: OK!
11:27:57.896 → MOT: Zero elec. angle: 3.20
11:27:58.089 → MOT: Align current sense.
11:27:59.186 → Ia: 1.05
11:27:59.186 → Ib: -0.63
11:27:59.186 → Ic: -0.57
11:28:00.284 → MOT: Success: 1
11:28:00.284 → MOT: Ready.
11:28:00.284 → Motor ready.

At 1M: (fail most of the time)
11:31:48.069 → MOT: Init
11:31:48.582 → MOT: Enable driver.
11:31:49.066 → MOT: Align sensor.
11:31:51.288 → MOT: sensor_direction==CCW
11:31:51.288 → MOT: PP check: OK!
11:31:51.994 → MOT: Zero elec. angle: 0.00
11:31:52.186 → MOT: Align current sense.
11:31:53.282 → Ia: -0.01
11:31:53.282 → Ib: -0.03
11:31:53.282 → Ic: -0.05
11:31:53.282 → CS: Err too low current, rise voltage!
11:31:53.282 → MOT: Align error!
11:31:53.282 → MOT: Init FOC failed.
11:31:53.282 → Motor ready.

I was suspecting a timing issue that, if the code is run too quickly, would prevent ADC to properly initialize, or something else, so I try to disable SimpleFOCDebug::enable(&Serial); and sure enough, the motor never get initialized.

I’ll try to add delays in the FOC internal initialization function to narrow this down, but I was curious to know if someone have an idea about this.

Also note that at the moment I’m using interupt based ABI encoder driver.

Here is my code

void setup() {
// use monitoring with serial
Serial.begin(115200);
// enable more verbose output for debugging
// comment out if not needed
SimpleFOCDebug::enable(&Serial);
encoder.init();
encoder.enableInterrupts(doA, doB);
motor.linkSensor(&encoder);
driver.voltage_power_supply = 16;  // power supply voltage \[V\]
driver.init();

motor.linkDriver(&driver);

currentSense.linkDriver(&driver);
currentSense.init();
motor.linkCurrentSense(&currentSense);

motor.voltage_sensor_align = 1;

motor.torque_controller = TorqueControlType::foc_current;
motor.controller = MotionControlType::torque;

motor.PID_current_q.P = 2.;
motor.PID_current_q.I = 1000.0;
motor.PID_current_d.P = 2.;
motor.PID_current_d.I = 1000.0;

motor.current_limit = 3.0;//A
motor.voltage_limit = 4.0;//V

//motor.useMonitoring(Serial);

// initialize motor
motor.init();
// align encoder and start FOC
motor.initFOC();
// 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(10000);
}