Shop OBEX P1 Docs P2 Docs Learn Events
rotary encoder — Parallax Forums

rotary encoder

ArchiverArchiver Posts: 46,084
edited 2004-05-30 01:06 in General Discussion
Hi everyone

is there a way to serial out the count, except to use pin 8 to 15 on
this particular program. I need all the pin on my BS2 for input
signals, can I use the internal EEPROM I dont know I am beginer.

' {$stamp bs2}
'{$PORT COM1}

' Program to act as high speed quadrature counter

DIRH = %11111111

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

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

start:
old = new & %1100 ' remember initial setting
Again:
new = INB & %1100 ' get new reading
IF new = old THEN again
directn = new.BIT1 ^ old.BIT0 ' XOR left bit of new with right
bit of old to get direction
IF directn = 1 THEN CW ' jump here to increment
LOW 0 ' pin 0 turns led off if turning counter-
clockwise
counter = (counter+1) ' jump here to decrement
OUTH = counter
DEBUG DEC counter,CR
GOTO again

CW:
HIGH 0 ' pin 0 turns on led if turning clockwise
counter = (counter-1)
OUTH = counter 'turn on leds on pins 8 through 15 to watch
DEBUG DEC counter,CR
GOTO start

I want to serial out the count but not use pin 8 to 15, because I
need the pins for over travel, home position.... ect

Thank you for your help

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2004-05-30 01:06
    --- In basicstamps@yahoogroups.com, "vermettechristian"
    <christian_vermette@v...> wrote:
    > Hi everyone
    >
    > is there a way to serial out the count, except to use pin 8 to 15
    on
    > this particular program. I need all the pin on my BS2 for input
    > signals, can I use the internal EEPROM I dont know I am beginer.
    >
    > ' {$stamp bs2}
    > '{$PORT COM1}
    >
    > ' Program to act as high speed quadrature counter
    >
    > DIRH = %11111111
    >
    > counter VAR Word
    > counter2 VAR Word
    > counter3 VAR Word
    > old VAR Nib
    > new VAR Nib
    > directn VAR Byte
    >
    > ' Channel a and b of encoder go on inputs 6 and 7 in this case.
    > quad:
    > counter = 125 'load a dummy value so can count up or down
    > new = INB & %0011 ' get initial condition
    >
    > start:
    > old = new & %1100 ' remember initial setting
    > Again:
    > new = INB & %1100 ' get new reading
    > IF new = old THEN again
    > directn = new.BIT1 ^ old.BIT0 ' XOR left bit of new with right
    > bit of old to get direction
    > IF directn = 1 THEN CW ' jump here to increment
    > LOW 0 ' pin 0 turns led off if turning
    counter-
    > clockwise
    > counter = (counter+1) ' jump here to decrement
    > OUTH = counter
    > DEBUG DEC counter,CR
    > GOTO again
    >
    > CW:
    > HIGH 0 ' pin 0 turns on led if turning clockwise
    > counter = (counter-1)
    > OUTH = counter 'turn on leds on pins 8 through 15 to watch
    > DEBUG DEC counter,CR
    > GOTO start
    >
    > I want to serial out the count but not use pin 8 to 15, because I
    > need the pins for over travel, home position.... ect
    >
    > Thank you for your help


    Christian,

    There's no requirement for outputs 8 - 15 to be used to show the
    output count. I originally put it there for troubleshooting.

    Just take out the two instances of "OUTH = counter" and use pins
    8 - 15 as you need. To get the data out, change your DEBUG statement
    to a SEROUT and send data out pin 16 ( the programming port ). That
    way you have maximum pins for your application.

    You can save one more pin by not using the direction indication
    provided by pin 0.

    Tom Sisk
Sign In or Register to comment.