AMT22 absolute encoder support?


I’ve got myself the AMT22 (AMT223A-V) absolute encoder and was wondering, if it’s supported by simpleFOC so that I can use it with the library by plug and play? (I’m not that good with programming yet.)

Good thing for me as a beginner is that I was able to get it working by this tutorial from the manufacturer:

Maybe that makes it eaisier for you too, if you want to implement it in simpleFOC.

Thank you very much!

Hey Lucas,

Thanks for the code, yeah it helps a lot to have a code to start from.
However this sensor seems to be a clasic example of a MagneticSensorSPI class of sensors.
Here are docs for it:

You will probably be able to use it directly with this class:

// MagneticSensorSPI(int cs, float _cpr, int _angle_register)
//  cs              - SPI chip select pin 
//  bit_resolution - magnetic sensor resolution
//  angle_register  - (optional) angle read register - default 0x3FFF
MagneticSensorSPI sensor = MagneticSensorSPI(2, 14, 0x0000);

Basically the AMT22 sensor uses the SPI interface, it can have the resolution of 14 or 12 bits, and the register which contains the current position is a 0x0000.

Check the library examples for a stand-alone arduino example with only this sensor.

If this does not work for some reason and if you are willing to install the dev branch of the simple foc library you can implament this sensor using the new GenericSensor class:

Thank you very much, that will help me!
I’ve tried the magnetic_sensor_spi_example with “MagneticSensorSPI sensor = MagneticSensorSPI(2, 14, 0x000);” and got values back but they seem strange to me.

I will have a look at the new GenericSensor class. As you may notice from my text I don’t understand much of it but I will try to make it running: :grin: Might take a little though. :laughing:

Hey @Lukas,

I’ve gone through the datasheet a bit and now I am sure that the MagneticSensorSPI class will work.

I think you have a 12 bit resolution sensor not 14 bit. According to the documentation:

So try:

MagneticSensorSPI sensor = MagneticSensorSPI(2, 12, 0x0000);

Hi there!

I’ve tried it again with the magnetic_sensor_spi_example and your recommendation.
The code works and also prints out Sensor ready but as I’ve mentioned before the data looks wrong to me.
So maybe there’s another problem.

I’ve got a screenshot for you from my serial monitor when I’m slowly spinning the sensor by hand (in one direction).
getAngle only give’s me back a very small fluctuating number that never goes above a certain value under -1.00 and velocity is all over the place but maybe I’m missing something. The sensor seems to be alright, because I’m getting back very stable readings with manufacturers code.