go_away

Author Topic: IR Encoder Code Help  (Read 1413 times)

0 Members and 1 Guest are viewing this topic.

Offline vivek9856Topic starter

  • Jr. Member
  • **
  • Posts: 43
  • Helpful? 0
IR Encoder Code Help
« on: May 24, 2008, 09:05:35 AM »
I have four IR encoders hooked up to my A2D pins on an ooPIC - R. The IR encoders are facing the inside of a wheel that has a reflective/nonreflective (white/black) pattern on them.

I am currently reading the pins in 10 bit mode, so I get values ranging from 0 to 1220 or something like that.

My problem is that I do not know how to write the code so that every time the IR encoder changes from either white to black, or black to white, it adds one to an interger that is used to count how many clicks the wheel has made.

The main issue is that the A2D level for the encoder never stays the same. It always fluctuates by about +/- 10 digits while standing still. And also, when over the white part of the wheel, the encoder reads a level or 900 +/- 100, and when over the dark part, reads about 300 +/- 100.

So how would I even start to write a code that says: When IRLevel goes from high (around 900) to low (around 300), add one click, and v.v.

Or even simpler, add one click to the count when IRLevel changes by 400?

Offline Rebelgium

  • Supreme Robot
  • *****
  • Posts: 638
  • Helpful? 0
  • It's called the future ... We like it here
Re: IR Encoder Code Help
« Reply #1 on: May 24, 2008, 09:54:48 AM »
quadrature encoders are usually connected to an interrupt pin and a normal pin.
And between the PIC and encoder you should place a smitt trigger, this converts your values to a nice 0 and 5V.

good explanation how it works:
http://www.geology.smu.edu/~dpa-www/robo/Encoder/pitt_html/encoders.html


It's probably possible to do it your way (ADC  and no interrupts) to, but it's easier doing it the normal way ;)
To relax after some hard work on robotics: A very fun free online text based MMORPG
orgcrime.net

Offline vivek9856Topic starter

  • Jr. Member
  • **
  • Posts: 43
  • Helpful? 0
Re: IR Encoder Code Help
« Reply #2 on: May 24, 2008, 04:16:30 PM »
I have a regular encoder, not a quadrature encoder. If I had a quad, I could have used the quad object on the ooPIC.

You said I should place a Schmitt trigger to get a nice logic high and low. Could I get this at radioshack?

If not, by using parts at Radio Shack only, can I make this work better? My reason for RS is because I have to have this done by Monday, so no time to order parts.

Thanks

 


Get Your Ad Here