AS5600 min output value stuck at -31072

I recently stumbled upon the Simple FOC library to control two motors for a gimbal project I’m working on. To determine the angle of the motors, I have bought two AS5600 sensors to measure the positions of the opposing motors. While testing one of the AS5600s I ran into some unexpected behaviour.

The AS5600 seems to measure some angle between -360 and +360 degrees. It takes a lot of revolutions of the motor to cover this range, but the sensor defintely responds to rotation of the motor. While the max value output settles at 1020 relatively quickly, the minimum value output starts at -31072 and doesn’t change regardless of the angle of the motor. Here are some readouts:

angle:5.08	, raw:813	, min:-31072	, max:0
angle:6.58	, raw:47	, min:-31072	, max:1020
angle:30.57	, raw:870	, min:-31072	, max:1020
angle:91.23	, raw:523	, min:-31072	, max:1020

I’m new to working with BLDC motors and position sensors, so hopefully someone can explain the behavior of the AS5600.

That is very interesting as a problem, I did not see that one happening before.

What microcontroller are you using?

The sensor will give you the angle in radians not in degrees. 2PI = 6.28 radians is 360 degrees.
So it makes sense that you need to make quiet a few turns before you get to 360 radians = 57 turns of the motor.

I am not really sure where does this error come from, is it due to the microcontroller or our code in the library. It might be that the min_count variable is just too high set on
int min_count = 100000;
you can try to reduce the number to
int min_count = 2000;

Or if it is not that it might be some unset value in the library, that by default takes the value of - 31072 and that gets propagated through on startup.

Hello Antun, thank you for your quick response.

I’m using the Arduino UNO in combination with the SimpleFOCShield V2. It’s been setup as suggested in the documentation (although the pwm pin in the documentation is A0 and in the code example A1).

Thank you for pointing this out, because I wasn’t aware that the angle is expressed in radians. In that case the outputs for angles make sense.

I’ve been using the default library code examples to test the AS5600. I didn’t have the time yet to experiment with these parameters, but I think your suggestion to lower min_count might actually resolve the issue. Although it makes me wonder why it’s so far apart from the default parameters.

I will experiment with these parameters somewhere in the coming days and keep you posted :smiley:

Its because there are microcontrolelrs that have 16 bit adc range by deafault as esp32. so from 0 to 65,5536.

But even arduino should have int32 which should not have any troubles with 100000. :smiley:

Please do let us know if this changes something.

If you do not have time to experiment, then you can just eyeball the min value, just rotate the motor and see what is the minimal raw value that you can obtain an that is the value you should enter to the constructor. Or if you have even less time, you can just use the defualt values min= 4, max=1020. You should be able to control your motor still, just might have a small jump around 0 values.