This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

New servicing routines for rotary encoders

Other Parts Discussed in Thread: MSP430G2231

I worked on a new servicing routine for my kit oscilloscope's quadrature rotary encoder, and having done the work, I decided to write up the new routines and post them on Github.  Included are routines for periodic polling and for pin-interrupt servicing.  Hardware switch debouncing is not needed.  The routines are for general use, but I wrote testing code for the MSP430G2231 installed on the Launchpad, so they are relevant here.  The scope guys have used the "lookup table" state transition routine that most people use today, but it doesn't work very well on the scope, and I haven't found it to work very well generally.  My routines are designed to avoid all effects of switch bouncing, and seem to work very well and efficiently, and don't require servicing of bounce-induced interrrupts.

Everything is explained in the PDF file in the repo.  All the testing code is also included, both source code and flashable hex files, and I'm afraid it's all in assembler.  But I hope it wouldn't be too difficult to create C versions if anyone is interested.  The routines are pretty short.  I've provided hex files for both types of encoders - those with the same number of pulses as detents per revolution, and those with half as many pulses as detents.  The code produces one "tick" per detent in both cases.

The new routines are based on what I would call moving the goalposts.  For example, in the pin-interrupt routine an interrupt is enabled on only one pin at a time.  When that interrupt takes place, the enable is immediately switched to the other pin, which is stable.  So any bouncing that takes place on the pin which triggered the interrupt will have no effect because interrupts are no longer enabled on that pin.  So for a full open/closed/open cycle of both switches, the routine services exactly four interrupts, one for each legit transition on either pin, but none for bounces.   And the polling routine uses similar logic to mitigate bouncing.

Hope this will be useful to someone.

https://github.com/gbhug5a/Rotary-Encoder-Servicing-Routines

**Attention** This is a public forum