Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCNT issue using FastAccelStepper 0.28.1 with ESP32Encoder 0.10.1 + workaround #83

Open
pit34 opened this issue Oct 30, 2022 · 0 comments

Comments

@pit34
Copy link

pit34 commented Oct 30, 2022

Hello,
I have found an issue about PCNT using FastAccelStepper and ESP32Encoder library on same project.
Behaviour seems indicate that both library use same PCNT unit, despite recent change done on each library about PCNT handling.
Here is my code about encoder and stepper :

[...]
ESP32Encoder encoder;
FastAccelStepperEngine engine                   = FastAccelStepperEngine();
FastAccelStepper      *stepper                  = NULL;
[...]

void Setup(){
[...]
encoder.attachFullQuad(ENC_A_PIN, ENC_B_PIN);
engine.init();
stepper = engine.stepperConnectToPin(MOTOR_STEP_PIN);
[...]

This way the stepper motor can move and his behaviour is OK, but encoder 's count is reset proportionally to the stepper speed.
I have tried to manually change the PCNT unit used by both library, but I am not competent enough to make it work.

Nevertheless, I have found a workaround to make it work. It consist of create a first encoder i.e. "encoder0" (which will work on same PCNT unit that the stepper motor) AND to attach pins to it. If .attach() is not used, the workaround doesn't work.

[...]
ESP32Encoder encoder0;
ESP32Encoder encoder;
FastAccelStepperEngine engine                   = FastAccelStepperEngine();
FastAccelStepper      *stepper                  = NULL;
[...]

void Setup(){
[...]
encoder0.attachFullQuad(ENC_A_PIN, ENC_B_PIN);
encoder.attachFullQuad(ENC_A_PIN, ENC_B_PIN);
engine.init();
stepper = engine.stepperConnectToPin(MOTOR_STEP_PIN);
[...]

Issue posted on FastAccelStepper repository :
#gin66/FastAccelStepper#148 (comment)

In hope this could be used to improve both libraries ;).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant