simplefoc / Arduino-FOC

Arduino FOC for BLDC and Stepper motors - Arduino Based Field Oriented Control Algorithm Library
https://docs.simplefoc.com
MIT License
2.03k stars 521 forks source link

[BUG] Magnetic encoder readings of a AS5600 gives large false movements ~50degrees when stationary #300

Closed frippe75 closed 1 year ago

frippe75 commented 1 year ago

This is a simplified template, feel free to change it if it does not fit your case.

Describe the bug Using version 2.3.0 via library manager in Arduino IDE. Connecting to a AS5600 magnetic encoder via I2C and I see a constant spike in the values. Ran another AS5600 library and the reading is superstable so dont expect this to be hw related. Just switching from sketch1 -> sketch2 and the issue goes away.

Describe the hardware setup For us it is very important to know what is the hardware setup you're using in order to be able to help more directly

IDE you are using

Tried the Getting started guide? - if applicable Copied the last example from https://docs.simplefoc.com/magnetic_sensor_i2c

Readings are stable for about 20-50 readings then a single reading 50 degrees of and the velocity spikes as well. I'm only testing the sensor portion so no motor connected.

Readings on serial monitor:

360.00  -530.53
336.45  -527.06
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
383.47  1067.20
336.45  -74.64
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
336.45  0.00
383.47  1074.19

Running a different example sketch from the Arduino AS5600 library everything is stable https://github.com/RobTillaart/AS5600/blob/master/examples/AS5600_position/AS5600_position.ino

853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
853 0
frippe75 commented 1 year ago

Direction pin floating was an issue here https://github.com/Seeed-Studio/Seeed_Arduino_AS5600/issues/3

I will give that a try

frippe75 commented 1 year ago

Looks like that was the issue. I had connected a jumperwire from dir_pin to a ESP32 pin without defining it as an output or set the direction. So .... My bad.