Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Encoder Library Turn Interrupt on and off

  1. #1
    Junior Member
    Join Date
    Sep 2017
    Posts
    11

    Encoder Library Turn Interrupt on and off

    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_....html#optimize

    Thanks

  2. #2
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    5,654
    Teensy 2.x or 3.x?

  3. #3
    Junior Member
    Join Date
    Sep 2017
    Posts
    11
    Sorry I should've specified.

    Arduino Uno and Teensy 3.6



    Thanks

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,169
    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.

  5. #5
    Junior Member
    Join Date
    Sep 2017
    Posts
    11
    Thanks I appreciate it.

    I will give that a try.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •