6pwm driver stuck at 4khz (noisy)

hi!

i have an esp32 connected to a 6pwm driver with a as5600 encoder via i2c.
if i run the closed loop sketches there is a distinct 4khz (250us cycle) whine coming from the motor.
trying to change the driver.pwm_frequency has no impact as far as i can tell.

how can i go about fixing this?
the issue is consistent across multiple esp32 boards.

if i run 2 motors closed loop with 1 esp32 the 4khz whine remains rock steady.
(if i ground or touch random solder joints it sometimes changes to a 2.66khz (375us cycle) so thats also strange)

i got the same result with a battery as power-supply.
i think the board itself works because in openloop the driver works nicely with 20khz and up.

i hope this is solvable and not a flaw of the setup that i’m using.
here’s the code:

#include <SimpleFOC.h>

MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);
BLDCMotor motor = BLDCMotor(7);
BLDCDriver6PWM driver = BLDCDriver6PWM(14, 27, 26, 25, 33, 32);

float target_velocity = 6.2;

void setup() {
 
 Serial.begin(115200);

 Wire.setClock(400000);
 sensor.init();
 motor.linkSensor(&sensor);

 driver.pwm_frequency = 100000;
 driver.voltage_power_supply = 12;
 driver.init();
 motor.linkDriver(&driver);
 
 motor.controller = MotionControlType::velocity;
 motor.PID_velocity.P = 0.2;
 motor.PID_velocity.I = 8;
 motor.PID_velocity.D = 0;
 motor.voltage_limit = 6;
 motor.PID_velocity.output_ramp = 1000;
 motor.LPF_velocity.Tf = 0.01;

 motor.init();

 motor.initFOC();

 Serial.println(F("Motor ready."));
 _delay(1000);
}
void loop() {

 motor.loopFOC();

 motor.move(target_velocity);

}

i just found that my library’s and board’s were not up to date(after spending multiple days on this issue). now i feel stupid but im having a lot of fun so i would still want to thank the makers and all participants of this cool library! i am enjoying it a lot.

Hey @Berend ,

I am not sure that I know what is the issue :smiley:
Which library version were you using?
Can you give us a hint what did you have to change?

hi Antun!

i do not know exactly which versions i previously had. but i think approx. 1 year old
it just worked so never had a reason to update until now.
but i reinstalled/updated the simpleFOC library to v2.2.0
and the esp32 boards to v1.0.6

after updating one of these i tested it, and there were issues with a sync and a mcpwm file, they maybe are related to this problem.

hope this helps!