Encoder Library Turn Interrupt on and off

Status
Not open for further replies.
Is it possible to turn the interrupt for the encoder library on and off so any encoder movements that happen when I don't care to read them don't slow my loop down?


My program uses switch... case statements so it would be easy for me to target when and where to shut off the interrupt and turn it back on. I just need to know if that is possible and how.


This is the library: https://www.pjrc.com/teensy/td_libs_Encoder.html#optimize

Thanks
 
For Teensy 3.6, you can use the NVIC interrupt mask bits to temporarily disable the interrupt for an entire port. First, figure out which of the 5 ports your pin uses, by looking at the schematic. For example, pin 2 is PTD0, so it's port D.

Use this to disable the port's interrupts:

NVIC_DISABLE_IRQ(IRQ_PORTD);

and use this to turn it back on again.

NVIC_ENABLE_IRQ(IRQ_PORTD);

For the other ports, replace "D" with whatever native port the pin actually uses.


For Arduino Uno, maybe try asking on Arduino's forum.

For either board, when you turn interrupts back on, if the encoder has moved more than 1 quadrature step, you'll get unpredictable results for the first change since the library doesn't "know" about all those steps it missed while you had the interrupt turned off.
 
Status
Not open for further replies.
Back
Top