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
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.