To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.handyboardOpen lugnet.robotics.handyboard in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / Handy Board / 8183
8182  |  8184
Subject: 
Re: Reading encoder forward/reverse
Newsgroups: 
lugnet.robotics.handyboard
Date: 
Wed, 22 Nov 2000 13:15:48 GMT
Viewed: 
890 times
  
In lugnet.robotics.handyboard, Richard Giuly writes:
I would like to tell which way my optical incremental encoder is turning. It
has two outputs, one offsett from the other. Is there any library around that
can count and give direction? (the "encoders.c" functions seem to only count
regardless of direction) If no premade software handles this, would it be
difficult to write it?

thanks
rgiuly@bigfoot.com

Hello Richard

I think you should use a Gray code (consecutive decimal numbers are
represented by binary expressions that differ in the state of one, and only
one, one bit. Synonym: reflected or mirrored code). Its very simple for two
bits:

    00
01      10
    11

This code only changes one bit position between two adjacent code-words. So
no problem whith glitches, and...  ¡It has direction info!

Theoretical complexity of higher order Gray-binary conversion is O(N-1),
where N is the word length. But there are algorithms with lower complexity.
Next is for a DSP, use it as "pseudocode" and translate:

unsigned short binaryToGray(unsigned short num)
{
        return (num>>1) ^ num;
}

unsigned short grayToBinary(unsigned short num)
{
        unsigned short temp = num ^ (num>>8);

        temp ^= (temp>>4);
        temp ^= (temp>>2);
        temp ^= (temp>>1);
        return temp;
}


Hope it works with you.

Juan José Escobar Mira
www.fractals.8m.com



Message is in Reply To:
  Reading encoder forward/reverse
 
I would like to tell which way my optical incremental encoder is turning. It has two outputs, one offsett from the other. Is there any library around that can count and give direction? (the "encoders.c" functions seem to only count regardless of (...) (24 years ago, 21-Nov-00, to lugnet.robotics.handyboard)

2 Messages in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR