-
Notifications
You must be signed in to change notification settings - Fork 616
Description
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