View Full Version : Quadrature Encoder Object question...

03-16-2009, 05:44 AM
Hi guys,

I have a question about the quadrature encoder object I am hoping someone can answer.ˇ I would like to know if there is a way to reset the counters to zero?ˇ I thought I could just set the variable to zero but that didn't seem to work out very well.ˇ Apparently the object somehow prevents this from happening.


03-16-2009, 06:11 AM
I remember doing something like that a while back. I had to add a method tho the encoder object. Try this method:

PUB Clear
'clears all of the encoder values (i.e. a reset)
longfill(Pos, 0, TotEnc+TotDelta)


T Chap
03-16-2009, 08:32 AM
Just stop and start the cog, that's what I ended up with.

03-16-2009, 05:36 PM
Yeah, I know I can start and stop it, but I was hoping for a way to clear just a specific variable.ˇ Tellurian, I will give your method a shot and see if I can manipulate that into doing exactly what I want.

Thanks guys!


Richard S.
03-19-2009, 11:07 PM
Seeˇ http://forums.parallax.com/showthread.php?p=720621I have done what you are asking about, resetting an individual axis while preserving the other values.

Richard in Michigan

03-20-2009, 05:21 AM

Thanks very much for the link - I have downloaded your code and will certainly incorporate this feature!!!


Jeff Martin
03-21-2009, 07:45 PM

You should not need to reset the counter, and in fact if one were to achive resetting it outside theˇcog that is reading the encoder(s), you'd be possibly creating a slight error (if the counter changed at a critical time in the read/write sequence of the encoder cog).

For this reason, the Quadrature Encoder cog does not allow resetting the counter and, instead, provides a much more useful feature... Delta tracking.

Simply call ReadDelta() every time you want to know how much the encoder has moved since the last time you "looked"... it provides a signed value, so if it moved backwards, you'd get a negative number.ˇ If it hasn't moved since the last time you called ReadDelta(), then it returns 0.

Read item 4 of "To use this object:" at the bottom of the code.

--Jeff Martin

ˇ Sr. Software Engineer
ˇ Parallax, Inc.