Hi, i tried to use the example from simple_foc to read my encoder output, but it doesn’t work. already had a look with the oscilloscope and the encoder signals look fine. i get the behaviour from the code that i would get if one of the two encoder pins wasn’t triggering. am i using unusable pins or should i look somewhere else? using a stm32F446RE nucleo, with channel A= PA13 and B=PA14, here is the code:
/**
- Encoder example code
- This is a code intended to test the encoder connections and to demonstrate the encoder setup.
*/
#include <SimpleFOC.h>
Encoder encoder = Encoder(PA13, PA14, 48);
// interrupt routine intialisation
void doA(){encoder.handleA();}
void doB(){encoder.handleB();}
int i=0;
void setup() {
// monitoring port
Serial.begin(115200);
// enable/disable quadrature mode
encoder.quadrature = Quadrature::ON;
// check if you need internal pullups
encoder.pullup = Pullup::USE_EXTERN;
// initialise encoder hardware
encoder.init();
// hardware interrupt enable
encoder.enableInterrupts(doA, doB);
Serial.println(“Encoder ready”);
_delay(1000);
}
void loop() {
// iterative function updating the sensor internal variables
// it is usually called in motor.loopFOC()
// not doing much for the encoder though
encoder.update();
// display the angle and the angular velocity to the terminal
if (i%100){
Serial.print(encoder.getAngle());
Serial.print(“\t”);
Serial.println(encoder.getVelocity());
i=0;}
i+=1;
}