Shop OBEX P1 Docs P2 Docs Learn Events
Reading a quadrature encoder with a basic stamp — Parallax Forums

Reading a quadrature encoder with a basic stamp

Erik ArendallErik Arendall Posts: 21
edited 2006-09-22 22:40 in BASIC Stamp
I have a technical question. Would I be able to read a quadrature encoder running at 7200 PPM on a BS2? If the BS2 is not fast enough which stamp would be?
Im wanting to monitor a motors direction by using a quadrature encoder. The motor runs at 120 RPM.

Any help would be great.

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-09-21 17:33
    Erik,

    ·· You could use the COUNT command on the BS2 if you have a clean TTL pulse.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2006-09-21 17:37
    You would probably need an external D-Latch (or J-K flip flop) to be able to sense direction using the 2 lines of the quadrature for clock and data. And as Chris mentions, COUNT can then be used to detemine RPM.

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    Personal Links with plenty of BASIC Stamp info
    StampPlot - Graphical Data Acquisition and Control
    AppBee - XBee ZigBee / IEEE 802.15.4 Adapters & Devices
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-09-21 18:46
    Whoa!· Didn't see the quadrature in there...That may be too fast to read directly...As it is a 16 ppr encoder is difficult for the BASIC Stamp to read at any high rate of speed.· I would recommend an SX Microcontroller for this application if you don't have the hardware to convert the signal into a raw pulse as Martin mentioned.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • stamptrolstamptrol Posts: 1,731
    edited 2006-09-21 19:19
    There are several algorithms for doing quad encoders for the Stamp, but once you get to even 30 pulses per second, you won't have time for the stamp to do anything else.

    You say you're using it to monitor motor direction. If that's the only criteria, you'll probably be OK because you can periodically check direction then go on to do the other parts of the program. But, if you're doing speed, direction or positioning, you may need more processing power, as has been noted.

    Following lines of code will give you the direction.

    ' {$stamp bs2}

    ' Program to act as high speed quadrature counter


    ' Program Name: quadhicount.bs2
    ' Last Update: Mar 10/01 tjs

    DIRH=%11111111

    counter VAR Word
    counter2 VAR Word
    counter3 VAR Word
    old VAR Nib
    new VAR Nib
    direct VAR Byte

    ' Channel a and b of encoder go on inputs 6 and 7 in this case.
    quad:
    counter=127 'load a dummy value so can count up or down
    new = INB & %0011 ' get initial condition

    start:
    old = new & %0011 ' remember initial setting

    again:
    new = INB & %0011 ' get new reading
    IF new=old THEN again
    direct=new.BIT1 ^ old.BIT0 ' XOR left bit of new with right bit of old to get direction
    IF direct=1 THEN cw ' jump here to increment
    LOW 0 ' pin 0 turns led off id turning counter-clockwise
    counter=counter-1 ' jump here to decrement
    OUTH=counter.LOWBYTE
    GOTO start

    cw:
    HIGH 0 ' pin 0 turns on led if turning clockwise
    counter=counter+1
    OUTH=counter.LOWBYTE 'turn on leds on pins 8 through 15 to watch count
    GOTO start

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tom Sisk

    http://www.siskconsult.com
    ·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-09-21 20:31
    Also attached are the two examples I have posted in the past.· Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • Erik ArendallErik Arendall Posts: 21
    edited 2006-09-22 00:13
    My exact application is to create a test bench for the quad encoders that my company makes. I want to compare the output of a commercially available quad encoder to the output of our encoder. Then generate a checksum on the combined output. I really need to monitor speed and direction, cause I want to test the encoder over a range of speeds. Do you guys think that it would be possible to create an interface chip with a SX then feed the stamp a signal from the SX?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-09-22 04:46
    Erik,

    ·· If you look in the help file for SX/B, there is an example of reading the encoders using the SX Chip.· You could do it by itself.· Take care.


    EDIT: that should have read, "You can do it with the SX alone"

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support


    Post Edited (Chris Savage (Parallax)) : 9/22/2006 3:25:38 PM GMT
  • hutdonhutdon Posts: 32
    edited 2006-09-22 14:55
    A few years ago I had to come up with a solution for a very similiar problem. What I did was to get a LS7084 from www.usdigital.com. This chip does the actual quadrature decoding in hardware and outputs a pulse. This was fed to an Al Williams PAKVIIa (www.al-wiliams.com) which accumulated the pulses and sent the total to a BSII via SHIFTIN when commanded. It worked very well even at very high speeds. If I had to do it again I would try the SX example in the SX/b help file. I'm not sure of the maximum rotational speed - but it will certainly be much higher than the BSII can do, especially if the BSII has to do the decoding.
  • Erik ArendallErik Arendall Posts: 21
    edited 2006-09-22 17:38
    One of the reasons why I wanted to use a BS2 is familiarity with its hardware and firmware, but this gives me a good reason to learn the SX MCU. Plus from what I seen interfacing to the BS2 is a little easier. Thanks for all the input guys.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-09-22 19:54
    Erik,

    ·· Whether you use the SX or the BASIC Stamp the interface is the same.· In the case of PBASIC VS SX/B the code will be very similar as well.· What will differ greatly is performance.· You will find the SX able to read higher resolution encoders at a much faster rate than a BASIC Stamp with a lower resolution one.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • BeanBean Posts: 8,129
    edited 2006-09-22 20:32
    I assume 7200 PPM is pulses per minute ?
    If so, that is 120 pulses per second.
    The SX could do that without even breaking a sweat.
    Just yell in the SX forum if you need assistance.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    There are only two guaranteed ways to become weathy.
    Spend less than you make.
    Make more than you spend.
    ·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-09-22 21:30
    Bean, yeah the speed is listed based on a·motor RPM of 120, which leads me to believe that the encoder has 60 pulses per revolution.· As per my example a 16 pulse per revolution encoder can be too fast spun by hand, for the BS2.· Definately an SX project.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • John AbshierJohn Abshier Posts: 1,116
    edited 2006-09-22 22:40
    The encoder object for the Propeller has worked well for me and is very capable.
Sign In or Register to comment.