Bringing this topic back up. I’ve been playing around with the STMHardwareEncoder library, trying to use it with an incremental encoder and a Nucelo F446RE. I’ve been unable to get it to work using TIM1 PWM pins, which the datasheet says supports quadrature encoders. Any suggestions on where to start with troubleshooting? Below is the code i’m using to just test the encoder without any of the motor code.
#include <Arduino.h>
#include <SimpleFOC.h>
#include "SimpleFOCDrivers.h"
#include <encoders/stm32hwencoder/STM32HWEncoder.h>
#define ENCODER_PPR 1024
#define ENCODER_PIN_A PA0
#define ENCODER_PIN_B PA11
STM32HWEncoder encoder = STM32HWEncoder(ENCODER_PPR, ENCODER_PIN_A, ENCODER_PIN_B);
long time_ms = 0;
void setup() {
Serial.begin(115200);
// initialize encoder sensor hardware
encoder.init();
time_ms = millis();
}
void loop() {
encoder.update();
if(millis() - time_ms > 10){
Serial.print(encoder.getAngle());
Serial.print('\t');
Serial.println(encoder.getVelocity());
time_ms = millis();
}
}