problem with reading value from the encoder HEDL 5540

Hey everyone,

Sorry you may see this thread in the sensor section. I am not sure if this is a sensor problem itself or programming. So I have this thread here.

I am trying to read the value from the encoder HEDL 5540 which is connected the Maxon motor EC-powermax 22. The encoder detail is attached here. This encoder looks to me a differential encoder. But I just connect A and B, power line (+5v) and Ground to Arduino to read the encoder value. The value I check from the serial monitor doesnt look right. It keeps adding up either in the positive direction or negative direction) even when I was not moving the motor shaft. Does anyone know what is wrong? The encoder code I used is here. I tested this code with a single ended encoder before. The code should work right. Also I tried this code with a simple single ended encoder from US digital. It worls fine.

Thanks a lot, everyone.

//--------------------
// for encoder 0
unsigned long last_read_time;
volatile float angle0 = 0;
#define encoder0PinA 2
#define encoder0PinB 3
int encoder0Count = 0;
//--------------------
void setup() {

  //  // for encoder 0
  pinMode(encoder0PinA, INPUT); 
  pinMode(encoder0PinB, INPUT); 
  attachInterrupt(0, doEncoder0A, CHANGE);  
  attachInterrupt(1, doEncoder0B, CHANGE);  
  last_read_time = millis();
  Serial.begin(9600);
}
void loop() {
  unsigned long t_now = millis();
  float dt = (t_now - last_read_time)/1000.0;
  Serial.print(dt); 
  Serial.print("\t");
  // for encoder 0
  // Serial.print(encoder0Count); Serial.println("\t");
  Serial.print(angle0); 
  Serial.println("\t");
}

void doEncoder0A(){  // interrupt 0 function
  if (digitalRead(encoder0PinA) == HIGH) {  // look for a low-to-high on channel A
    if (digitalRead(encoder0PinB) == LOW) { // check channel B to see which way encoder is turning
      encoder0Count = encoder0Count + 1;
    } 
    else {
      encoder0Count = encoder0Count - 1;
    }
  }
  else {                                     // must be a high-to-low edge on channel A
    if (digitalRead(encoder0PinB) == HIGH) { // check channel B to see which way encoder is turning  
      encoder0Count = encoder0Count + 1;
    } 
    else {
      encoder0Count = encoder0Count - 1;
    }
  }
  angle0 = 3*0.08789*encoder0Count;  // unit: degree
}

void doEncoder0B(){  // interrupt 1 function
  if (digitalRead(encoder0PinB) == HIGH) {   // look for a low-to-high on channel B
    if (digitalRead(encoder0PinA) == HIGH) { // check channel A to see which way encoder is turning
      encoder0Count = encoder0Count + 1;
    } 
    else {
      encoder0Count = encoder0Count - 1;
    }
  }
  else {                                    // must be a high-to-low edge on on channel B
    if (digitalRead(encoder0PinA) == LOW) { // check channel B to see which way encoder is turning
      encoder0Count = encoder0Count + 1;
    } 
    else {
      encoder0Count = encoder0Count - 1;
    }
  }
  angle0 = 3*0.08789*encoder0Count;  // unit: degree
}

Encoder_HD.pdf (918 KB)

Please edit your post and replace quote tags with code tags.

Thanks for pionting out. It has been changed.

This encoder looks to me a differential encoder.

It is a differential encoder, and you need a differential interface. See the data sheet for an example.

Hello everyone...

Even I am working on the same encoder[HEDL-5540], and I am going through multiple datasheets related to it. Unfortunately I am finding only the pin configurations and the hardware descriptions. I am not able to find anything related to interfacing of this encoder nor any examples.

Can someone please help me out...

Use a differential line receiver like 26C32 or 26C33. Be sure to have proper resistive termination on the data lines, as described in the 26C32 data sheet.