Encoder-Arduino Uno Missing Pulses

Hello

Today I tested my incremental encoder I bought last week.The problem is that my encoder missed pulses when I rotate it faster. During rotating it slowly it's fine. I don't know why these things happened, so I would like to ask You for help me with this. The specification of encoder is as attachment.

Model of Encoder : ZL3806-360-5-24L
Connection to Arduino: Vcc-5V, GND-GND, Phase A and Phase B to Pin 2 and Pin 4 with resistors 10k Ohm
Code I used for testing:

#define PhaseA         2      
#define PhaseB         4      
#define clockwise           1       
#define counterclockwise    2       
 
volatile long encposition= 0;
short encdirection = clockwise;
long lastposition = 0;
 
void setup()
{
  pinMode(PhaseA, INPUT);
  pinMode(PhaseB, INPUT);
 
  attachInterrupt(digitalPinToInterrupt(2), isr, RISING);
 
  Serial.begin (19200);
}
 
void loop()
{
  
  if (encposition != lastposition )
  {
    Serial.print(encposition, DEC);
    Serial.print(encdirection == clockwise ? "clockwise" : "counterclockwise");
    lastposition = encposition;
  }
}
 

void isr()
{
  
  int a = digitalRead(PhaseA);
  int b = digitalRead(PhaseB);
 
  if (a == b)
 {
   encposition--;
   encdirection = counterclockwise;
 }
 else
 {  
   encposition++;
   encdirection = clockwise ;
 }
 
}

Greetings

Phase A and Phase B to Pin 2 and Pin 4 with resistors 10k Ohm

It's possible that the 10K pullup resisitors on the outputs are not strong enough, and you could try 2.2K.

Have you connected the resistors properly as pullups to 5v, and not in series between the phase output pins and the arduino pins?

cattledog:
It's possible that the 10K pullup resisitors on the outputs are not strong enough, and you could try 2.2K.

Have you connected the resistors properly as pullups to 5v, and not in series between the phase output pins and the arduino pins?

It should be connected as pullups ?
I connected resistors between the phase output pins and the arduino pins. To be honest, I don't know my outputs are OC PNP ( like on website specification I bought from ) or long drive ( like the designation on encoder: ZL3806-360-5-24L and then compare it with specification I got with encoder - attached images ).
Can I check it without multimeter ?

It should be connected as pullups ?

If it's NPN open collector output like the most common form of output. I'm not familiar with some of the other drive possibilities, but I don't think that trying the pullup configuration will damage anything.

They must be pullups. 10k resistor in series could protect you from voltage spikes on the wires, but
generally don't do anything but limit the bandwidth to under 1MHz or so.

Got a link to ZL3806-360-5-24L? I don't see it at Digikey.com

MarkT:
They must be pullups. 10k resistor in series could protect you from voltage spikes on the wires, but
generally don't do anything but limit the bandwidth to under 1MHz or so.

So I have to put pullups 10k or 4.7k resistors instead of these resistors in series I put, yes ?

And what do you mean by ,, limit the bandwidth to under 1MHz or so '' ? I am a little green in it and don't know.

CrossRoads:
Got a link to ZL3806-360-5-24L? I don't see it at Digikey.com

The images of specification of encoder I got are as attachments. I have also the site from where I bought encoder, but it's in Polish language: http://sklep.cncprofi.com/enkoder-profi-360-06-a-a-b-b-z-z.html

Looks like the outputs are open collector PNP, so you would need pulldown resistors, 2.2k to 10k ?

Yea, on the site it looks outputs are OC PNP, but I tried to connect using pulldown resistors 10k without resistors in series and it didn't help :confused:

Bandwidth is the max frequency, it won't be an issue here I don't think.

To determine if it needs pullups or pulldowns, try both, using a multimeter to look at the output
voltage - if it fails to change upon slowly rotating the shaft you have the wrong ones.

Hello again,

I solved my problem - now it works correctly with other program and algorithm - I used two interrupts with mode Change on A and B based on Gray Code. Also I change the connection between Arduino and Encoder by putting two 4,7k Ohm pull-down resistors.

I have also one more question - I would like to measure the voltage on outputs A and B - how I should apply the ends of multimeter ?

Greetings