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

Thread: Teensyduino encoder library "provides 4X counting mode" ?

  1. #1

    Teensyduino encoder library "provides 4X counting mode" ?

    Hi, I am using an encoder and the values returned are skipping by 4 (each detent increments the value by 4). I understand this is because the encoder has quadrature output, however, the Teensyduino encoder library "provides 4X counting mode" correct? How do I engage the 4x counting mode?

    My circuit is on a pcb with the bourns recomended circuit so I am confident this is a software question. I could divide by 4, but I want to use the library functionality if it it is available.


    Bourns Encoder Cat. No. PEC12R-2225F-N0024
    Teensy LC

    Code:

    #include <Encoder.h>
    Encoder knobLeft(12, 22);
    void setup() {
    Serial.begin(9600);
    Serial.println("Encoder Test:");
    }
    long positionLeft = -999;
    void loop() {
    long newLeft;
    newLeft = knobLeft.read();
    if (newLeft != positionLeft) {
    Serial.print("Left = ");
    Serial.print(newLeft);
    Serial.println();
    positionLeft = newLeft; }
    if (Serial.available()) {
    Serial.read();
    Serial.println("Reset both knobs to zero");
    knobLeft.write(0);
    }
    }

  2. #2
    Senior Member
    Join Date
    Aug 2019
    Location
    Melbourne Australia
    Posts
    294
    For another take on managing encoders look here:-

    https://github.com/luni64/EncoderTool

  3. #3
    Thank you MatrixRat. I will try implementing the EncoderTool library from luni64.

    I added my schematic - maybe I executed the example from Bourns incorrectly.

    Click image for larger version. 

Name:	261542606_627250068692379_4892696950666499573_n.png 
Views:	18 
Size:	12.3 KB 
ID:	26797

  4. #4
    Senior Member PaulS's Avatar
    Join Date
    Apr 2015
    Location
    Netherlands
    Posts
    767
    Quote Originally Posted by mikemontauk View Post
    How do I engage the 4x counting mode?
    The encoder library is, by design, operating in 4x counting mode: "The library updates its count at each change, which is often called 4X counting". It's not a mode you can select.
    I just divide by 4 to count the detents.

    Paul

  5. #5
    Thank you for clarifying Paul. I will divide by 4.

Posting Permissions

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