Hello,
I’m using SimpleDCMotor to control a 12V DC motor, via a 2_PWM H-bridge, using an ESP32-S2 microcontroller (An Adafruit Feather). An AS5600 encoder is providing feedback.
It’s all working wonderfully (including the AS5600!), so thank you to everyone involved in such an awesome library.
My problem, however, us that the DC motor occasionally ‘hiccups’ … this looks like an unexpected velocity spike when I use motor.monitor(). It appears entirely at random whilst I’m controlling the motor using the ‘dc-velocity’ example code.
The simplest scenario I can create that replicates this bug, is if I create a new code sketch that “manually” PWMs the motor (see code below):
void loop() {
if (micros() - prevMicros >= interval) {
prevMicros = micros();
motorPinState = !motorPinState;
digitalWrite(motorPin, motorPinState);
}
}
With this code running, the motor experiences a velocity spike / hiccup regularly every 2 seconds, like clockwork. The spikes are identical to the ones I see when using the SimpleDCMotor library.
If I change the code to this, the spikes/hiccups disappear:
void loop() {
analogWrite(motorPin, 128);
}
I’ve ruled out other potential causes of the problem:
- Not the DC power supply – it is powerful enough with a generous safety factor. I can replicate the same bug using different power supplies, and even a battery.
- Not Encoder problems and Not SimpleFOC library problems – I can replicate the bug with the very simple PWM code above.
My theory is that the ESP32-S2 is doing something in the background that is interrupting the code, causing a particular pulse in the PWM scheme to be too long, causing the velocity to increase momentarily. I’ve tried disabling the watchdog timer (which I really don’t want to do), but the behaviour remains.
A complicating factor is that I see that the ESP32-S2 doesn’t have MCPWM, and only a single core. Could this be a root cause, and if I replace my board with a ‘normal’ ESP32, might the problem go away?
Has anyone here experienced this problem with the ESP32-S2, and might you have any other suggestions? Thank you!
PS. I’ll try to get a Serial.plotter screenshot of the voltage spikes later today, and post here.