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
  • About Us
  • 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 2: Capturing Input on a Cypress PSoC4
  • 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: 12 Jul 2015 9:11 PM Date Created
  • Views 2373 views
  • Likes 6 likes
  • Comments 3 comments
  • rotary_switch
  • psoc4
  • rotary_encoder
  • cypress
Related
Recommended

Rotary Encoders - Part 2: Capturing Input on a Cypress PSoC4

Jan Cumps
Jan Cumps
12 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.

In post 1, I wired up the electronics.

In this one, I'm capturing the encoder's info on a Cypress PSoC4.

 

image

The Firmware

 

My original plan was to use another microcontroller as development platform. But this comment from DAB made me change my mind.

I'm using the Cypress PSoC4 BLE development kit. The BLE part isn't active in my design (although it would be easy to publish the encoder's data via BLE - maybe something for a follow up blog.

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

The Cypress PSoC Creator (their IDE) comes with a neat Quadrature Decoding example. It doesn't even need a rotary (or other) encoder. It generates the signals using the on board PWM modules.

I took it as a start, but replaced the on-chip generated signals with the real hardware encoder encoder outputs.

In my code, I added some instructions to read the decoder counter value. That's the data that I'm really after.

Because my needs are so close to that example, I started off with that:

 

image

I searched for a Quadrature example, and loaded it to the IDE. You can choose your favorite one out of the two create buttons.

 

image

 

Once the project is created, take care that you select the right device.

image

I found the right device name in the Quick Start leaflet of my dev kit.

image

I then adapted the routing so that it fits my boards layout. The PDF file that's loaded in your IDE when you create the project has good info on that:

image

I kept the assignments for encoder PIN A and Pin B. I had to change the green LED assignment to the green pin of the RGB LED mounted on my kit.

image

Content from the QuadDecExample documentation.

 

That LED is the only on-board route to change. In the next section I'll describe the external connections. But as mentioned above, I haven't altered them.

image

 

Changes to the example C code.

 

Almost none. I removed the on-chip quadrature signal generation, and replaced it by a few lines to read the decoded count.

Because I just want to show that the concept works, I just put a check in there to see if my movements brought the counter to a multiple of 10.

That allows me to put a breakpoint in my code where I can read back the counter (logging PSoC info to the IDE console is somewhat involved, otherwise I would just have used a printf() instead).

 

 

// ...

    /* Set index trigger */
    QuadDec_TriggerCommand(QuadDec_MASK, QuadDec_CMD_RELOAD);

    uint32_t oldcount = QuadDec_ReadCounter();

    for(;;)
    {
//        PhiAbGeneration(CNT_PULSE); // I COMMENTED THIS OUT
        uint32_t count = QuadDec_ReadCounter();
        if (! (count % 10) && (count != oldcount) ) { // each 10 counts
            oldcount = count; // BREAKPOINT POSITION
        }

// ...

 

 

That's it. You can now compile and debug the program.

Put a breakpoint on line 13, and add count to your watch window.

The program will halt whenever you reached a count that's dividable by 10. And you can evaluate in the watch display if the encoder really counted up or down as desired.

image

 

Wiring the Hardware

 

Look back at my first post to check how to components are wired up.

Then connect the encoder with the board.

Ground to Ground, 3.3V to 3.3V,

PINA to P0[1], PINB to p0[0].

 

Connect the kit, start the debugger and check if the execution breaks after a few turns left or right.

 

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

  • Fred27
    Fred27 over 7 years ago +1
    I assume it's using the programmable digital blocks for the quadrature decoding, rather than just software inside QuadDec_ReadCounter().
  • Jan Cumps
    Jan Cumps over 7 years ago in reply to Fred27

    yes

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Fred27
    Fred27 over 7 years ago

    I assume it's using the programmable digital blocks for the quadrature decoding, rather than just software inside QuadDec_ReadCounter().

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

    fixed the embedded video link

    • 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