SEARCH
TOOLBOX
LANGUAGES
modified on 10 May 2010 at 08:26 ••• 28,174 views

Rotary Encoder Demonstration

From WFFwiki

Jump to: navigation, search

A rotary encoder with LED display

Rotary encoders are very versatile input devices for microcontroller projects, not only do they provide 360 degrees of rotational freedom they also allow digital positioning information to be gained without the use of analogue to digital converters (ADCs). When using rotational encoders in projects it's possible to use the same encoder to represent a number of different input types, however this requires some form of feedback display to let the user know what information he is inputting and the 'position' of the encoder.

The project is based around a 24 position rotary encoder, 16 LEDs arranged in a circle around the encoder, an A6276 16 LED serial driver IC and the PIC182550 microcontroller.

Contents

YouTube Demonstration Video

Rotary Encoder

A rotary encoder has 3 pins usually called A, B and C. The C pin (which is normally the centre pin) should be grounded and both A and B should be connected to the microcontroller with individual pull-up resistors on each input. In this project I used RB4 and RB5 on the PIC to connect the encoder; this has 2 advantages, firstly you can use the PORTB internal weak pull-up (which means you do not need external resistors) and also the PIC provides an 'interrupt-on-change' which can be used to monitor the encoder.

LED Display

The LED display consists of 16 3mm red LEDs arranged in a circular pattern around the encoder. I chose normal intensity LEDs since you don't want the display to annoy or blind the user, also normal intensity LEDs are cheaper and more readily available. The LEDs are connected with common anodes to +5V and the individual cathodes running to the A6276 LED driver IC.

The A6276 is a 16 channel serial LED driver which supports SPI. Although you can see in the video that the LEDs have PWM brightness control, this is actually performed by the PIC (since the A6276 does not have in-built PWM). The A6276 allows you to control far more LEDs than the PIC can handle by itself (since you are limited to a maximum output of 200mA from the PIC) and also the SPI serial connectivity saves port pins on the PIC and makes the design much more scalable if you wish to add more encoders and displays.

Here is a picture of the PCB artwork used for the encoder and display:

Rotary Encoder PCB artwork

PIC Firmware

The PIC firmware is relatively simple (I borrowed the A6276 PWM driving code from my UltimateSIMON project). It provides 3 types of rotary input and feedback:

  • 360 degree position - In this mode the LED display indicates the current 'position' of the encoder, the user can rotate the control left and right any number of degrees
  • Volume - In this mode the LED display indicates a value which is varied between the minimum and maximum ends of the input range (like a volume control). The LEDs show the current value as a solid bar from zero
  • 3 position rotary toggle switch - In this mode there are only 3 positions to choose from. The user selects the desired position by rotating the control left and right.

To understand how the PIC reads the encoder information and communicates with the A6276 please take a look at the source-code provided below.

If required you can easily add a USB interface to this project by combining the firmware with the Generic HID library firmware available here.

Circuit Schematics

The schematic for the circuit used in this demonstration is as follows:

Rotary Encoder Display Schematic

I built the encoder and display on a simple PCB to allow the correct placement of the LEDs, the rest of the project was built on a breadboard.

Files for download

Project Files - A zip containing the MPLAB project and source-code (for Hitech C), the schematic and PCB design are also included.



Donate to waitingforfriday.com:

If you like this site and want to help support future projects, or you just want to show appreciation for a project you built, used or enjoyed, please consider leaving a PayPal donation. It's quick, secure and helps us to run the site and fund future projects!


PayPal, fast, easy and secure




Join the EFF:

Join the Electronic Frontier Foundation


The owner of this site is a member of the EFF and you should be a member too! The EFF protects the rights of open-source, open-hardware authors all over the world.



Most popular pages:

  1. Building a PIC18F USB device ‎(252,926 views)
  2. Home ‎(238,403 views)
  3. 4-Bit Computer ‎(104,196 views)
  4. Projects ‎(103,467 views)
  5. Open Source Framework for USB Generic HID devices based on the PIC18F and Windows ‎(103,334 views)
  6. Open Source Visual C++ Class for USB Generic HID Communication ‎(62,760 views)
  7. Real-Time Audio Spectrum Analyser ‎(60,998 views)
  8. Controlling LED brightness using PWM ‎(51,238 views)
  9. USB RGB LED VU Meter ‎(49,637 views)
  10. PIC USB Development Board ‎(48,667 views)
  11. 16x8 LED Matrix Display ‎(43,964 views)
  12. C64 VICE Front-End ‎(36,612 views)
  13. USB Performance Monitor ‎(33,205 views)
  14. PC Case USB LCD ‎(30,052 views)
  15. Rotary Encoder Demonstration ‎(28,174 views)
  16. Commodore SID 6581 Datasheet ‎(26,968 views)
  17. Reverse engineering an MB Electronic Simon game ‎(24,031 views)
  18. Retro Computing ‎(22,929 views)
  19. LED Colour Organ ‎(22,798 views)
  20. Vetinari's Clock ‎(18,593 views)

more >>