AS5047, SPI, and Teensy 4.0 always outputs 0

Status
Not open for further replies.

StefanB

Member
Hey guys.

I'm writing a high-speed rotary encoder for Teensy 4.0 and as I'm sure you guessed, running into issues.

my code is this:

Code:
// Include the library
#include <AS5X47.h>

// Define where the CSN Pin in connected. 
int slaveSelectPin = 10;

// Start connection to the sensor.
AS5X47 as5047p(slaveSelectPin);

void setup() {
  // Initialize a Serial Communication in order to
  // print the measured angle.
  Serial.begin(9600);
}

void loop() {
  // Read the measured angle
  float angle = as5047p.readAngle();

  // Show the measure angle on the Serial Port
  Serial.println(angle);

  // Wait 1 second (1000 milliseconds) before reading again.
  delay(1000);
}

I'm using Teensy 4.0, it's in 24mhz mode.

The pin diagram is as follows:
Teensy -> AS5047
5V -> 5V
Gnd ->
Pin10 -> CSn
Pin11-> CLK
Pin12-> MOSI
Pin13-> MISO

Picture:
64dfe6250da0b40c9e5a1088298e9831.png


Now, on the standard arduino board I uploaded this to, the serial monitor outputted values from 0 to 360 as expected as the magnet rotated, as expected. However, in the teensy 4.0 there is only 0 values coming down. The debug system also reported 0 values on everything.

Anyway, I would appreciate assistance figuring this out. Thanks a lot!
 
The pin diagram is as follows:
Teensy -> AS5047
5V -> 5V
Gnd ->
Pin10 -> CSn
Pin11-> CLK
Pin12-> MOSI
Pin13-> MISO

First of all - are you sure the encoder output is max 3.2 Volts? Any voltage above that can destroy the Teensy in millisconds..

Then, your PIN-Mapping sounds a bit strange to me. If you take a look at the card, you'll see this mapping for SPI:
MOSI: Pin 11
MISO: Pin 12
SCK: Pin 13
 
Hey Frank!

Thanks for the response. The encoder is not putting out any voltage at all, it's taking power from the Teensy. I also tried on independent power with no luck.

You're right. the pinout that I wrote down is incorrect, the actual pinout that you wrote down is the right one. You can actually see this in the image.

Thank you for the response, and I hope this helps diagnose my issue!
 
The T4.0 is not 5V tolerant so you must have the AS5047 board configured for 3V3 operation which involves feeding it the 3V3 supply from the T4.0 and setting the jumper at JP1 correctly.

Pete
 
If you have used the AS5047 with 5v with the teensy 4 , then because the o/p pins of the AS5047 to the teensy would have a logic 1 level of 4.5v (see AS5047 datasheet) it is highly likely that those pins on the teensy have been destroyed. Try removing your circuit from the teensy and try reading input 0 and 1 (with 3.3v as a 1) on the pins you have been using with a simple program. If you can detect changing states on the teensy pins then it might be ok. Otherwise it has been damaged.
 
Bri,

All 3 pins checked good. I checked them by println to serial if they were high. They all outputted correctly.
 
Mlu,

That sounds like what might be causing my issues, as I'm using that library! Do you know what settings were changed and how I should compensate?
 
The T4 default SPI speed is way faster than most Arduinos. The AS5047 has a max SPI rate of 10MHz...
 
if you're referring to this:

Code:
 SPISettings(14000000, MSBFIRST, SPI_MODE0)

I've varied that value from 1/100th its preprogammed value to 100 times its preprogrammed value and got no response, unfortunately.

But I really do think the problem might have something to do with that.
 
You need to check the mode is correct - that means reading the timing diagrams in the datasheet
usually as they don't like to make it easy for some reason. SPI has 4 modes and they are all different,
although sometimes the wrong one appears to work (unreliably perhaps)

I'd go for 4MHz initially till its working, don't expect whacky clock rates to work, choose plausible ones.
 
Ah, I see. According to the datasheet, it wants SPI_MODE1. 4MHz did not work.

Thank you for taking the time to work through this.

Alternatively, I've had some success reprogramming the AS5047P to output PWM. However, you must reprogram it through SPI to accept PWM, and apparently it loses its programming values when you unplug it, so I'm back to square one - for the record, I'm able to connect through SPI through the Uno and reprogram it but the register must be volatile. It has a non-volatile memory but I just am too dumb to make it work lol
 
Yup as an update to the second thing, I tried following the OTP reprogramming instructions but the settings still aren't being burned it seems.
 
Status
Not open for further replies.
Back
Top