Re: Rotary Encoder [hijacked thread]

Hello everyone, I have a small doubt on rotary encoder. I am using RCS 5102 rotary quadrature encoder. In this I am using X4 encoding type for increment or decrement the count value.

Once I rotate my encoder slowly I get a large counts when compared to rotate my encoder faster for one cycle. I do not know why this changes happen.

Below I attach my program, Kindly check it out

int encoderPos = 0, A, B;
unsigned long duration1, duration2;
const int encoderPinA = A1;
const int encoderPinB = A0;
boolean encoderALast = LOW, encoderA;
void setup() {
Serial.begin(9600);
pinMode(encoderPinA, INPUT);
pinMode(encoderPinB, INPUT);
digitalWrite(encoderPinA, HIGH);
digitalWrite(encoderPinB, HIGH);
A = encoderPos;
}

void loop() {
encoderA = digitalRead(encoderPinA);


if ((encoderALast == HIGH) && (encoderA == LOW)) {

  if (digitalRead(encoderPinB) == LOW)
  {
    encoderPos--;
    B = encoderPos;

  }
  else {
    encoderPos++;
    B = encoderPos;

  }
  Serial.println(B);
  } 
encoderALast = encoderA;


}

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Can you post a link to spec/data of your encoder please?

Is the encoders output open collector?

Thanks.. Tom.. :)

The output is, slow speed(Half rotation)

1
2
3
4
.
.
.
.
573

fast speed(Half rotation)

1
2
3
4
.
.
.
.
217

This is what I get.

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you post a link to spec/data of your encoder please?

Is the encoders output open collector?

Thanks.. Tom.. :)

Moderator:

  1. Don’t hijack threads
  2. Read How to use this forum
  3. You has been asked twice

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Almost certainly your Serial.println() statement takes too long: it's about 1 ms per character at 9600 bps. Very slow. Later in the run it's 2 ms, then 3 ms each time you print out something. Oh, add another 1 ms for the CR character that's appended, so 2-4 ms per print statement.

Try removing this, or set your Serial speed to something more sensible such as 115200.

RCS 5102 rotary quadrature encoder.

Is yur encoder this one?https://robokits.co.in/sensors/encoders/rotary-quadrature-encoder-1000ppr-4000cpr-with-index

If so, It is a high resolution encoder, and is best read with interrupt techniques instead of pin change polling with this

encoderA = digitalRead(encoderPinA);
if ((encoderALast == HIGH) && (encoderA == LOW))

I think a review of this will be helpful https://playground.arduino.cc/Main/RotaryEncoders

TomGeorge: Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you post a link to spec/data of your encoder please?

Is the encoders output open collector?

Thanks.. Tom.. :)

RMCS 5102 rotary quadrature encoder. https://robokits.co.in/sensors/encoders/rotary-quadrature-encoder-1000ppr-4000cpr-with-index

In this, I am connecting two signal pin with analog pin A0 and A1.

Thanks @wvmarle now it will work fine.

I have a doubt,In this encoder with the help of count value how we can measure distance.

Hi,
The spec is a bit ambiguous as to the type of output of the encoder;
encoder111.jpg

But I would add 4K7 pullup resistors to the encoder outputs, just in case it is open collector.
Tom… :slight_smile:

Ganesh2807: I have a doubt,In this encoder with the help of count value how we can measure distance.

Count gives you the number of rotations (1000 pulses per rotation - so every pulse is 1/1000th of a rotation), you know the circumference of the wheel it's attached to (or measure this), and that gives you the distance travelled.

TomGeorge: But I would add 4K7 pullup resistors to the encoder outputs, just in case it is open collector.

The built-in pull-ups may work just fine, I'd try that first. Parasitic capacitance of the encoder should be low, though at the maximum 300 kHz it may become a problem.

I am using RMCS 5102 rotary encoder. How to measure distance with the help of count value from rotary encoder. Can anyone tell me idea for this.

Don't you read the replies given to you? I gave an answer on that in #10 already.

Thanks @wvmarle now it works fine.