cancel
Showing results for 
Search instead for 
Did you mean: 

Code Examples

odissey1
Honored Contributor II

Hi,

Here is my version of the quadrature decoder with a button switch custom component (QudDec_SW), which was designed for interfacing of rotary shaft encoders to PSoC4 and PSoC5. It has been created out of necessity to save hardware resources in projects with limited or exhausted UDB/PLD space. The stock PSoC5 QuadDec component with hardware debouncer are consuming three Datapath cells per single encoder, which is too much for a device which remains idle for most of the time.

The QuadDec_SW component is implemented entirely in software, without using any UDB resources. It is sufficient for hand-operated rotary shaft encoders for non-critical operations such as scrolling menu or updating parameters.

The QuadDec_SW component has several options

      Returns position and direction of rotation.

      Optional 8-bit, 16-bit, 32-bit, single or double position range.

      Optional button switch with debouncing.

      Optional increment step size.

      Optional range limits.

      Uses interrupt or polling technique.

Attached archive contains component library, several demo projects for PSoC5 and PSoC4, a component datasheet, Application Note and algorithm description paper. Please read installation instructions in the readme.txt. Since the Community Components forum is no longer exists, it is being posted here, PSoC5 forum, as the most relevant place to be.

The component provided as-is, no liabilities. It is free to use and modify.

regards,

odissey1

YouTube demo: using QuadDec_SW with DDS24 signal generator

DDS tunable frequency / phase generator using Cypress PSoC5 - YouTube

pastedImage_0.png

YouTube demo: using QuadDec_SW for PLL tune-up

Custom Phase Lock Loop (PLL) demo using PSoC5 microcontroller. PSoC 5lp - YouTube

pastedImage_2.png

encoder_01b.png

=============================================================================

P.S. In case if only buttons events (w/debouncing) are needed, another simple component is available (ButtonSw32)

ButtonSw32: button switch debouncer component

Screenshot_1.png

ButtonSw_basic_1b.png

Message was edited by: odissey1 Scroll down for v0.1 of the component.

11 Replies
Bob_Marlowe
Expert II

WOW!

Good work, superb documentation!

Bob

0 Likes
odissey1
Honored Contributor II

Thank you, Bob.

Writing documentation actually helped with concept and debug, but ate

enormous time.

Sorry to say that Community Components forum is gone, being diluted into

the Software forum. I miss it a lot. There should be some repository for

custom code, please mention it to Cypress if you have a chance.

regards,

odissey1

On Sep 20, 2017 1:09 AM, "user_1377889" <community-manager@cypress.com>

Anonymous
Not applicable

This is awesome, and exactly what was was looking for, but I'm getting a couple of errors trying your interrupt example out on the PSOC 4200 BLE in the Notice List.

Screen Shot 10-01-17 at 11.32 AM.PNG

And here is what the component layout looks like:

Screen Shot 10-01-17 at 11.39 AM.PNG

0 Likes
odissey1
Honored Contributor II

The screenshots suggest that you opened and running library project instead

of demo. To run ISR demo, open encoder_isr_ex1.cywrk project.

See readme file for installation instructions. In short, unzip all files

provided in same folder. Check that unzipped folder structure is same as

shown in readme.txt.

odissey1

On Oct 1, 2017 9:40 AM, "dturney_1462731" <community-manager@cypress.com>

0 Likes
odissey1
Honored Contributor II

Attached is updated version of the component, fixing some minor bugs and updated Datasheet, which describes the changes.

To update the component, unzip in the same root folder and update component by clicking onupdate icon at the bottom of the Creator.

The Demo projects has not been changed.

 

odissey1

Anonymous
Not applicable

I owe you a beer. Thank you

0 Likes
rybo_1140436
New Contributor

This is awesome!  It makes many of the issues with Quad Encoders for this type of application MUCH easier. 

I'm currently trying to use this in a project with a 4 Line LCD.  It is working pretty well except that I get some "extra lines" of characters when the menu is scrolled down to the last menu item.  Any hints on how to deal with this? i.e. The two actual LCD menu items are displayed on lines 0 and 1, so I'd like to blank out lines 2 and 3. 

Many thanks for posting!!

0 Likes
odissey1
Honored Contributor II

user_222...,

In the char LCD demo, a 2x16 LCD was used for prototyping. For 4-row LCD, try to update LCD_menu.c:

void Update_Menu()

{

   //const uint8 NumRows = 2; // this is for 2x16 LCD:

   const uint8 NumRows = 4; //

/odissey1

rybo_1140436
New Contributor

Thanks.  I did try that, however, I still get some residual text in the bottom two lines.

I added an "LCD_ClearDisplay();" call after in the Update_Menu() function.... just before the "uint8 row;"  line, which cleaned things up a bit... but I still get a few leftovers.

It still works very well to change menu items though... and it's way further along now than my first attempt. 

0 Likes
odissey1
Honored Contributor II

user_222...,

I will take a look, but I have no 2004 (4x20) char LCD at hands to test the code.

/odissey1

0 Likes
odissey1
Honored Contributor II

user_222...,

Try to update next lines also,

void Update_Menu()

{

    const uint8 NumRows = 4; // this is for 4x20 LCD:

    char buf[20];            //LCD output buf

   

    if (menu_idx>lcd_idx+3) lcd_idx=menu_idx-3; else    // past bottom line, 3==(NumRows-1)

    if (menu_idx<lcd_idx) lcd_idx=menu_idx;                   // above top line

0 Likes