24 bit SSI encoder

Hi,
i was trying to read my absolute 24 bit encoder with arduino Nano , i've been using rs422 to ttl converter to get values, encoder got 2 data wires, 2 clock wires and +5 V

i used this sketch
And that's the numbers i get

Reading: 22176
Reading: 4294945617
Reading: 4294945617
Reading: 4294945617
Reading: 4294945617
Reading: 4294939412
Reading: 30026
Reading: 21180
Reading: 18088
Reading: 12140
Reading: 6717
Reading: 3555
Reading: 4294965553

numbers with first 4 look close but its not the right numbers because when i start spin encoder its changing on numbers with 5 digits

link: return statement - cppreference.com

My take - You're using unsigned long almost everywhere. One place it's not used is in the return type of readPosition(), which is shown as int. I'd try making readPosition()'s return type unsigned long so it matches the other variable types.

1 Like

As mentioned, the "int" is the problem, if you are using an AVR based Arduino (16 bit ints).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.