Glitch during open loop PWM on esp32


(Even channels are high side, odd channels are low side)

I’ve been trying the library on ESP32 with a simple transistor driver and the movement wasn’t very smooth. I tried a few motors, including a gimbal motor with barely any perceptible cogging when turning by hand. But when driven by SimpleFOC open loop 6PWM, it is still not very smooth.

So I took a look, and noticed that sometimes, there’s a PWM signal that seems like the opposite of what it should be for a single cycle. That would seem consistent with the motion problem

Has anyone else seen/felt this with esp32 (or another uC)?

(Arduino IDE latest SimpleFOC + latest esp32 platform + updated header file)

Are you using mosfets with no driver? If so, interesting!

Looks like the middle phase should be ‘off’ but has switched on. Odd. I’ve added print statements to the generic and stm32 pwm code before and the phases are nicely sinusoidally. So I’d guess this is either a hardware glitch or a problem with esp32 implementation. @David_Gonzalez is our esp32 expert, maybe he can shed some light.

Can you video the motor’s behaviour. I think you are saying it is not super smooth i.e looks like cogging when you believe it should turn better. Does giving it a slightly higher voltage limit in velocity_openloop mode make it smoother. Is it only noticeable at slow speed?

Weird stuff! Which pins of the ESP32 are you using? That looks almost like something is interfering with the PWM signal.

You can use driver.setPwm(Vu,Vv,Vw) to set a duty cycle directly (probably best to disconnect your motor!) and check the output of the PWM for an explicitly set value.

Motor setup

BLDCDriver6PWM driver = BLDCDriver6PWM(32,33,25,26,27,12);

The driver is 6 NPN BJTs, since it’s what I had handy. This limits my usable motor supply voltage, but I’m just doing no-load testing.


After further investigation, the glitching seems triggered by ~30kHz+ (doesn’t seem to happen @25kHz) frequency & >= 50% “voltage”, e.g.

  driver.pwm_frequency = 30000;
  motor.voltage_limit = driver.voltage_power_supply / 2.0;

It’s most easily observed by setting the velocity to ~5rad/sec. And I set triggering to pulse width, > 32.9us, < 34.4us. Then it triggers both where expected and these glitches

So this is maybe operator error - I was fiddling with parameters hoping I could get it smoother before attaching the scope and made it worse.

Trying in position mode, I can’t find a single position that triggers it steady. It occurs around 0.33689 radians in the open loop position example, transitioning past that point will trigger the single pwm cycle glitch.

I have to admit that while I use the ESP32 a fair amount, I’ve never looked into the PWM code. @David_Gonzalez is the expert for that. I’ll take a look and see if I can spot anything.

It sounds like it is only occurring on the higher PWM duty cycles then - might have to do with the way the duty cycle is set.