Shop OBEX P1 Docs P2 Docs Learn Events
Reading optical encoders with javelin — Parallax Forums

Reading optical encoders with javelin

theoatvecnatheoatvecna Posts: 20
edited 2005-02-25 03:24 in General Discussion
Has anyone read optical encoders using javelin, or have any suggestions.

Here are some of the options I am considering:

-I have a chip (LS7 183) that turns the encoder a&b signals to a simple updown counter signal, which I presume I could read directly on the javelin, but I am a bit concerned about missing counts.

-I could use the above decoder and a simple updown counter chip (74193) to buy some security about not missing counts, and then could regularly read the 4 byte output of the chip using 4 data lines of the javelin.

-I have a chip (LS7 166) that will take care of all the counting (24bit), but has a fairly involved set of registers and an 8bit bus.

-Wondering if there is any IIC enabled encoder counter chip out there (I haven't found it)

Any suggestions or advice would be welcomed.

Thanks,
Daniel

Comments

  • m817m817 Posts: 11
    edited 2004-12-07 15:28
    How fast will your encoder be rotating?· If it is very fast, maybe dedicate a bs1 to just monitoring the encoder.

    I have interfaced a Bournes ( or was it Grayhill? )· quadrature rotary switch (optical encoder)·to a Javelin using the PCF8574 i2c i/o expander.

    PCF8574 has 8 i/o pins (user configurable),·and uses i2c for communication.· The Javelin library already includes a class for using the chip.· In the next day or so, I'll have written a class to read the switch.

    The good thing about the PCF8574 is the chip has an output pin,·!INT,·which signals if any change has occured on the input pins. Rather than constantly read the chip via i2c, I just check a single cpu pin to know if the chip needs to be read.

    In a tight loop, I could not turn the switch fast enough to "skip" a position.· A skipped position is detectable by reading an illegal count progression.· There was a Circuit Cellar article that was very helpful in learning to decode quadrature patterns.· Basically, the last position AB bits are in bits 3,2.· Current AB bits or'ed in to bits 1,0.· The four bit number is used in·a lookup table, indicating CW, CCW or skipped increment.

    Maybe a rotary switch isn't totally related, but I hope this helped.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-07 15:59
    I just ported a quadrature encoder app from PIC assembly to SX/B, and the process works like this:

    A) Read new encoder bits
    B) result = new XOR old
    C) If result is 0, go back to A
    D) old = old << 1
    E) old = old XOR new
    F) If old.1 is 1 then CW, otherwise CCW

    I hope this makes sense and is helpful. Perhaps a timer object could be used to make sure that the ecoder bits are read at a fairly regular rate.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • theoatvecnatheoatvecna Posts: 20
    edited 2004-12-07 20:43
    I guess what I am leaning towards right now is using the decoder chip and then reading the data from the chip using the 8bit databus directly from the javelin (this will take about 10-12 pins, but that should still leave enough for other things. Anyone have experience reading an 8bit databus directly?

    thanks,
    Daniel
  • Jack HudlerJack Hudler Posts: 6
    edited 2004-12-08 07:28
    I definitely prefer the dedicated route.

    I'm using a PCF8574 that reads US Digital LS7166 this setup needs 5 ports.
    If you can afford the chip count then go for it beats throwing away CPU cycles and forever wondering if you missed encoder lines.
    If you can afford the ports then skip the PCF8574, this takes 11 ports.

    http://www.usdigital.com/products/ls7166/ls7166adv.shtml

    I also like there encoders very fast delivery and very economical.

    Now· if someone would just make a I2C version of this chip!

    Jack Hudler

    I was just looking for the I2C -> 166 Java and I can't find it anywhere... it was just a prototype.
    On the other hand I have some BS2 code that reads the 166 chip, and should be easy to convert.

    I attached the BS2 code if you need the schematic for this let me know.


    Post Edited (Jack Hudler) : 12/8/2004 7:42:58 AM GMT
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-08 16:41
    How about a serial device, Jack? If you checkout the SX forum you'll see a quadrature reader project I did with the SX/B compiler. I'm thinking of expanding it to read four encoders, each with a 16-bit counter, and provide a serial link so that a microcontroller can get/set any/all of the counter values through a single-pin connection. Mind you, this is just an idea, but I have the tools to do it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
  • Shawn ReedShawn Reed Posts: 6
    edited 2005-02-03 19:03
    Jon,

    After a year of not playing with my robot toys, I have ordered a couple SureLink boards and grabed the plastic boxes of parts from the garage. My first priority will be to get the SureLinks going and write a class for them as well as a comm protocol so I can use a host PC to function as a goals processor with the Javelin being the action processor. After that though I plan to get some quadrature encoders going and your SX project sounds like fun. You can just never have enough types of microcontrollers on a bot!

    By the way when will we see SX/J? lol

    Current bot chassis is: www.shekari.org/wheels.php

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    -Shawn

    Post Edited (Shawn Reed) : 2/3/2005 8:07:47 PM GMT
  • theoatvecnatheoatvecna Posts: 20
    edited 2005-02-24 21:02
    Jack,
    I spent a little time trying to read the LS7166 directly without success, I am not sure how to handle some of the pins. Is the schematic offer still good? That would help me tremendously. Thanks.

    Jack Hudler said...
    I definitely prefer the dedicated route.


    I'm using a PCF8574 that reads US Digital LS7166 this setup needs 5 ports.

    If you can afford the chip count then go for it beats throwing away CPU cycles and forever wondering if you missed encoder lines.

    If you can afford the ports then skip the PCF8574, this takes 11 ports.



    http://www.usdigital.com/products/ls7166/ls7166adv.shtml



    I also like there encoders very fast delivery and very economical.



    Now if someone would just make a I2C version of this chip!



    Jack Hudler



    I was just looking for the I2C -> 166 Java and I can't find it anywhere... it was just a prototype.

    On the other hand I have some BS2 code that reads the 166 chip, and should be easy to convert.



    I attached the BS2 code if you need the schematic for this let me know.
  • theoatvecnatheoatvecna Posts: 20
    edited 2005-02-25 03:24
    Here is my attempt at converting your code to java. I just get zeros. I checked things with the scope, and I am at least seeing what I expect from the code. When I rotate the encoder I get no change. Also verified the encoder is working on the scope. As far as the wiring, it is as documented in the code, but I wasn't sure what to do with LoadCounter and A/B Enable pins. I tried various combinations. Any help would be appreciated.

    Thanks,
    Daniel
Sign In or Register to comment.