The long story short is that I am building a hexapod robot. I'm using six pololu gear motors
with quadrature hall effect encoders mounted on the back. I am using an Arduino Mega to read all six encoders, and I am having a hell of a lot of trouble getting the data to look the way it should.
I tested the encoder inputs on a oscilloscope. Everything appeared correct. 0-5V signals, 90 degree offset.
The first thing I tried was loading the Teensy Encoder library
that the Arduino Encoder page links to. I loaded the library, set up an encoder object, and made a small chunk of test code. This test code told one of my robot legs to spin at 1/5 speed, so approximately 20 RPM. I outputted the position data via serial to see what my microcomputer was seeing. My data was spazzing between the values of -12 to 12, and seemed to get "stuck" on a value sometimes, sitting at 0 to 9 for half a revolution at a time. I couldn't make any sense of it.
I set the teensy code aside and tried to use the nested "For" loop code that the Arduino Encoder page used
. When I used that, I got ~256 counts per revolution, which was odd, as even measuring the falling and rising edge of Encoder Pin A and Encoder Pin B, I should only get a maximum of 64 counts per revolution. If I'm reading it correctly, that code is only counting a single edge of Pin A (when it goes from high to low) so I should only be counting sixteen.
Well, at least it was consistent, I thought. But when I tried to extend the nested for loop code to two motors, things got crazy again. It started only counting ~38 counts per revolution of each motor. Then I was royally confused.
So, has anyone used a two-channel quadrature encoder with an Arduino before? And does anyone know where I should start in getting consistent values for each encoder/motor combo? Any and all advice appreciated.