Runs well for 5 minutes, then stops. 100% repetable

I have a small drone motor runing now in FOC and velocity mode. I am using ESP32, 8302 driver broad and an optical A/B (no X) encoder. I am spinning the moter smoothing at 2pi radians per second. I have tested up to 20pi.

Problem: It works for a while then stops. Pressing the re-boot button on the ESP32 always fixes it. After about 4 or 5 minutes the motor “stutters”, slows then stops. There is still some very slight vibration and low-level “white noise” sound while it is stopped. Then I press restart and (after init) it silently goes back to running, for another 5 or so minutes.

How to debug this? It seems to be a software thing, as the re-boot fixes the problem. My guess is maybe some kind of counter overflow, maybe in PID or encoder driver. After all, there is no index phase on the encoder. Or maybe the ESP32 has an issue with interrrupt processing.

I’d try a magnetic encoder but I don’t have any magnets. They are taking weeks to ship from China. Is there an Amazon seller for 6mm magnets? (I am in the US)

Yes, probably an overflow. Make sure you’re up to date, there was a TODO in Sensor::getVelocity that caused similar problems for a couple of people some months ago, but is fixed now Velocity and angle control works for a while (+/- 1 mins) then it goes crazy

Check motor.shaft_velocity. If the low-pass filter ever gets fed a bad value, it never recovers. If that is the case, then you just need to find where the bad value is coming from.

The software is up to date. I’ll try logging rotation angle and look for anomalies. Or wait for magnets to ship. The last problem I solved this morning as a blown pin on the ESP32 Dev board. It is easy to do that with flying DuPont leads everywhere. Perhaps 12Volts got on a pin?

Can you check the current consumption (for example with a multimeter or on your PSU)?
Does it slowly rise even though the velocity is constant, and is a lot higher when the motor is stopped at the end than it was near the beginning?

My guess as to what’s happening is that the encoder is missing a few counts each iteration, and therefore you’re gradually losing the correct electrical zero - until its at 90° to where it should be and then you have no more torque and the motor stops…

Does the “white noise” you describe get louder when the issue appears? (I.e. is the noise quieter after rebooting the ESP32?)

I am asking, because this, or something symptomatically very similar has happend to me occasionally over the last few days. I haven´t noticed it being this repeatable, but didn´t look into it. Though I thought it was an issue caused either by my unusual software setup, or my modified library code.

For reference, I use an encoder with index pin and have the motor pretty much stationary in foc_current torque mode.