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

encoder problem

Let's Go!Let's Go! Posts: 124
edited 2010-11-17 16:04 in Robotics
i tried the position controller and the rotary encoder, with very little luck. this post regards the rotary encoder. the program is set up to send a high to another bs2, which controls the motor, from the encoder bs2. the receiving pins are active high. when the rotary encoder gets to 48, 96, or 2, the pins are supposed to send the high.

the objective for the robot is to go back and forth through this routine. starts at 0, goes to 48, then 96, then back to 48 and back to 2, for precision.

it will sense the 48, stop as directed, go to 96, sometimes stop as directed, goes back to 48, and never stops as directed, and goes on to 2, and never stops as directed.

so, the objective is for precison, but i can't make it even complete the routine. i feel i have tried all solutions, except for the timing of the bs2's. i.e. maybe the bs2 is not quick enough.

any ideas? i appreciate all who respond.

jim

' =========================================================================
'
' File...... Easy Encoder V1.0.bs2
' Purpose... Read A Rotary/Quadrature Encoder
' Author.... Parallax, Inc.
' E-mail.... support@parallax.com
' Started...
' Updated... 06-07-2010
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================


'
[ Program Description ]

' This code demonstrates reading a rotary/quadrature encoder using a BASIC
' Stamp 2 Module. This code will work on the BS2e, BS2sx, BS2p24, BS2p40,
' BS2pe and BS2px24.

' A Output Connects To P0 (use 10K pull-up to VDD)
' B Output Connects To P1 (use 10K pull-up to VDD)
' C (COM) Connects to GND

' By default a counter is displayed using the DEBUG terminal, however you
' can get better peformance when not having to update the DEBUG terminal
' serially (which is relatively slow).


'
[ I/O Definitions ]



'
[ Variables ]

oldBits VAR Nib ' Previous State Of I/O Pins 0 - 1
newBits VAR Nib ' Current State Of I/O Pins 0 - 1
counter VAR Byte ' Counter (0-255)
turntable PIN 13
cart PIN 15
index VAR Word



'
[ Initialization ]

newBits = INA & %0011
oldBits = newBits
counter = 0
DEBUG HOME, DEC3 counter ' Show Current Counter On DEBUG Screen

stache DATA "!7!"



'
[ Program Code ]

Main:


DO
newBits = INA & %0011 ' Get State Of I/O Pins 0, 1
IF newBits <> oldBits THEN ' Have Bits Changed?
counter = counter - 1 + (2 * (newBits.BIT0 ^ oldBits.BIT1))
DEBUG HOME, DEC3 counter ' Show New Counter On DEBUG Screen
oldBits = newBits ' Update oldBits
IF counter=48 THEN mid 'high 5 to bs2 pin 6
IF counter = 96 THEN dx 'high 8 to bs2 9
IF counter = 2 THEN first 'high 10 to bs2 10


ENDIF
LOOP
STOP


mid:

HIGH 5
PAUSE 100
LOW 5

DEBUG "mid"

GOTO main

dx:

HIGH 8
PAUSE 100
LOW 8

DEBUG "dx"


GOTO main


first:

HIGH 10
PAUSE 100
LOW 10

DEBUG "first"

GOTO main

Comments

  • Let's Go!Let's Go! Posts: 124
    edited 2010-11-17 15:40
    i have added the program..
  • Let's Go!Let's Go! Posts: 124
    edited 2010-11-17 15:55
    i send from pins 5, 8, and 10 on the encoder bs2 to pins 6,9, and 10 on the receiving bs2 which controls the motor.
  • Let's Go!Let's Go! Posts: 124
    edited 2010-11-17 16:04
    encoder pin a is connected to bs2 p0 to 10k, to +5v, as is the encoder pin b and bs2 p1, as per instructions.
Sign In or Register to comment.