2

I have written an Arduino code to get 10-bit data from an absolute rotary encoder (ep50s8-1024-2f-p-24).

It gives correct values when the encoder is at rest. but when it is rotating it first gives incorrect value and then correct value.

If the value is between 511 and 1023 it first gives 1023 for .5 sec and then correct value. Kindly help.

This is the code I have written:

#include <digitalWriteFast.h>
void setup() {
    pinModeFast(2,INPUT);
    pinModeFast(3,INPUT);
    pinModeFast(4,INPUT);
    pinModeFast(5,INPUT);
    pinModeFast(6,INPUT);
    pinModeFast(7,INPUT);
    pinModeFast(8,INPUT);
    pinModeFast(9,INPUT);
    pinModeFast(10,INPUT);
    pinModeFast(11,INPUT);
    for(int i=2;i<12;i++)
    {
        digitalWriteFast(i,LOW);
    }
    Serial.begin(9600);
}

void loop() {
    const int b0= digitalReadFast(2);
    const int b1= digitalReadFast(3);
    const int b2= digitalReadFast(4);
    const int b3= digitalReadFast(5);
    const int b4= digitalReadFast(6);
    const int b5= digitalReadFast(7);
    const int b6= digitalReadFast(8);
    const int b7= digitalReadFast(9);
    const int b8= digitalReadFast(10);
    const int b9= digitalReadFast(11);
    const float val= b9*512 + b8*256 + b7*128 + b6*64 + b5*32 + b4*16 + b3*8 + b2*4 + b1*2 + b0*1 ;
    const float deg= 360.0/1024*val;
    Serial.print(val);
    Serial.print(" ");
    Serial.println(deg);
}
user3704293
  • 1,026
  • 2
  • 16
  • 28
mns
  • 29
  • 2
  • 1
    So you have the version with power supply 12V to 24V? Datasheet also mentions "open collector" PNP!! That means you have voltage divider at each output to get 5V at the Arduino inputs as it is a high side switch? We need schematics for at least one pin. – KIIV Oct 29 '16 at 15:44
  • I was getting 6v output from each pin. so I used a voltage divider to get 3v and now it is giving perfect readings – mns Nov 17 '16 at 07:25

0 Answers0