Quadrature Decoder not working

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Using the PSoC4 Pioneer Kit and a 500 PPR encoder I am trying to get it to count up when I turn the encoder in one direction then count down hen turned it the other direction; but it is not working correctly.

   

When I turn the encoder in what I believe to be the count-up direction (A leads B) it does count up.

   

When I turn the encoder in the count-down direction (B leads A) it does NOT count down.

   

It just toggle back-and-forth between two values.

   

I capture the counts through Hyper Terminal and log them to a .txt file.

   

My project and the text file are attached.

   

I manually edited the .txt file to give indicators when I changed encoder direction.

   

 

   

Thank you,

   

Doug

0 Likes
10 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The provided project does not match your count output. I cannot see where you print "DN ".

   

Your components are outdated, consider updating to Creator 4.0 SP1 and updating tje components.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

What version of Psoc Creator are you using?  You need to update it to the latest revision. Here is an example with a PDF to check your Program  against as I don't have an encoder to check your program.

0 Likes
Anonymous
Not applicable

Thank you everyone for your replies.

   

 

   

   

I had HyperTerminal save the incoming counts to three .txt files.

   

1.) First I turned the encoder in the count-up direction and saved the counts to: counts01.txt and then closed that file

   

2.) Then I turned the encoder in the count-down direction and saved the counts to: counts02.txt and then closed that file.

   

3.) Last I turned the encoder in the count-up direction and saved the counts to: counts03.txt and then closed that file

   

4.) I combined the three files into one and changed the UP to DN at the right places and added the ---------------- between the UP and DN counts.

   

 

   

I tried to up-date my components but it looks like I have all the latest versions.

   

 

   

Any other help is appreciated.

   

 

   

Thanks,

   

Doug

   

 

   

This is my version of PSoC Creator:

   

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Actual version is Creator 4.0 SP1 and afaik there is a new version coming soon.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Doug,

   

 

   

I took a look at your project and I noticed that the "Encoding mode" under the "Quadrature Decoder" tab is set to 1x.  That is fine for a tack to read RPM but you are interested in counting up and counting down so the Encoding mode should be set to 2x.  That way the decoder can tell direction, up or down.

   

 

   

Ken

0 Likes
Anonymous
Not applicable

That worked Ken, thanks.  But when I look at the counts on Hyper Terminal or look at them in the text file there are missing counts.

   

Example:

   

33408
33409
33410
33412
33415
33416
33417
33419
33421
33424
33425
33426
33427
33429
33430
33432
33434
33435
33437
33438

   

There are 20 numbers here, there should be 31.  The 11 listed below were missed.

   

33411, 33413, 33414, 33418, 33420, 33422, 33423, 33428, 33431, 33433, 33436

   

I upped the UART's and Hyper Terminal's baud rate from 9600 to 19200.  It seemed to of helped, but the numbers above were taken at 19200 so that didn't solve the problem.

   

Also, I stopped logging the numbers to a text file in case that was slowing things down but that didn't help.

   

I would think that others, maybe many others, have used the quadrature decoder component before with success and I am hoping they can give me some helpful input to my problem.

   

 

   

Thanks again,

   

Doug

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Can you please provide us with your actual project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

 

   

Bob

0 Likes
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted
        Looks like normal behavior when decoder polling rate is slow. The encoder has very fine pitch (500/turn), so it updates position faster than UART can output. To confirm, change baud rate to 57k or 115k.   
0 Likes
Anonymous
Not applicable

Doug,

   

 

   

When you say the decoder is missing counts I don't think that is the case.  Looking at your numbers such as 33410 and 33412, you are thinking that the decoder is missing counts, but it can't count from 33410 to 33412 unless it has already counted 33411.  Just like you can't count from 1 to 10 by adding 1 to the previous number and not count all the numbers, you can't get to 5 from 3 by adding 1 unless you have already went from 3 to 4 first.

   

I think you data logging/display part is too slow, the count is there, it has already come-and-gone by the time the UART sends it to Hyper Terminal and it gets displayed.

   

I would try upping you BAUD rate, as odissey1 suggested.

   

Other possible bottlehecks could be:

   

   1.) serial communication wiring from the PSoC board to your computer.

   

   2.) your computer running slow.

   

   3.) delay due to writing to the log file.

   

   4.) UART-to-USB Bridge if you are using the PSoC 4 Pioneer board.

   

 

   

Ken

0 Likes
Anonymous
Not applicable

Thank you Odissey1, thank you Ken.

   

 

   

I upped the baud rate to 115200 and got the missing counts which proved Ken's theory correct.  The quadrature decoder was working as it should, I just couldn't see it because of the missing counts.  The missing counts from the too slow baud rate and not from the PSoC component.

   

So thanks again.

   

 

   

Doug

0 Likes