Encoder.h

Status
Not open for further replies.
Might be a speed problem - The Teensy is sooooo much quicker than this old slow Arduino Mega. But if you don't respect the forum rules, sharing code to reproduce the problem and details about wiring (i.e. schematics), pictures of you probing the A and B phase signals with an oscilloscope, etc., it's not easy to help you.
 
Just as a hint : With these "de luxe" encoders which you use and with the Teensy 3.5 you can have much quicker, more precise, and less resource consuming encoder readings if you don't use that slow encoder.h library, but if you use the native encoder reading feature of the Teensy's integrated flex timers. Details can be found in the hardware reference manual.
 
Might be a speed problem - The Teensy is sooooo much quicker than this old slow Arduino Mega. But if you don't respect the forum rules, sharing code to reproduce the problem and details about wiring (i.e. schematics), pictures of you probing the A and B phase signals with an oscilloscope, etc., it's not easy to help you.


#include <Encoder.h>

#define motorHizA 5 // enable1
#define motorA2 7 // motor1ileri //Sag
#define motorA1 6 // motor1geri
#define motorB2 9 // motor2iler //sol
#define motorB1 8 // motor2geri
#define motorHizB 10 // enable2

// Change these pin numbers to the pins connected to your encoder.
// Best Performance: both pins have interrupt capability
// Good Performance: only the first pin has interrupt capability
// Low Performance: neither pin has interrupt capability

Encoder knobLeft(28, 27);
Encoder knobRight(29, 30);
// avoid using pins with LEDs attached

void setup() {
Serial.begin(9600);
Serial.println("TwoKnobs Encoder Test:");

pinMode(motorA1, OUTPUT);
pinMode(motorA2, OUTPUT);
pinMode(motorHizA, OUTPUT);
pinMode(motorB1, OUTPUT);
pinMode(motorB2, OUTPUT);
pinMode(motorHizB, OUTPUT);
}

long positionLeft = -999;
long positionRight = -999;
long newLeft, newRight;

void loop() {
newLeft = knobLeft.read();
newRight = knobRight.read();

analogWrite(motorHizA, 255);
digitalWrite(motorA1, HIGH);
digitalWrite(motorA2, LOW);
analogWrite(motorHizB, 255);
digitalWrite(motorB1, HIGH);
digitalWrite(motorB2, LOW);

Serial.print("Left = ");
Serial.print(newLeft);
Serial.print(", Right = ");
Serial.println(newRight);

if (newLeft != positionLeft || newRight != positionRight) {
positionLeft = newLeft;
positionRight = newRight;
}
// if a character is sent from the serial monitor,
// reset both back to zero.
if (Serial.available()) {
Serial.read();
Serial.println("Reset both knobs to zero");
knobLeft.write(0);
knobRight.write(0);
}
}wi
Code is Teensy sample code of teensy library Encoder .https://www.pjrc.com/teensy/td_libs_Encoder.html .Sorry i do not have oscilloscope:( .Wiring GND-GND , 5v to Encoder 5V and PİN27,28,29,30 connect to 5V with 10 K
 
1600 counts per revolution is correct when using a true quadrature decoder with a 400 pulse two-phase Incremental Rotary Encoder.
 
Last edited:
1600 counts per revolution is correct when using a true quadrature decoder with a two-phase Incremental Rotary Encoder.

You mean that since the encoder gives 400 pulses per revolution, I have 4 counts per pulse (A up, B up, A down, B down for example) ? In that case, the problem can be solved for the OP by a (x >> 2) operation on the readings if he wants backwards-compatibility to his old AtMega stuff.
 
Yes.
A 2 phase quadrature encoder has 400 pulses/rev for each channel, 90 deg out of phase. This gives 1 count per edge, and direction.
 
Status
Not open for further replies.
Back
Top