Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 10 of 10

Thread: AS5048A rotary magnetic encoder.

  1. #1
    Member
    Join Date
    Mar 2016
    Location
    Ireland
    Posts
    64

    AS5048A rotary magnetic encoder.

    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/AS50...er/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

  2. #2
    Member
    Join Date
    Mar 2016
    Location
    Ireland
    Posts
    64
    I might be imagining it but I think I was getting solid results before upgrading to teensyduino 1.29..... I may be mistaken.

  3. #3
    Member
    Join Date
    Mar 2016
    Location
    Ireland
    Posts
    64
    Can anyone give guidance please. I'm pretty badly stuck with this.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,707
    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?

  5. #5
    Member
    Join Date
    Mar 2016
    Location
    Ireland
    Posts
    64
    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

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,707
    Yup, saw that comment. Can't imagine any changes in the last year which would affect this very basic SPI library usage.

  7. #7
    Junior Member
    Join Date
    Apr 2018
    Posts
    7
    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.

  8. #8
    Junior Member
    Join Date
    Jul 2018
    Posts
    1
    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!

  9. #9
    Junior Member
    Join Date
    Jul 2018
    Posts
    1
    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!

  10. #10
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,321
    Quote Originally Posted by bonifacio View Post
    "...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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •