# AS5600 Magnetic Rotary Position Sensor - Setup

I've been trying to get this sensor working for quite a while.
In theory, its a great sensor with huge potential but I've failed to get it up and running.

So maybe, somebody can give some advice.

Hardware Setup:
Motordriveshaft with magnet propped on
AS5600 fixed next to it

Software:
is up and running. I'm working with the seeed library (GitHub - Seeed-Studio/Seeed_Arduino_AS5600: The library comes with AS5600. Through this library, we can realize read the angles 、get magnetic from a magnet underneath the sensor.)
I get a reading of the "raw angle" and "get AGC" is working too

But now the problem starts, because till now, I've not been able to get a linear reading from raw angle, obviously I have problems with:

• my magnet is not centred on the axis
• the distance of my as5600 to the magnet is not ok
• my as5600 is not centred on the magnet
• the as5600 is not parallel to the magnet

you see, in theory quite a good sensor but practically not easy to set up.

Big question here, is how to physical set up the as5600 with the magnet to get linear readings?

the data sheet says:
"The typical airgap is between 0.5 mm and 3 mm. Using the AGC value as a guide, the optimal airgap can be found by adjusting the distance between the magnet and the AS5600 so that the AGC value is in the center of its range."

so as I'm running the AS5600 on 3.3v, I'm expected to get a reading of between 0 and 128 counts. Which I do.

When I turn on the motor, the AGC value fluctuates somewhere between 0 and 128.
so in which N / S position of the magnet must my reading be 64? How do I now what the position of my magnet is (where is N where is)?

Anybody out there, who can give advice on how to physically set up the as5600 and a magnet?
With what readings did you set up the as5600 in reference to the magnet?

Take a photo or draw a picture showing the relative positions of the magnet and sensor.

I’m using this code

code is too long to post here

and here is part of the library
https://github.com/Seeed-Studio/Seeed_Arduino_AS5600/blob/master/AS5600.cpp

and then I use the function getAGC and the raw angle. As mentioned before. I get readings and I’d say that code, sensor and AS5600 are working.

I just cant put the as5600 at the right spot to get a good reading.

I’ve made a little plate on my lathe, so that the magnet is located in the centre of the motor-axis.
as you see on the picture, the AS5600 is fixed to plate on 3 bolts, so that I can adjust the distance between magnet and sensor.
This also allows me to adjust the place of the sensor in reference to the magnet.

The question here is, what readings can I use to make sure that the as5600 really is at right spot?

Is the magnet in the shape of a disk or cylinder? Is the N/S magnetic axis in line with the motor axis or perpendicular to the motor axis?

Also, what metal is the plate made from?

These rotary magnetic encoders require a disc magnet thats magnetized across a diameter, not axially. The datasheet says this. Without the right type of magnet it will not work, with the right type it works fine, I've used them.

the plate is a metal, cant tell you what it is but its not magnetic, so I’d guess is aluminium.

I realised before post #3 as well, that I’m trying with the wrong magnet.

I just ordered new magnets.
the data sheet actually suggests a disk magnet of 6mm diameter and 2.5mm height.

AND diametrically magnetised!! which means the poles of the magnet are facing each other on the round (disk) side and not as most magnets on the height.

So for the moment, the project is on hold as I need to wait for the right magnet.

but guys, can you explain me the agc? if the magnet is placed in front of the chip and the motor is running (and the magnet is going around) should the agc value be stable or should it change?

It was just a guess, that I have the wrong magnets, but I just got the confirmation.

If anybody, will come across the same question:

get yourself and old school compass, the compass needle will show you clearly the polarity of the magnet (very clearly!).

Advice after some waisted hours... if anybody is going to buy an as5600, get a diametrically magnetised magnet at the same time!

Magnets have arrived, the ones the data sheet proclaimed, 6mm round and 2.5mm thick diametrically magnetised.

After some time trying, I must still say, the physical adjustment of magnet and sensor is quite difficult.
And I’ve not really been successful yet, you’ll see later.

with a little washer, I think, I’ve been able to place the magnet relative central on the turning axis.
The sheet where the as5600 is fixed to, allows me to move the sensor in therms of distance between magnet and sensor but also allows me do adjust the centre with the magnet.

I’ve still not understood what the AGC value really means and how to use it to adjust the sensor and the magnet.
It says that the AGC value has to be 50%, if that means at a certain point (at one point of the 360°) or if it always should be 50%, even when the motor is running (on all points of the 360°), I dont know

If tested a few settings (meaning places of the sensor in relations to the magnet) but I only get a reading of the diagram of the attachment.

You see, that I dont get a linear reading which obviously means that my sensor is not central to the magnet…
And it also means, that using the value of 0 - 4096 is not linear.

for example, 25% of 4096 would be 1024, but with my readings, 25% of the turn would be with the value of 1381.

not being centred, doesnt make it easier to work with.

If anybody, has a some advice for me on how to adjust the sensor relative to my magnet, I’d be very happy to hear it.

The non linearity is probably due to the magnetic field being distorted by the presence of the nuts and bolts and motor housing.

Try using non-metallic mounting hardware and put a 30mm spacer between the magnet and the end of the motor shaft.