element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Legacy Personal Blogs Rotary Encoders - Part 1: Electronics
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 11 Jul 2015 5:52 PM Date Created
  • Views 5253 views
  • Likes 7 likes
  • Comments 16 comments
  • rotary_switch
  • rotary_encoder
Related
Recommended

Rotary Encoders - Part 1: Electronics

Jan Cumps
Jan Cumps
11 Jul 2015

I've removed the rotary encoder from the scroll button of a defect mouse. Let's see how we can use that in a microcontroller design.

 

image

 

 

 

 

The Encoder

 

On the outside, a rotary encoder looks like a potentiometer. On the inside, it's a different beast though.

Instead of a resistor, it has a number of contacts in there that open and close while you're turning the device.

As a result, you get two signals on the output that are 90° out of phase (hence the name quadrature encoder).

 

If you turn clockwise, B is lagging on A. If you turn counter-clockwise, A lags on B.

 

image

Drawing adapted from the Texas Instruments RM46x microcontroller TRM, Enhanced QEP (eQEP) Module documentation

 

The encoder in my mouse turned out to be a EC101102X2E-VAX. It's a jellybean part that's found back in many devices.

 

 

image

 

Photo taken from http://www.soundwell.cn/products_detail/&productId=be545b9a-1e26-43c2-aecb-4b451cf432cd.html

 

Schematics

 

I'll be feeding the signal into a few different peripherals. All of them will want a debounced block signal from the encoder.

What we'll have to do is provide two pull-up resistors so that we get a high pulse when the switch is open, and debounce capacitors to keep the signal reasonably free from glitches.

image

Literature advices to use .1µF caps. Just because I happened to have .5µ ones on my desk, I used those.

They work well. The signal  rises fast enough (the slope isn't really steep because the 10K resistor in series slows down the charging). And as you can see on the captures below, there's no trace of bounce.

 

Clockwise capture:

image

 

Counter-clockwise capture:

image

 

You can recognize the excerpt of that TI reference manual drawing in the captures.

 

Interpreting the Signal

 

There are a number of possibilities. Some microcontrollers use dedicated peripherals to translate rotary action into data and interrupts that can be used in your firmware.

For others you have to build the logic yourself. That can be done using edge interrupts or other approaches.

With the small test bed I have built here, I can explore some of those mechanics.

That's something for the next posts.

 

Content
Part 1: Electronics
Part 2: Capturing Input on Cypress PSoC4
Part 3: Capturing Input on an Arduino
Part 4: Capturing Input on a Texas Instruments Hercules LaunchPad with eQEP
Part 5: Capturing Input on an FPGA
Real World Application: Hercules LaunchPad and GaN FETs: Control Big Power with a Flimsy Mouse Scroll Wheel
  • Sign in to reply

Top Comments

  • michaelkellett
    michaelkellett over 9 years ago +4
    Here's a link to an article I wrote awhile ago about a simple software decoding method which copes well with edge uncertainty which can be an issue with low cost optics. http://www.mkesc.co.uk/ise.pdf…
  • DAB
    DAB over 9 years ago +1
    I think you are dealing with a standard Quadrature encoding. You can decode it with a component in your Cypress PSOC. DAB
  • jw0752
    jw0752 over 9 years ago +1
    I enjoyed your analysis so far and will look forward to any additional posts about the quadrature encoder. I took some optical encoders out of a printer a couple months ago and had some fun figuring them…
  • Jan Cumps
    Jan Cumps over 9 years ago

    I've added the TI Hercules LaunchPad and Xilinx FPGA tests.

    I still have to upload the FPGA video. That's something for tonight.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • johnbeetem
    johnbeetem over 9 years ago in reply to Jan Cumps

    Jan Cumps wrote:

     

    I've got it working with an FPGA too.

    I'll be pinging John Beetem after I posted that design, so he can critique my (stolen from the internet) VHDL code - I think I'm a bit off with the numeric libraries and the scope of modules.

    image

    For VHDL you should try michaelkellett   Most of my FPGA work is done in Verilog.

     

    Nice Papilio Pro photo!  I'm a big Papilio fan.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 9 years ago in reply to martinvalencia

    I've got it working with an FPGA too.

    I'll be pinging johnbeetem after I posted that design, so he can critique my (stolen from the internet) VHDL code - I think I'm a bit off with the numeric libraries and the scope of modules.

     

    I have a bit of lag on my blog posts.

    I've got the Cypress PSoC and Arduino documented,

    Texas Instruments Hercules LaunchPad blog is WIP,

    and I haven't started the FPGA blog post yet.

     

    But I do have a customer action photo featuring the Papilio Pro image

     

     

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • martinvalencia
    martinvalencia over 9 years ago

    thank you very much, works perfectly :-)

     

    2015-07-13.jpg

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 9 years ago

    I've added a blog on that implementation on a Cypress PSoC: Rotary Encoders - Part 2: Capturing Input on a Cypress PSoC4

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube