Issue linking the magnetic sensor (AS5600) to the motor

Greeting,
I have an issue linking the sensor to the motor.

I’m using magnetic sensor AS5600 and a 14pps motor with a B-g431-ESC motor driver.

When I check the sensor data by the following example sketch


The angle and velocity seem to be right, with 1 revolution I got the angle value as 6.28.
However, when I try with the close loop velocity sketch the motor can not run normally

When I look at the angle and velocity values it seems to be incorrect, with one revolution the angle changes by around 78,000 in value if I print the motor.monitor(), meanwhile if I use
sensor.update();
Serial.print(sensor.getAngle());
Serial.print(“\t”);
Serial.println(sensor.getVelocity());
It shows the correct value of 6.28 per revolution

How can I link the sensor value to the motor correctly?

Dear @nqh2412 ,

Are you running the velocity control magnetic sensor example unmodified?

Because this example is for an SPI sensor, not I2C. So you will have to modify the example to use the I2C sensor if you want to use it with the AS5600…

Hi, Thank you for your reply

I did change the sensor setting as the example of I2C

The strange thing is in this same sketch if I print the angle and velocity by
sensor.update(); Serial.print(sensor.getAngle());
It would show the correct value of 6.28 per revolution while motor.monitor() isn’t

I purchased my sensor from Aliexpress but I don’t think it is the issue.
I will try to reinstall the library

Thank you again for your support.

Honestly, I am not sure what is wrong here…

Installing the newest version of the library and the STM32 board package is probably a good idea!

Also, there are many threads in the forum about the B-G431B-ESC1 driver board, and how to use it. Perhaps it can be helpful to search in the forum.

I’m sorry I can’t be of more help.

1 Like

I can only think what could possibly be wrong with this.
I often spent a lot of time with as5600 and this is my least favorite sensor (but cheap).
According to specs AS5600 should run on Fast Mode Plus (1Mbit), you’re running it at 400Kbit.
I would suggest to try running it off 100Kbit first then 1Mbit see if you get different readings.
Although this is very unlikely this could be an issue.

1 Like

Which sensor would you recommend?

I’d recommend any SPI/SSI sensor, they are simply faster than I2C.
My personal choice are MagAlpha sensors (MA/MAQ), they are relatively affordable, come in few variants (like one with PUSH detection etc.) But most importantly they work out of box with SimpleFOC MagneticSensorSPI driver. Also additional benefit of MagAlpha sensors is fact that relatively low maginitude is required to have reliable readings, something on 10mT.

Other than that MagnaTek sensors are great and TLV too but are noisy.

1 Like