Skip to content

Interrupt code timing bug - Encoder, StepDirListener #169

@runger1101001

Description

@runger1101001

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions