My current Arduino project is to translate a quadrature encoder's positions over time into a series of movements, in the hope it would help me understand the inner workings of a Canon Pixma MX340 multi-function inkjet. Trying to keep the project simple, it was simpler to calculate "microseconds per encoder count" (shortened to us/enc below), which is the reciprocal of velocity "encoder count per unit of time". I think it'll still have all the information I need. I graphed output from my first draft sketch and it looked like a promising start.

The first problem I want to tackle is noise introduced by the encoder bouncing back and forth between two adjacent values. For example, 1799 then 1800 then back to 1799. This happens because the motion control system could not (or deliberately chose not to) hold the motor at a precise location, allowing it to move around a bit. Since these small bounces aren't very frequent, they work out to very large us/enc values. Without any processing, the raw plot results in lots of noise in the orange line that doesn't correspond to any actual movement on the blue line.

To keep my code simple, I've been resisting solutions that require me to implement a long history buffer, wary of bugs as I traverse the buffer. I've been able to get away with tracking a single history point so far, but in order to recognize bounces, I need to track a second history point to know if I'm just bouncing back and forth between the two history records. As expected, maintaining double the history entries approximately doubled my code complexity, but at least it's still simpler than implementing a circular buffer or anything along those lines.

The results were worth it! A bit of debounce code eliminated all obvious noises, leaving me with a much cleaner output so I can get a better understanding of this system's behavior.


This teardown ran far longer than I originally thought it would. Click here to rewind back to where this adventure started.

Captured CSV and Excel worksheets are included in the companion GitHub repository.