Skip to content

Interrupt code timing bug - Encoder, StepDirListener #169

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

Closed
runger1101001 opened this issue Apr 13, 2022 · 0 comments
Closed

Interrupt code timing bug - Encoder, StepDirListener #169

runger1101001 opened this issue Apr 13, 2022 · 0 comments

Comments

@runger1101001
Copy link
Member

Both Encoder and StepDirListener are affected.

https://community.simplefoc.com/t/simplefoc-port-on-stm32cubeide-problem/1911/4?u=runger
https://community.simplefoc.com/t/communication-error-step-dir/1369/14?u=runger

Basically we configure the interrupt for CHANGE, but then use digitalRead() inside the interrupt routine to check the state of the pin. The intention, I think, is to double-check the state of the pin.

This code is timing dependent - if the pulses are very short, the interrupt gets triggered but the pin reads low by the time digitalRead() is used to check - so the interrupt routine does not operate correctly. Another reason for the problem can be delayed interrupts (due to critical sections, other interrupts, etc).

The code (IMHO) should be modified to remove the digitalRead() and just trust the interrupt. To be discussed, @askuric

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

2 participants