Magnetic Shaft Encoders

Hello, all. I am trying to code 4 of these 10-bit PWM absolute magnetic shaft encoders:

The encoder is attached to gears such that when my motor moves, so does the shaft of the encoder.

When I use pulseIn(), my numbers are jumping around when I’m not moving my motor/encoder. Any idea what’s wrong?
My code is below and see the attached picture for a sample output.

unsigned long duration;

void setup(){

void loop(){
  duration = pulseIn(11, HIGH);

Do you have a oscilloscope you could use to check the pulse output of the device? Perhaps some kind of electrical noise is getting into the data stream/

How much is it jumping around? Could it be jitter due to the timer0 interrupt handler routine running (it does this roughly once every ms).

I checked with an o scope and the signal is constant with no interference

I don't know how the timer0 interrupt would affect it. It'll jump between single digit numbers to 4 digit numbers. The numbers change sporadically and don't seem related to the motion of the motor at all. I can't figure out what's wrong.

Is pulseIn() compatible with the Mega 2560? I don't know why it wouldn't be but someone suggested I check

Did you resolve this issue?
I also want to use those encoders but not sure on the code.

I think that the pulsein fxn is too slow for the encoder as it prints out at 1kHz.
I believe you might have to use a timer but i am not sure how...

pulseIn has to be called "at least a few dozen microseconds before the start of the pulse",
which you aren't doing.

You need to call it twice in a row and take the second result if starting off unsynchronized
I think... Either that or wait for the line to go idle in a tight loop first.