encoder reading misses steps at high speed on arduino
Arduino Nano, rotary encoder on pins 2/3 using interrupts. At slow rotation I get correct counts, but when I spin the encoder fast, counts are missed - a full turn that should give 20 detents gives maybe 12. I'm using attachInterrupt with CHANGE on both pins and a simple state machine in the ISR to determine direction. ISR just increments/decrements a volatile long. Is the ISR too slow, or am I missing transitions because both pins change at once? Could noise be causing extra interrupts that I'm misreading? Do I need to disable interrupts while reading the count in loop()?
4 replies