How to set up AS5047 encoder on vesc based escs

This is a tutorial how to setup AS5047 encoder on vesc based escs.
I‘m going to split this in 3 parts:

Let’s talk encoder (part 1 basics)

Basics

Our VESC firmware supports the use of different types of encoder with vesc based escs.
The AS5047 is one of them.
What is the AS5047 encoder?
It’s a rotary encoder which can tell the vesc the exact position of our motor at any time.
How does it work?
Simply said, you place a magnet on the motor shaft. The encoder chip is placed directly over the magnet. When the motor shaft is rotating, the magnet field does change as well and that’s what the encoder use to calculate the motor position.
Why could this be interesting for me?
With HFI and soon ASS the use if external sensors or encoder might become less and less relevant but for now it’s the most precious way to tell the motor position. This gives you an even smoother start up especially if you ride off-road.
It’s also a cheap and easy to implement option for people who bought sensorless motors or broke their hall sensors.

All right, so where you can get those AS5047 encoder?
My choice is Mouser, but l‘m sure you can get them as well somewhere else.
Make sure you select the right type. You want to buy the „P“ version.

You can get the full set with magnet and header and the chip on a pcb.
https://www.mouser.de/ProductDetail/ams/AS5047P-TS_EK_AB/?qs=Rt6VE0PE%2FOfJKFTMKo%2BL0Q%3D%3D

Or you can just get the chip and design your own pcb and safe some space.

The data sheet with the most important information you can find here
https://www.mouser.de/datasheet/2/588/AS5047P-TS_EK_AB_Operation-Manual_Rev.1.0-775823.pdf

Let’s talk encoder (part 2 wiring)

Wiring

Ok, so how to wire the fuckers up?
There are two main options:
3V and 5V
3V is the way to go if you have problems with noice. For this you need to switch the vesc based esc from 5 to 3V (usually small switch on the pcb) and change the 0 Ohm resistor R1 to R2 on the encoder pcb.
5V is usually fine and the factory setting on the encoder, so I will further explain how to set everything up with 5V.

To connect the 5V there are two ways.
Connect to the 5V terminal and solder a bridge to MOSI as well as solder a bridge on the PCB voltage select terminals.

Or you get the 5V from the esc directly to the MOSI terminal and just bridge that to the middle terminal of the voltage select pins.

Important to use shielded wires and connect the shield to ground on the esc and encoder side. I did twist the shielding and soldered a small bit of AWG wire on. That did work very well.

Also try to hold the cable length as short as possible to reduce noice.

Wiring schematic ESC to encoder is following

At this point it should look like this:
Disclaimer (yellow is 5V in the picture, not red)

For one or the other it would make now sense to use a bit of clear nail polish :nail_care:
On the pcb please… just for that extra water proofing.

And we are done with the wiring.

Let’s talk encoder (part 3 installation and setup)

Installation and setup

How do we install the encoder on our motors?
First we need to fix the magnet on the motor shaft.
For outrunner it’s more convenient to place the magnet inside the pulley/sprocket/gear bore. For this you might need to shorten the shaft a bit.
In my case (inrunner) I placed the magnet on the back of the motor.
A drop of green/red loctite should be enough to hold the magnet in place. As I’m extra sensitive, I did add a bit of epoxy around the magnet as well.
Important: the magnet need to sit as centered as possible on the motor shaft.

Now we need to fix the encoder pcb above the magnet. The encoder need to be placed centered and 1-3mm over the magnet.
Etoxx gear drives you can buy with a slot for the encoder PCB.
If you run chains or belts you could just design a belt/chain cover to accommodate the PCB.

I did something similar. Just an additional end cap that can be mounted on the 3x M3 holes of the inrunner case.

To fix the PCB in place, I used some liquid tape, but you could use sugru or epoxy as well.
Just keep the encoder clean.


If you place the encoder next to each other like in my case, it’s recommended to save a distance of 15-20mm between the encoder chips. If you place them more close to each other there might be a bit of noice from the opposite magnet/encoder signal.

Now we plug the jst plug into the hall sensor port on our esc.
Just like we would with regular hall sensors.
For setup via vesc tool we follow the motor wizard.
If the motor detection takes a bit longer than usual with hall sensors, we know we are on the right way.
In general the auto detect should find the encoder and calibrate everything by it’s own.
After finishing the motor detection there should be written „encoder“ together with the motor current, inductance and all the other parameter.

To double check everything we can go into
Real Time Data -> tap Motor position
Than click „Encoder“ on the right menu.

If you turn the motor by hand, you should just get a nice clean line showing you the position of the motor.


As I did rotate the motor by hand it’s not a linear graph, but it shows that the signal is without noice and the encoder right calibrated.

In fact we are now done and ready to ride.
:+1:

14 Likes

You are welcome @glyphiks

7 Likes

Fine work my friend. Fine work indeed. This knowledge is invaluable :ok_hand:

7 Likes

considering these magnetic encoders are placed almost back to back, do you see any position changes on motor 1 if you hand spin motor 2?

5 Likes

The magnet shouldn’t be placed more than 3mm from the encoder chip to work correct.
So even the encoder placed back to back, the distance from magnet to the opposite chip is too not to have an influence.
I can double check that the next days by placing the motors as close as possible together. Will update the results here.

5 Likes

@ducktaperules took me a bit till I had a time to play around, but here we go.
I placed the motors as close as I could.
That’s about 4-5mn of PETG from the cases between the encoder chips.

The real time data screen shot is from the motor which does not rotate.

While rotating the motor which is not connected to the vesc tool I get some noice which equals around 1 degree difference from the actual position which is more or less reasonable I think.
With a distance of 15-20mm there is close to be no noice induced by the motors next to each other.

5 Likes

I‘m just about to get another set of encoders ready for my quad.
Sooo good I wrote this one. Already forgot how to wire everything up.
Well done to my to myself :relieved::+1::joy::joy::joy:

6 Likes

Dear Andy, thank you for the helpful information. I’m encountering issues converting a car alternator to a motor. I’m having difficulty controlling the alternator with the Vesc. That’s why I’ve considered installing an encoder, but when I turn on the magnetic field of the rotor the ground cable heats up, and the encoder doesn’t seem to work either. I can’t detect a signal in the Vesc tool. Could you please assist me? For additional details, please refer to the provided pictures.

When I do the motor detection it doesn’t show the as5047p encoder.

Hey! Puh it’s a long time ago I did set up my last encoder :sweat_smile: but let’s see. First of all double check your wiring. I‘m sure all is correct, but better to go through it once more. Also check if your esc works with 5V or 3.3V. Sometimes it’s possible to switch between the voltage for sensors. In fact you’re esc should see the encoder in the live data section. Not sure if you really need a motor detection for it before. Try to turn the motor by hand and check if you get a signal. Also double check that the magnet is placed directly over the chip and the gap between magnet an chip isn’t too big. I think the max gap shouldn’t be bigger than 3mm.

I have checked the wiring no problem there.
I have tried to put the magnets in the drill.
I still don’t get a signal.

Your magnet didn’t come with the encoder? Make sure the pole orientation on your magnet is like this

If on your magnet the positive pole is the flat surface up and the negative the flat down, it will not work.

I think that’s the problem.
I have ordered new magnets.

did you solve your problem?