Shop OBEX P1 Docs P2 Docs Learn Events
quadrature encoders — Parallax Forums

quadrature encoders

gregg Agregg A Posts: 2
edited 2008-07-09 16:44 in BASIC Stamp
Can anyone tell me how to read a quadrature encoder using a BS2?
I cant find a program that works.

Comments

  • Tracy AllenTracy Allen Posts: 6,664
    edited 2008-07-08 23:59
    Here is another link with PBASIC code:

    www.emesys.com/BS2fsm.htm#twobit

    Note that the BASIC Stamp is relatively slow in executing instructions, so it only works for encoders that are moved slowly. The processor has to be fast enough to detect every single state transition.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • jeffjohnvoljeffjohnvol Posts: 197
    edited 2008-07-09 00:45
    gregg A said...
    Can anyone tell me how to read a quadrature encoder using a BS2?
    I cant find a program that works.
    Those are good links, but I have to agree with the last poster, even with a bs2px you end up skipping (missing spots) if it goes more than 1 revolution per second, and that was just dedicated for looking at the encoder.

    I ended up using an absolute encoder from usdigital.com.· It works good, but you need an ADC chip to read the voltage (it varies from 0-5volts).· If you get an absolute encoder, I can share my code for tracking it and measuring rollovers (counts).
  • kenwtnkenwtn Posts: 250
    edited 2008-07-09 00:48
    Please share your code anyways, if you don't mind. It might come in handy for something.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Keep buying replacement parts and sooner or later you will get it RIGHT!
  • jeffjohnvoljeffjohnvol Posts: 197
    edited 2008-07-09 01:00
    Okay, here's the code.· Its not very well documented at this point because its a project in progress.· Also, it is for use with the PLC development board.

    "DrumCnt" is the number of rotations, and "DrumPos" is the relative position.· I degraded the value to get a range of 0-60.
  • kenwtnkenwtn Posts: 250
    edited 2008-07-09 01:04
    Thanks, can always pickup something new from others.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Keep buying replacement parts and sooner or later you will get it RIGHT!
  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2008-07-09 01:07
    If you pickup this months SERVO magazine there is an article in there about encoders. It uses a Parallax SX28 chip as an encoder processor. It can scale down the encoder values so you won't miss pulses. At any rate you may find the article helpful.

    Robert
  • gregg Agregg A Posts: 2
    edited 2008-07-09 14:43
    Thanks to all..

    lots of good info responses to my question.
  • jeffjohnvoljeffjohnvol Posts: 197
    edited 2008-07-09 15:06
    RobotWorkshop said...
    If you pickup this months SERVO magazine there is an article in there about encoders. It uses a Parallax SX28 chip as an encoder processor. It can scale down the encoder values so you won't miss pulses. At any rate you may find the article helpful.

    Robert
    Nice.· Too bad I can't find that mag at a Krogers, lol.· Don't they make dedicated chips for this purpose too?
  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2008-07-09 16:09
    jeffjohnvol,

    "Don't they make dedicated chips for this purpose too?"

    Years ago it was not uncommon to see an arrangement·using a 74HC73 (Dual J-K Flip-Flop) and a couple of 4040B's (12-Bit Ripple Counter)





    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
    1060 x 1184 - 375K
  • ercoerco Posts: 20,257
    edited 2008-07-09 16:44
    I see a lot of people putting encoders on the motors instead of the wheels, and it seems to me that's looking for a bloody nose. Obviously the wheels (several gears downstream from the motor) are turning more slowly than the motor, and a BS2-class chip stands a better chance of keeping up with encoder ticks. Those using motor encoders hoping for better resolution via more ticks per wheel revolution will quickly find that transmission backlash (gear slop) introduces erroneous errors. IMHO, it's better to have the encoder look at wheel revolutions for real-world output, and give our beloved Stamps an honest chance to keep up with them. My own robot has 5" diameter wheels, travels relatively quickly at 1.5 feet per second, has 32 holes in it, and the BS2 never misses a tick. I use a plain old Radio Shack IR LED & phototransistor sensor, directly input into a BS2 pin. The input signal swings back & forth across the Stamp's logic level transition ~1.4 volts, and I simply test for high/low to look for passing holes. I deleted my original Schmitt trigger because I had better results by sampling the input signal twice (make sure I get two lows in a row, then two highs in a row). That has totally eliminated false triggering from the noisy transition from high to low.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·"If you build it, they will come."
Sign In or Register to comment.