Cracking Noise at 0rad/s despite great alignment and no issues

Hello everyone,

I have a troubling problem where the motor (racerstar 4108 380kv) Would crackle at 0 rad/s.

The encoder as5048 runs fine with SPI. Furthermore, my esc the B-G431B was modded to use SPI3 and USART1 (communicating to ESP32) to debug and command. The setup works okay on open loop with no issues, however in closed loop, the motor is not responding at all, and produces cracking noise at 0 speed.

Open loop works fine, though it needs some PID tuning which is not tedious, however in closed loop, I am completely lost.

Here is the Code:

PlatformIO:

“[env:disco_b_g431b_esc1]

platform = ststm32

board = disco_b_g431b_esc1

framework = arduino

monitor_speed = 115200

;monitor_port = COM7

build_flags =

-D PIO_FRAMEWORK_ARDUINO_ENABLE_CDC

-D PIO_FRAMEWORK_ARDUINO_NANOLIB_FLOAT_PRINTF

-D HAL_UART_MODULE_ENABLED

-D HAL_OPAMP_MODULE_ENABLED

-D SERIAL_UART_INSTANCE=1

lib_archive = false

Main.cpp:

#include <Arduino.h>

#include <SimpleFOC.h>

HardwareSerial MyUART(USART1);

MagneticSensorSPI sensor = MagneticSensorSPI(PA15, 14, 0x3FFF);

SPIClass SPI_3(PB5, PB4, PB3);

BLDCMotor motor = BLDCMotor(11, 0.1, 380);

BLDCDriver6PWM driver = BLDCDriver6PWM(A_PHASE_UH, A_PHASE_UL, A_PHASE_VH, A_PHASE_VL, A_PHASE_WH, A_PHASE_WL);

LowsideCurrentSense current_sense = LowsideCurrentSense(0.003, -64.0/7.0, A_OP1_OUT, A_OP2_OUT, A_OP3_OUT);

Commander command = Commander(MyUART);

void doTarget(char* cmd) {

command.scalar(&motor.target, cmd);

}

void setup() {

// UART on PB6 TX / PB7 RX

MyUART.setTx(PB6);

MyUART.setRx(PB7);

MyUART.begin(115200);

SimpleFOCDebug::enable(&MyUART);

motor.useMonitoring(MyUART);

motor.monitor_variables = _MON_TARGET | _MON_VEL | _MON_ANGLE ;

motor.monitor_downsample = 100;

sensor.init(&SPI_3); // Rearranged to use custom SPI bus as per examples

motor.linkSensor(&sensor);

motor.LPF_angle.Tf = 0.01;

driver.voltage_power_supply = 24;

motor.voltage_limit = 24;

driver.pwm_frequency = 20500;

driver.init();

motor.linkDriver(&driver);

current_sense.linkDriver(&driver);

current_sense.init();

motor.linkCurrentSense(&current_sense);

// PID velocity parameters

// motor.PID_velocity.P = 0.01;

//motor.PID_velocity.I = 20;

//motor.PID_velocity.D = 0.001;

//smooths out noisy sensor signal

motor.PID_velocity.output_ramp = 1000;

//motor.LPF_velocity.Tf = 0.0001;

motor.current_limit = 3.6;

motor.torque_controller = TorqueControlType::voltage;

motor.foc_modulation = FOCModulationType::SinePWM;

motor.controller = MotionControlType::torque;

motor.init();

motor.initFOC();

command.add(‘T’, doTarget, “target velocity”);

}

void loop() {

motor.loopFOC();

motor.move();

command.run(); // handles incoming T commands + sends replies

}”

I am also not able to set speed. The motor would continue to crackle at T5 or T10. Thank you in advance for anyone who has any idea!

Here is the startupt messages

“MOT: Init

MOT: Enable driver.

MOT: Align sensor.

MOT: sensor_direction==CCW

MOT: PP check: OK!

MOT: Zero elec. angle: 0.06

MOT: Align current sense.

MOT: Success: 1

MOT: Ready.

AS5048A returns sporadic bad angles in my experience, which is likely what’s causing the motor to twitch. I used a simple spike filter which fixed it for low speed stepper motors, but I haven’t tried it at high speed. It just keeps a history of 3 readings, and if the middle one is significantly different than the other two, return the oldest, otherwise return middle.