I'm trying to test the AS5311 encoder with this board. I'm testing it by first reading the PWM signal by itself, then with a separate code i'm unplugging the PWM and reading the two square waves from the A and B pins. I'm getting a reading from the first PWM test, but the resolution is too small for me to see if the value is correct. During the second test, I'm not getting any signal, which is strange because the exact same code works on the AS5304 chip which has only A and B encoder signals.
Am I wrong in assuming the A and B pins will work the same as the AS5304 chip? I've been ignoring all the other programming pins because I assumed those are intended for functions I don't need. To be honest I'm not entirely sure what the the other pins do.
Here's the code I'm using
volatile int pwm_value = 0;
volatile int prev_time = 0;
void setup() {
Serial.begin(115200);
// when pin D2 goes high, call the rising function
attachInterrupt(0, rising, RISING);
}
void loop() { }
void rising() {
attachInterrupt(0, falling, FALLING);
prev_time = micros();
}
void falling() {
attachInterrupt(0, rising, RISING);
pwm_value = micros()-prev_time;
Serial.println(pwm_value);
}
Here's the encoder test code. This works perfectly on the AS5304
#include <Encoder.h>
// Change these pin numbers to the pins connected to your encoder.
// Best Performance: both pins have interrupt capability
// Good Performance: only the first pin has interrupt capability
// Low Performance: neither pin has interrupt capability
Encoder knobLeft(4, 5);
Encoder knobRight(7, 8);
// avoid using pins with LEDs attached
void setup() {
Serial.begin(115200);
}
long positionLeft = -999;
long positionRight = -999;
void loop() {
long newLeft, newRight;
newLeft = knobLeft.read();
newRight = knobRight.read();
Serial.print("x");
Serial.println(newLeft);
Serial.print("y");
Serial.println(newRight);
positionLeft = newLeft;
positionRight = newRight;
delay(50);
}
Another possibility is that the encoder magnet that shipped with the AS5311 board isn't compatible with the AS5311. There's no ID marking for the magnet they sent.
any help is much appreciated. Thanks in advance.