I am following the Getting Started tutorial and have not been able to get the motor running properly or correct readings from the sensor (at least that I can understand).
My setup is as follows:
I am using a NEMA 11 200step/rev(50pp), 24v stepper motor. Each phase has 8.5ohms of resistance.
The AS5600 magnetic encoder is on SDA/SCL pins 6 and 7 with 2.2kOhm pull-up resistors to ESP 3.3v. The AS5600 is powered by said 3.3v on VCC, with a capacitor across VCC and ground. The I2C Magnetic Encoder example sketch works fine. I have confirmed that the magnet is split hemispherically rather than axially.
My motor driver is an L289N. The driver is supplied with 24v and 5v from a bench power supply with plenty of ampacity. Phase A+ and A- are on ESP32-C3 pins 3 and 4, respectively, while phase B+ and B- are on pins 10 and 9. Phase A enable is on pin 2, and B is on pin 8.
The ESP is powered by and connected through a good-quality USB-C cable.
All grounds are tied together
Arduino IDE is version 2.3.5, with Espressif ESP32 board manager version 3.3.2 and simpleFOC library version 2.3.5. My computer is a Macbook M2 on OSX 14.8.
I successfully ran the Magnetic Sensor I2C test sketch (6.28radians per motor revolution when turned by hand), the driver test (āEP32-DRV: Configuring 4PWM, EP32-DRV: 4PWM setup in group: 0, EP32-DRV: 4PWM setup suggessful!, Driver ready!ā, though this sketch needed an extra second of delay() after Serial.begin()) for the notice to display on Serial Monitor), and the Open Loop example (this has a distinct thump of cogging every two seconds, frequency independent of speed but growing stronger with voltage and speed).
When I merged the Open Loop and the sensor test, the motor speed was steady (T=6, L=6), but the sensor reading angular velocity was all over the place, jumping erratically both positive and negative. I then confirmed that the sensor works fine with the AdaFruit AS5600 library and a drill gun on the motor shaft (disconnected motor wires first!).
Maybe my sketch merge was poorly crafted? Here is what I used to run Open Loop/Sensor Test
// Run motor in Open Loop with the sensor providing speed feedback
#include <SimpleFOC.h>
// Stepper motor & driver instance
StepperMotor motor = StepperMotor(50, 8.5); //Motor pole pairs, phase resistance
StepperDriver4PWM driver = StepperDriver4PWM(3, 4, 10, 9, 2, 8); //(A+, A-, B+, B-, Enable A(optional), Enable B(optional))
//AS5600 configuration
MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);
//target variable
float target_velocity = 2; //starting speed in rad/s
// instantiate the commander
Commander command = Commander(Serial);
void doTarget(char* cmd) { command.scalar(&target_velocity, cmd); }
void doLimit(char* cmd) { command.scalar(&motor.voltage_limit, cmd); }
void setup() {
// use monitoring with serial
Serial.begin(115200);
// enable more verbose output for debugging
// comment out if not needed
SimpleFOCDebug::enable(&Serial);
// configure i2C
Wire.setClock(400000);
// initialise magnetic sensor hardware
sensor.init();
// driver config
// power supply voltage [V]
driver.voltage_power_supply = 24;
// limit the maximal dc voltage the driver can set
// as a protection measure for the low-resistance motors
// this value is fixed on startup
driver.voltage_limit = 24;
if(!driver.init()){
Serial.println("Driver init failed!");
return;
}
// link the motor and the driver
motor.linkDriver(&driver);
// limiting motor movements
// limit the voltage to be set to the motor
// start very low for high resistance motors
// current = voltage / resistance, so try to be well under 1Amp
motor.voltage_limit = 12; // [V]
// open loop control config
motor.controller = MotionControlType::velocity_openloop;
// init motor hardware
if(!motor.init()){
Serial.println("Motor init failed!");
return;
}
// add target command T
command.add('T', doTarget, "target velocity");
command.add('L', doLimit, "voltage limit");
Serial.println("Motor ready!");
Serial.println("Set target velocity [rad/s]");
_delay(1000);
}
void loop() {
// open loop velocity movement
// using motor.voltage_limit and motor.velocity_limit
// to turn the motor "backwards", just set a negative target_velocity
motor.move(target_velocity);
// user communication
command.run();
//read the sensor
sensor.update();
// display the angle and the angular velocity to the terminal
Serial.print(sensor.getAngle());
Serial.print("\t");
Serial.println(sensor.getVelocity());
}
And here is a sample of the serial output of the above. I do see the pattern in the sensor reading, but I donāt understand what it means. Noise? Misalignment?
-56.16 -7.24
-56.17 -12.72
-56.18 -11.04
-56.18 -3.71
-56.18 1.94
-56.18 1.94
-56.18 -2.80
-56.19 -11.05
-56.20 -12.92
-56.21 -7.65
-56.21 -7.65
-56.21 -7.65
-56.21 -1.23
-56.22 -10.97
-56.23 -11.08
-56.24 -9.87
-56.24 -3.69
-56.24 3.70
-56.24 -1.88
-56.24 -7.40
-56.26 -12.86
-56.27 -13.47
-56.27 -5.53
-56.27 -1.83
The KV test is equally erratic and has the same thunk every 2 seconds.
EP32-DRV: Configuring 4PWM
EP32-DRV: 4PWM setup in group: 0
EP32-DRV: 4PWM setup successful!
MOT: Monitor enabled!
MOT: Init
MOT: Enable driver.
MOT: Align sensor.
MOT: sensor_direction==CCW
MOT: PP check: OK!
MOT: Zero elec. angle: 1.98
MOT: No current sense.
MOT: Ready.
Motor ready.
Set the target voltage : - commnad T
Calculate the motor KV : - command K
88.97
105.07
38.08
36.51
51.03
-182.48
-215.74
Then, to really put icing on the cake, my ESP32s also just stop transmitting over serial after a while; ~10 minutes the first time running Open Loop and ~25 minutes the second time running Find KV Rating. To test if this was a simpleFOC-related bug, I ran the AdaFruit AS5600 test sketch again, and that lost serial comms after ~22 minutes. I feel like this has happened within much shorter timeframes though, as I have not had an FOC sketch running successfully that would need to be tested for so long yet. This may be related to a watchdog timer not being reset? I had to push the reset button before the Arduino IDE would connect again.
When the ESP32 stops transmitting, the motor runs noticeably smoother(due to no delay from the serial interrupt, I understand), but the 2-second thunk is still there.
I have used these motor and sensor arrangements for months with normal stepper drivers and Arduinos/libraries, so Iām confident those two elements work fine.
I have troubleshot these issues for three evenings now and have read many similar posts but nothing that quite matches my troubles; any help would be greatly appreciated.
Hereās my setup and a link to a video of the thunk
