Author Topic: Adding a Rotary Encoder  (Read 6459 times)

0 Members and 1 Guest are viewing this topic.

Offline popcap

  • Thread Starter
  • Posts: 15
  • Location: Toronto, ON
Adding a Rotary Encoder
« on: Wed, 28 August 2019, 21:13:27 »
If this isn't in the right place please let me know.

I am looking for a resource to figure out how to add a rotary encoder into my pcb design. I am using a atmega32u2.

Any help would be greatly appreciated.


Offline Findecanor

  • Posts: 5039
  • Location: Koriko
Re: Adding a Rotary Encoder
« Reply #1 on: Wed, 28 August 2019, 22:08:21 »
A rotary encoder is just like a set of switches that activate in the order of Gray code when turned. However, like other switches, input needs to be debounced.
Most encoders for user input have three pins and produces a 2-bit Gray code. Keebio and others sell the EC11, so I would support that if I was designing a PCB to sell.

You could just connect common to GND, and input pins directly to GPIO pins on the AVR (with internal pull-ups enabled) with your firmware polling the encoder every ms and debounce in software.
You could even put a rotary encoder as part of a keyboard matrix, with the common pin on a column (shorted to GND when strobed), and each input pin on a row — if the necessary debouncing time is not longer than for the key switches.
Do consult the encoder's datasheet and examples in the firmware you intend to use.

The alternative would be to debounce each pin in hardware. In this case, your firmware could be based on pin-change interrupts, and you would have to use a pin from port B. Debounce the same way as for switches.

« Last Edit: Wed, 28 August 2019, 22:22:17 by Findecanor »
🍉

Offline popcap

  • Thread Starter
  • Posts: 15
  • Location: Toronto, ON
Re: Adding a Rotary Encoder
« Reply #2 on: Wed, 28 August 2019, 22:19:39 »
A rotary encoder is just like a set of switches that activate in the order of Gray code when turned. However, like other switches, input needs to be debounced.
Most encoders for user input have three pins and produces a 2-bit Gray code. Keebio and others sell the EC11, so I would support that if I was designing a PCB to sell.

You could just connect common to GND, and input pins directly to GPIO pins on the AVR (with internal pull-ups enabled) with your firmware polling the encoder every ms and debounce in software.
You could even put a rotary encoder as part of a keyboard matrix, with the common pin on a column (shorted to GND when strobed), and each input pin on a row — if the necessary debouncing time is not longer than for the key switches.
Do consult the encoder's datasheet and examples in the firmware you intend to use.

The alternative would be to debounce each pin in hardware. In this case, your firmware could be based on pin-change interrupts, and you would have to use a pin from port B. Debounce the same way as for switches.

Thank you for this definitely putting me down the right path in figuring this out.

Offline Tactile

  • Posts: 1434
  • Location: Portland, OR
Re: Adding a Rotary Encoder
« Reply #3 on: Thu, 29 August 2019, 00:20:51 »
The folks who make the Teensy have a library available and some examples here.
REΛLFORCE