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

encoder BS2P

BernardBernard Posts: 3
edited 2004-12-29 14:31 in BASIC Stamp
Hi, everbody

I start, I don't arrive to translate for BS2P in vers 2.5 the part of·PGM downloaded
on parallax site.
Can you help me, thanks

Bernard

' {$STAMP BS1}
' {$PBASIC 1.0}
' Stamp Applications no. 8, October 1995
' Program Listing Demonstrating Use Of a Rotary Encoder
' Program: Rotary.BAS (Read a rotary encoder and scroll a display)

SYMBOL old = B0
SYMBOL new = B1
SYMBOL directn = BIT0
······························· ' Before entering the main loop, the program stores
·the·beginning
································ ' state of the encoder bits into the variable 'new.'

· LET new = PINS & %11000000··· ' It ANDs the pins with %11000000 in order to strip off all bits except for
································ ' 6 and 7. (ANDing a bit with 0 always produces 0; ANDing with 1
································ ' copies the state of the bit.)
start:
· LET old = new & %11000000
······························· ' Mask bits and copy new into old.
again:
· LET new = PINS & %11000000···· ' Copy encoder bits to new.
· IF new = old THEN again······· ' If no change, try again.
· LET directn = BIT6 ^ BIT15···· ' XOR right bit of new w/ left bit of old.
· IF directn = 1 THEN CW········ ' If result=1, encoder turned clockwise.
································ ' If result=0, counterclock (scroll left).
· GOTO start
······························· ' Do it again.
CW:
······························· ' Clockwise (scroll right).
· GOTO start··················· ' Do it again.

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-12-29 14:31
    This is a direct translation of the program you reference, but it shows how to read a quadrature encoder with the BS2 family.· Since you're new, you may consider reading our "What's A Microcontroller?" book to get up to speed on PBASIC programming.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.