Shop OBEX P1 Docs P2 Docs Learn Events
Rotary encoder and Basic Stamp 1. — Parallax Forums

Rotary encoder and Basic Stamp 1.

Happytriger2000Happytriger2000 Posts: 14
edited 2007-10-03 17:55 in BASIC Stamp
Hi everyone,
················ Im currently doing a project related to motion control, and the task is to read the quadrature signal output of a rotary encoder's channel A and channel B and feed into Basic Stamp 1 then output to a stepper motor. Can anyone give some tips to start with?

tongue.gif

Freddy

Comments

  • Happytriger2000Happytriger2000 Posts: 14
    edited 2007-09-27 20:09
    Hi Stephenwanger,
    ························ Thanks for the links. The Spin-and-Grin project use a rotary encoder and a LCD, may I know which part of the program of LCD need to be changed to fit the steeper motor?.

    Im a begginner in Basic Stamp.

    Freddy
  • stephenwagnerstephenwagner Posts: 147
    edited 2007-09-27 20:55
    What do you want the motor to do????

    1. Follow the rotory encoder step by step????

    2. Speed motor up and down????

    3. What kind of stepper motor do you have???? Bipolar or Unipolar????

    Parallax App. note No. 6. describes how to use a BS1 and bi-polar stepper motor.
    http://www.parallax.com/dl/appnt/stamps/bs1Appnotes.pdf

    You will need a current amplifier/driver·for both.

    SJW

    ·
  • stephenwagnerstephenwagner Posts: 147
    edited 2007-09-27 21:06
    I am sorry

    Parallax App. note No. 6. describes how to use a BS1 and bi-polar BIPOLAR stepper motor.
    http://www.parallax.com/dl/appnt/stamps/bs1Appnotes.pdf
  • stephenwagnerstephenwagner Posts: 147
    edited 2007-09-27 21:07
    Parallax App. note No. 6. describes how to use a BS1 and bi-polar UNIPOLAR stepper motor.
    http://www.parallax.com/dl/appnt/stamps/bs1Appnotes.pdf
  • Happytriger2000Happytriger2000 Posts: 14
    edited 2007-09-30 16:31
    Hello Stephenwanger,

    ···························· Sorry for the late reply.

    Yes, I want the stepper motor to follow the rotary encoder step by step, or the same speed as the encoder.

    Im using a rotary encoder of 500 p/r and a 1.8degree/step 6 wires stepper motor and as for the stepper driver it accepts Step and Dir. I know how to send the signal pulse to the stepper driver but dont know how to receive signal from the encoder.

    Freddyeyes.gif
  • sdysdy Posts: 40
    edited 2007-09-30 18:36
    Typicaly, using encoders, when one output line, A, goes hi, that's one click. Then you look at the other output line, B, and if 1 or 0 then it turned CW or CCW.
    So, in a loop, check if A is hi. If it is, check B. If hi, add one to a counter, if low subtract one.

    IF A = 1 THEN
    IF B = 1 THEN
    Cntr = Cntr+1
    ELSE
    Cntr = Cntr-1
    ENDIF
    ENDIF
  • sdysdy Posts: 40
    edited 2007-09-30 18:37
    Typicaly, using encoders, when one output line, A, goes hi, that's one click. Then you look at the other output line, B, and if 1 or 0 then it turned CW or CCW.
    So, in a loop, check if A is hi. If it is, check B. If hi, add one to a counter, if low subtract one.
    Something like:
    IF A = 1 THEN
    IF B = 1 THEN
    Cntr = Cntr+1
    ELSE
    Cntr = Cntr-1
    ENDIF
    ENDIF
  • kelvin jameskelvin james Posts: 531
    edited 2007-09-30 23:03
    This is how i do it with a bsp24 and stepper driver module, it runs step per step, encoder to motor and changes the direction. Unfortunatley, i have no idea how to port it over to bs1 code.


    old VAR Nib
    new VAR Nib
    ob VAR old.BIT0
    nb VAR new.BIT1
    cnt VAR Word


    HIGH 14 'set driver direction pin

    Start:

    decode:
    old=INC & 3 'get encoder state on pins 8 and 9
    new=INC & 3
    IF new=old THEN decode 'loop if no change
    cnt=(ob^nb)*2-1+cnt ' calculate motion
    IF (ob^nb)*2-1=-1 THEN LOW 14 'if reverse set driver pin to counter c/w

    PULSOUT 15,25 'pulse motor driver pin 15

    old=new

    GOTO Start
  • Happytriger2000Happytriger2000 Posts: 14
    edited 2007-10-02 04:19
    Thanks SDY and Kelvin James for your reply.
    I only have Basic Stamp 1 module, so the program has to be compatible with BS1.

    The program below by SDY, is it a complete program? Because for If..then command, usually after·'THEN' there should be something else, isnt it?, for example, 'If A = 1 Then cw'.

    IF A = 1 THEN
    IF B = 1 THEN
    Cntr = Cntr+1
    ELSE
    Cntr = Cntr-1
    ENDIF
    ENDIF

    Currently Im experimenting the program to run the stepper motor by using a switch, I wrote:

    check:
    If pin·3 = high then cw ( a switch connected to pin 3·with 5v input to give a 'high')
    if pin 4 = high the ccw ( a switch connected to pin 4· with 5v input to give a 'high')
    goto check

    cw:
    ···· Pulsout 1,200 (step signal to Driver board)

    ···· high 0·········· ( a low signal to DIR)

    goto check

    ccw:
    ······ pulsout 1,200
    ······
    ·······high 1

    goto check

    OK, is there anything wrong with the program I wrote above?

    Freddy
  • skylightskylight Posts: 1,915
    edited 2007-10-02 06:40
    sdy·put the line cntr=cntr+1 after the two·THEN statements·IF a=1 <newline>·IF b=1 and followed with two ENDIF's

    Im presuming that as the logic is AND'ed that that is the way to type it rather than the statement

    IF·a·AND b=1 THEN

    or

    IF a=1 AND b=1 THEN

    which i would have thought would save eeprom space( or is this interpreted by the basic editor either way·and still uses use the same coding space whichever you choose?)

    could this also be typed as

    if a,b=1 then· or something similar say IF(a,b)=1

    for the·other direction

    that would type as

    If A=1·AND b=0 THEN

    is this a correct assumption?

    Is there only one way of typing it then?




    Post Edited (skylight) : 10/2/2007 6:52:22 AM GMT
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-10-02 08:13
    skylight -

    You might do well to download a copy of the PBASIC Reference Manual, which can be downloaded for free from the Parallax web site. That contains all of the syntax and usage rules for the PBASIC language.

    There are two constructs for IF ... THEN one of which is single-line and the other is multi-line. Each has its uses and as far as I'm aware, both generate the same amount of p-code.

    As far as using connectives (AND, OR, etc) you must specify both conditions completely. In other words, the only proper way to check to see if two given variables are one and three respectively·is as follows:

    IF variable1 = 1 AND variable2 = 3 ...

    There are two ways to check if two variables are equal to the same value:

    IF variable1 = 1 and variable2 = 1 ...
    or
    IF variable1 =1 and variable2 = variable1 ...

    There is nothing implied in the IF ... THEN syntax, all parameters must be specified.

    All of this information is also available in the PBASIC Help File which is accessible from the PBASIC IDE or separately if you have it set up that way.

    Regards,

    Bruce Bates

    Post Edited (Bruce Bates) : 10/2/2007 8:19:32 AM GMT
  • Happytriger2000Happytriger2000 Posts: 14
    edited 2007-10-03 17:55
    A question to everyone:

    Can I use Pulsin to measure the pulse output of the Encoder? If yes, can anyone provide a sample program?

    Freedy
Sign In or Register to comment.