Any known library incompatabilities with the Teensy 4.x HW Quadrature Encoder library?

strud

Well-known member
I have a DAQ product which I am adding quadrature encoder capture to.

The hardware uses a Teensy 4.1 and the simple example in the library is showing the library and hardware to work using inputs 33 and 37.

When this is integrated into the main project I do not get any counts at all and hence it seems as though a library I'm using (or something else in my code) is causing an issue.

In the github repo (https://github.com/mjs513/Teensy-4.x-Quad-Encoder-Library) I was unable to find a list of any known library incompatabilities hence thought I would ask here.

In the mean time, I will start adding some libraries to the example project to see if I can trigger the issue.
 
I am not aware of any conflicts with other libraries that I tried. Maybe someone else can jump in here.

Only thing to be aware is this warning in the repo:
```
WARNING! Pins 0, 5 and 37 share the same internal crossbar connections and are as such exclusive...pick one or the other. Same thing applies to pins 1 / 36 and 5 / 37.
```
So if you happen to be using pin 0 and 5 for something else you would get a conflict if using pin 37.
 
I am not aware of any conflicts with other libraries that I tried. Maybe someone else can jump in here.

Only thing to be aware is this warning in the repo:
```
WARNING! Pins 0, 5 and 37 share the same internal crossbar connections and are as such exclusive...pick one or the other. Same thing applies to pins 1 / 36 and 5 / 37.
```
So if you happen to be using pin 0 and 5 for something else you would get a conflict if using pin 37.
Looking more into pinMode etc and discovered that setting the pinMode to input for these encoder inputs stops it working.

Next question: Is one able to read a pin status (as an input) that is defined as a pin for the encoder library? (ie and not set as input with pinMode)
 
You haven't said what frequency range you need to support, but if it's not too high, you could use the Encoder library instead of QuadEncoder. Encoder sets up the pins as digital inputs with interrupts and does all of the quadrature counting in the ISR(s). You can also read the status of the digital inputs via the usual digitalRead() or digitalReadFast(). The QuadEncoder library uses the T4.x quadrature hardware, which can count at high frequency with no CPU at all, but doesn't let you treat the pins as ordinary digital inputs.
 
Will be used for high speed encoder counting so need to use this library.

I have some pins spare so will parallel them up and define these as regular digital inputs I can read independantly.
 
Encoders usually require pullups enabled, INPUT mode doesn't use pullups

If you read the README there is an option to configure pullups for use with the encoder pins.

Rich (BB code):
QuadEncoder myEnc1(1, 0, 1, 0);  // Encoder on channel 1 of 4 available
                                 // Phase A (pin0), PhaseB(pin1), Pullups Req(0)

So if you have an issue try setting pullups to 1, it defaults to 0. Don't add pinmode yourself to the sketch.
 
My input hardware interface uses high speed optoisolators with totem pole outputs so no pullups/downs required.
 
Back
Top