AS5600 i2C: Incorrect angle readings

Hello guys,
I am trying to use SimpleFOC library for my new Robot arm project. I am using AS5600 encoder with stepper motors. I tried to get started with the simple sensor readout program, when I use “sensor.getAngle()” I am getting the sensor output. When I rotate the motor shaft by roughly around 90 degrees, the angle change it showed is only around +7 degree (for example before rotation the sensor readout is 3 degree after moving by 90 degree the sensor readout is 10 degree). I am using version 2.3.2 of SimpleFOC library. Also I am using timing belts so I need to account for the timing belt reduction to calculate the final angle and I am not sure how to accomplish that, because in order to link the sensor to the motor control program I have to use this line of code " motor.linkSensor(&sensor); ".

here is the code I used:
#include <SimpleFOC.h>

MagneticSensorI2C sensor = MagneticSensorI2C(AS5600_I2C);

void setup() {
// monitoring port
Serial.begin(115200);

// init magnetic sensor hardware
sensor.init();

Serial.println(“AS5600 ready”);
_delay(1000);
}

void loop() {
// IMPORTANT - call as frequently as possible
// update the sensor values
sensor.update();
// display the angle and the angular velocity to the terminal
Serial.print(sensor.getAngle());
Serial.print(“\t”);
Serial.println(sensor.getVelocity());
}

Thank you in advance

Can you confirm the gear/motor/sensor arrangement? You really want to have the sensor measuring the actual motor shaft rotation (before any gearing from timing belt). It sounds like you are measuring after timing belt and that the belt has a 90/7 = 13:1 gear ratio.
If the sensor is the wrong side then you’ve massively lost precision and are subject to backlash errors etc.

1 Like

Hi Owen, Thanks for the reply. My sensor measures the actual motor shaft rotation. my idea was to measure and read the angle of motor shaft and then calculate the driven pulley angle by using this formula:

Rotated angle of driven pulley = { (No of teeth on driving pulley) / (No of teeth on driven pulley) } * Measured motor shaft rotation angle.

Once again Thanks in advance.

is it showing a change of 7 degrees? Or a change of 7 radians?
Default simpleFOC units for angle are in radians (degrees * 2pi / 360), if you are getting 6.28 radians change for one rotation, then everything is working normally.

Sorry I forgot to mention about this in my previous post, I changed the code in “MagneticSensorI2c.cpp” to display the change in degree instead of radians.

All of the simplefoc code is written with radians in mind… why modify the library code instead of just changing the units of what gets printed to the serial terminal?

Hi @SHI-R-ISH , welcome to SimpleFOC!

That seems fine. But please work in radians as @VIPQualityPost suggests, otherwise you will have a constant source of errors.

I think you should change the code back to the original version of the library, and then try again. It sounds like you might have inadvertently mixed something up.

To print the current angle value in degrees you can use:

Serial.println(sensor.getAngle()/_2PI * 360.0f, 2);

Otherwise your test-code seems ok. When just printing the angles it will run too fast. You can add a delay to the main loop:

delayMicroseconds(1000); // run main loop 1000x per second, its enough

Remember to remove that when actually running a motor though.

If the problems still persist, then it most likely has to do with the setup:

  • is the magnet a correct diametrical type?
  • is the sensor close enough to the magnet?
  • is the sensor correctly configured for the voltage you are using 3.3V/5V?
  • are the other terminals of the sensor properly configured (e.g. the DIR pin in particular should not be left floating)

Many people have problems with the AS5600 related to one of these points.