Shop OBEX P1 Docs P2 Docs Learn Events
Optical encoder problem. — Parallax Forums

Optical encoder problem.

Tech-ManTech-Man Posts: 100
edited 2008-06-25 02:34 in BASIC Stamp
Along with my Submarine project me and a friend are also working on an electric vehicle using old metal scraps, sprockets, batteries, and an electric wheel chair I picked up for $25
I have two questions but I’ll just ask one then ask the other one later. ·
I bought this video game steering wheel for a $1 thought it would be easy to interface with a BS2 and have it control the wheel chair motors but I’m having a bit of trouble.
Before I even get to the electronics part of this I hit a wall, at least to my knowledge.
There is a plastic wheel (pictured below) for the most part it looks like any other optical encoders I’ve read about. Has “teeth” that block the light and openings that let it pass through. And a large opening on the far side so you know when you have turned all the way to either side.
In this case the encoder turns with the wheel and this plastic teethed piece stays in place. My·· question is how does it (my program/me) know if I’m turning left or right since either direction would act in the same way?


·
I simply can’t figure out how it knows.
DSCF4250.jpg

Near the middle tords the right is the optical encoder.
DSCF4251.jpg
·




▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
There are no Undo buttons in life.

Comments

  • ercoerco Posts: 20,259
    edited 2008-06-19 12:09
    TM: There are two encoders there, 90 degrees out of phase. Based on signal overlap pattern, you can figure out CW/CCW rotation.·See "incremental rotary encoder" info at http://en.wikipedia.org/wiki/Rotary_encoder

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-06-19 15:46
    In the future please link or attach larger pictures like that rather than embedding them into the message as it causes the screen width to be forced to the picture width. On many members this causes the text to appear off the right side of the screen.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Tech-ManTech-Man Posts: 100
    edited 2008-06-19 19:34
    Ok ill post smaller pictures in the future sorry about that.
    That Wiki makes since but I just don’t see how mine can do that. So your saying that what I thought was a IR LED and a Photo transistor is actual a IR LED and two photo transistor, and by knowing which one breaks the beam first you can tell direction. That would make a tone of since and be sort of easy to program. But I have a felling it’s a bit different because they were talking about square waves, do I have to send it a signal. Or is it just like having two photo transistors like on the Boe-Bot.
    Thanks for the help but I’m still a tad bit lost.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • agfaagfa Posts: 295
    edited 2008-06-19 23:16
    Tech-Man,

    It appears to me that there is only one LED / transistor set, even though there is a place for a second set.
  • Tech-ManTech-Man Posts: 100
    edited 2008-06-20 01:09
    I know there is also a notch for the seconded set on the wheel it is much deeper. I guess it’s so it knows when it’s centered. But since there isn’t a seconded encoder it’s just blank.
    So given this information is it possible that the three pin thing across from the IR LED is in fact two separate receivers spaced apart a bit. I don’t know if that’s even possible but just thronging it out there. I’ll try to trace the paths and see where it all connects.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • agfaagfa Posts: 295
    edited 2008-06-20 01:43
    I believe the "three pin thing across from the IR LED" is a single "receiver" / phototransistor.· The phototransistors i've seen have 3 leads, the base is often not used, but can be to adust the light level that triggers the transistor.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-06-20 01:50
    How is the three-pin device connected to the rest of system? Can you trace the circuit and provide a partial schematic? Without that, we're just spinning our wheels here...

    -Phil
  • Tech-ManTech-Man Posts: 100
    edited 2008-06-20 04:01
    Ok I think your right this might just be a photo transistor. I’ve attached the requested partial schematic. If it is just one photo transistor how the heck dose it since direction. Well whatever take a look for yourself, sorry if the schematics a bit crappy but that’s MS Paint for you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
    909 x 643 - 48K
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-06-20 04:34
    Double check the PCB again. Are you sure that both pins with the 10Ks to ground don't have a lead going back to the epoxy-coated chip?

    -Phil
  • Tech-ManTech-Man Posts: 100
    edited 2008-06-20 04:52
    Yes!!! Your right i had it on my hand sketch but left it out on the computer one. Man your good. Anyway whats that mean. Looks similer to how you hook up a switch on a BS2?????

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-06-20 05:08
    It means there are two sensors/phototransistors in there, each outputting on one of those 10K pulled-down leads. Their phases will be in quadrature with each other, allowing the direction of rotation to be determined.

    -Phil
  • Tech-ManTech-Man Posts: 100
    edited 2008-06-20 05:22
    Ok its real late here so ill look it all up in the morning, heck i still don't even know exactly what a pull down resister dose. I mean i sort of do but not the math part. Thats cool that there are two in there like i thought. I will be able to interface them with a BS2 right? Don't see why not just wondering.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-06-20 05:49
    Tech-Man said...
    I will be able to interface them with a BS2 right?
    Check the voltage on those leads with everything powered up. If you see 4-5V with light shining through and 0-1V when blocked (or vice-versa), it should work with the BASIC Stamp.

    The pulldowns are there to force the signal pins to ground when there's little or no current being sourced by the detector in its "off" state. Otherwise, the pins could float in an indeterminate state or remain high from the slightest leakage current.

    -Phil
  • Tech-ManTech-Man Posts: 100
    edited 2008-06-21 14:39
    Ok soldered it up and it works just fine, when light is blocked I get around 0.41V and when allowed to shine through I get around 4.31V on both sensors.
    So now I should be able to hook it up to the breadboard and program it. I was setting here just logically thinking about what a chart would look like for CW and CCW and I got a chart that looks just like the one Erco showed me here http://en.wikipedia.org/wiki/Rotary_encoder#Incremental_rotary_encoder
    I’ve got to go out of town today but when I get back I’ll work a bit more on the programming. I don’t know why but I’m vary excited to have figured this out, maybe it’s because I’ve always logically knew how sensors like this work but I’ve never known how to use them in a circuit.
    A bit of topic but I know you guys will help; I understand the purpose of a resister in general it limits the amount of current that can flow through it. I know how to find the value in ohms and I’ve used them a lot in different circuits that others designed. But aside from driving an LED I have no idea when to use them or what value in ohms/watts to use. Just like in the case here I know I need a 10K to pull it down to ground but that’s only form being told that and I don’t know why its 10k. So if anyone could just give me a quick lowdown on the subject or send me a link. That ·would be so helpful.
    Well anyway like I said I’ve got to leave town in a bit, I might be able to take it in the car and program it there idk.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • Tech-ManTech-Man Posts: 100
    edited 2008-06-22 17:44
    I made a simple program that returns the two values and as I turn it either direction I get perfect results.
    Since I’m using this for an electric car I’m going to want more than just CW and CCW dada I also need to know how far it has gone in either direction.
    So this is my idea, when the wheel is at rest I get | A = 0 B = 0 |that’s perfect. So I can recognize this as a starting point. And have some variable set at 180 ·now say it turns one step ··| A = 1 B = 0 | A = 1 B = 1 | I know it went CW one notch so I could subtract 1 from the 180 to get 179 and keep subtracting if its following the CW pattern. And of course if it starts following a CCW pattern ill start adding to 179.
    Then when I get around to interfacing the “gas” petal I can use this value along with the “gas” peddle numbers to determine how fast to turn. Not just turn at the same speed as the pedal.
    This works so perfectly in my head but how do I do it. It must be very simple just I don’t know how.
    I need to store or remember the state of both switches then when the sate of either one changes I need to determine did it go CW or CCW and then erase the current stored value and replace it with the current value so it’s up to date for the next turn.
    Then like I said once I know if it went CW or CCW id just add or subtract from the 180 var.
    Any suggestions or terms I need to look up actually there syntaxes right? Well here is the program I have right now just to test the states.··

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
     
    x VAR Byte
    y VAR Byte
    DO
    x = IN6
    y = IN1
    
    DEBUG BIN1  x
    DEBUG BIN1  y
    PAUSE 500
    LOOP
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • Tech-ManTech-Man Posts: 100
    edited 2008-06-23 15:57
    Quick question i've had this happen before but i don't remember how to fix it.··· " No BASIC Stamp found"



    Still looking for some ideas on the encoder, Thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • kenwtnkenwtn Posts: 250
    edited 2008-06-23 15:59
    Usually the stamp is not connected or has power.
  • Tech-ManTech-Man Posts: 100
    edited 2008-06-23 16:03
    I have both power / conected, it was just working a minute ago. Made a new program pluged it back in and got that message.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • Tech-ManTech-Man Posts: 100
    edited 2008-06-23 17:19
    Ok this might be it but i don't know how its happening ok i took off all the components on the board to make sure they werent placed wrong, then i tryed downloading the code again and still nothing this is when i relised that the two smaller black chips on top of the BS2 modual were very hot. Why is it getting hot there arnt even any componenta on the board. Could the whole chip be dead now? [noparse]:([/noparse]

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
  • Brad_HBrad_H Posts: 35
    edited 2008-06-24 05:20
    I believe the 2 chips you are talking about are the eeprom and the voltage regulator.
    The whole chip could be dead.
    How did you have this wired? What board are you using?
  • Tech-ManTech-Man Posts: 100
    edited 2008-06-25 02:34
    I have a BS2 on a BOE. While i had it wired i could not get it to respond when downloading code. So i took off all the parts to see if it was something there, once i had all the parts off is when i noticed it was getting hot. All i had was a 7404 chip pin 14 connected to vdd, pin 7 to vss and pin 1 to pin 0 on the BS2. I do not see why this circuit would have been wrong in any way. But then again i had not checked if i could use the 7404 chip in this way. And I may have done something completely wrong.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are no Undo buttons in life.
Sign In or Register to comment.