Encoder direction problem

Status
Not open for further replies.

lukebarber

New member
Hello,

I'm trying to use the Encoder.h library with Teensy. The program compiles without any errors and sort of works but not very reliably. I am using a standard rotary encoder and connecting the output of the encoder directly to pins 7 and 8.

My code monitors the encoder in a loop and does a serial print on whether it is turned clockwise or counter clockwise. So, when I turn the encoder in one direction, it reports the wrong direction about 25% of the time. Has anyone here encountered a similar problem?

Datasheet for the encoder in question is below.

http://www.clrwtr.com/PDF/Accu-Coder/Accu-Coder-Cube-Series-Encoders.pdf
 
Sorry, I might not be much help here. But might help to know more information like which of their encoders you are using, as it looks like some of them output a single wave and others do quadrature encoding. Also when you are doing this what type of speed are we talking about? (RPM or KHZ).

Which Teensy? Are we talking a 2.0 or 3.2 or 3.5/6? You might also want to do a search on the forum for encoder and see if some of the other threads might give additional hints.
 
Do you have the open collector or the pull up resistor variant? Did you check with an oscilloscope if the signal levels at pin7 and 8 are clean (no bouncing, quick ramps, full amplitude) ?
 
Has anyone here encountered a similar problem?

Yes, many times. It's almost always come down to a hardware issue. Some have been poor connections, others have been encoders with mechanical chatter which require a low-pass filtering with resistors and capacitors.
 
Check the pinout. If you have the pins mixed up, you would get the symptoms you are seeing.

EDIT: Actually, that 711 model that you linked to doesn't seem to be a quadrature encoder at all. So the encoder library won't work. That encoder model doesn't seem to be capable of detecting the direction.
 
Last edited:
The data sheet says it's uni-directional. Put meters on both A and A' output and see if they switch in a quadrature fashion. Maybe there's output on only one pin and the other is floating.
 
Yeah, for a unidirectional (single pulse, not 2 pulses in quadrature), you could probably just use attachInterrupt and increment a number.

Remember to make the variable volatile type, so the compiler doesn't optimize access to it (by assuming numbers in memory don't change). If using 8 bit Teensy, also disable interrupts when reading anything more than 8 bits.... the usual stuff when moving data from interrupts to your program.
 
Status
Not open for further replies.
Back
Top