AS5048A rotary magnetic encoder.

Status
Not open for further replies.

muggins

Well-known member
Hi
I've been struggling for quite some time with this encoder.
It behaves perfectly when attached to the standard SPI pins (11,12,13 + CS) on an Arduino UNO
#include "AS5048A.h"
AS5048A angleSensor(6);
void setup(){

delay (2000);
angleSensor.init();
Serial.begin(115200);
}

void loop()
{
delay(1000);
int val = angleSensor.getRawRotation();
float angle=val/45.511;
Serial.print("Got rotation of: ");
Serial.print(angle);
Serial.println(" degrees ");

}
The library is located at
https://github.com/ZoetropeLabs/AS5048A-Arduino/tree/master/lib/AS5048A

BUT when I attach it to the Teensy I get sporadic results, only returning a value about every 5th read. I have also tried the device with a separate 3.3V supply. I don't know what else to try.
thanks
John
 
I might be imagining it but I think I was getting solid results before upgrading to teensyduino 1.29..... I may be mistaken.
 
This library really looks like it should work.

Maybe try uncommenting the AS5048A_DEBUG line near the top of AS5048A.cpp. Perhaps the extra info it prints will give you an idea what it's really doing?
 
Paul uncommenting debug just shows that device is not responding to every poll.
I have 5 teensys and 5 of these devices. All work flawlessly with Arduino UNO and all "stutter" on the teensys. Did you see my earlier comment suggesting that my upgrade to recent teensyduino might have broken it?
Read (0x3FFF) with command: 0b1111111111111111
Read returned: 10101001 11110000
Got rotation of: 235.90 degrees
Read (0x3FFF) with command: 0b1111111111111111
Read returned: 0 0
Got rotation of: 0.00 degrees
Read (0x3FFF) with command: 0b1111111111111111
Read returned: 101001 11110010
Got rotation of: 235.94 degrees
Read (0x3FFF) with command: 0b1111111111111111
Read returned: 0 0
Got rotation of: 0.00 degrees
Read (0x3FFF) with command: 0b1111111111111111
 
Yup, saw that comment. Can't imagine any changes in the last year which would affect this very basic SPI library usage.
 
I was able to figure the problem out. The issue is the teensy clock speed is too fast when it transitions from a read to a write. A delay is shown in the code:
//Send the command
digitalWrite(_cs, LOW);
SPI.transfer(left_byte);
SPI.transfer(right_byte);
digitalWrite(_cs,HIGH);

// slow things down for a bit - other delays may work
delayMicroseconds(10);

//Now read the response
digitalWrite(_cs, LOW);
left_byte = SPI.transfer(0x00);
right_byte = SPI.transfer(0x00);
digitalWrite(_cs, HIGH);

Did the trick for me.
 
Perfection!

Thanks for posting your solution! A 1 microsecond delay worked for me on teensy 3.5 with the as5047p. I had to modify the ZoetropeLabs library slightly to work with this chip already.
Thanks again for sharing the knowledge!
 
thanks so much for sharing and updating what was the problem as i have something similiar. hopefully i have the same problem and, obviously, same solution. can i come back with questions in case i would have any? thanks a lot!
 
"...Hi
I've been struggling for quite some time with this encoder.
It behaves perfectly when attached to the standard SPI pins (11,12,13 + CS) on an Arduino UNO"

Hi ... you can forward the AS5048A connection scheme to the arduino UNO. I searched a lot on the web and found nothing. I need this a lot.

Ask in the Arduino forums or look at the source code of the Arduino SPI library. There must be a documented default pin configuration somewhere.

Edit: A quick look at the Arduino library reference let me find this (scroll down to see the pin numbers for the different Arduinos)
https://www.arduino.cc/en/Reference/SPI
 
Status
Not open for further replies.
Back
Top