Shop OBEX P1 Docs P2 Docs Learn Events
Need help with stepper motor program — Parallax Forums

Need help with stepper motor program

Keith VandKeith Vand Posts: 3
edited 2008-04-05 22:17 in BASIC Stamp
I wrote a rather lengthy program to control my senior design project, but the stepper motor part of it is causing a problem.· I need the stepper motor to rotate 132 times, that is 26,400 steps.· When the program gets to that part of the program the stepper motor rotates maye 10-20 times and then the whole program restarts.· This is the part of the program giving problems.

Rotate_Vert:
DEBUG "Rotating to Vertical: "
· Steps=26400
· DEBUG DEC Steps
· DEBUG " "
· OUTA=$1
· PAUSE 007
· DO
··· OUTA=$2
··· PAUSE 007
··· Steps=Steps-1
··· IF (Steps=0) THEN EXIT
··· DEBUG DEC Steps
··· DEBUG " "
··· OUTA=$4
··· PAUSE 007
··· Steps=Steps-1
··· IF (Steps=0) THEN EXIT
··· DEBUG DEC Steps
··· DEBUG " "
··· OUTA=$8
··· PAUSE 007
··· Steps=Steps-1
··· IF (Steps=0) THEN EXIT
··· DEBUG DEC Steps
··· DEBUG " "
··· OUTA=$1
··· PAUSE 007
··· Steps=Steps-1
··· IF (Steps=0) THEN EXIT
··· DEBUG DEC Steps
··· DEBUG " "
· LOOP
· PAUSE 1000
· OUTA=$0
· Status=1····· 'Position is remembered
DEBUG "Now in Vertical Position - "

Does anyone know why this would happen?· I have rewritten the program a few different ways and the result is always the same.

Post Edited (Keith Vand) : 4/5/2008 7:23:18 PM GMT

Comments

  • phil kennyphil kenny Posts: 233
    edited 2008-04-05 19:37
    Attach your entire program and perhaps you will get help.

    The problem may be in how you have declared the variables.

    phil
  • Keith VandKeith Vand Posts: 3
    edited 2008-04-05 19:58
    Ok, this is the whole program, and I attached a image file of the schematic of my circuit if that helps.


    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    DIR0=1
    DIR1=1
    DIR2=1
    DIR3=1
    DIR15=1
    Time VAR Nib
    Cycles VAR Nib
    Status VAR Bit
    Steps VAR Word
    Cycles=0
    Status=0
    FOR Cycles = 1 TO 15
    · IF (Status=0) THEN GOSUB Move
    · IF (Status=0) THEN GOSUB Rotate_Vert
    · IF (Status=1) THEN GOSUB Dive
    · IF (Status=1) THEN GOSUB Rotate_Hor
    · DEBUG "End of Cycle "
    · DEBUG DEC Cycles
    · DEBUG " - "
    NEXT
    Hold:
    GOTO Hold
    Move:
    DEBUG "Move Sequence: "
    OUT15=1
    Time=15
    DO WHILE (IN13=0)
    · DEBUG DEC Time
    · DEBUG " "
    · PAUSE 1000
    · Time=Time-1
    · IF (Time=0) THEN EXIT
    LOOP
    OUT15=0
    DEBUG "End of Move Sequence - "
    RETURN

    Rotate_Vert:
    DEBUG "Rotating to Vertical: "
    · Steps=264000
    · DEBUG DEC Steps
    · DEBUG " "
    · OUTA=$1
    · PAUSE 007
    · DO
    ··· OUTA=$2
    ··· PAUSE 007
    ··· Steps=Steps-1
    ··· IF (Steps=0) THEN EXIT
    ··· DEBUG DEC Steps
    ··· DEBUG " "
    ··· OUTA=$4
    ··· PAUSE 007
    ··· Steps=Steps-1
    ··· IF (Steps=0) THEN EXIT
    ··· DEBUG DEC Steps
    ··· DEBUG " "
    ··· OUTA=$8
    ··· PAUSE 007
    ··· Steps=Steps-1
    ··· IF (Steps=0) THEN EXIT
    ··· DEBUG DEC Steps
    ··· DEBUG " "
    ··· OUTA=$1
    ··· PAUSE 007
    ··· Steps=Steps-1
    ··· IF (Steps=0) THEN EXIT
    ··· DEBUG DEC Steps
    ··· DEBUG " "
    · LOOP
    · PAUSE 1000
    · OUTA=$0
    · Status=1····· 'Position is remembered
    DEBUG "Now in Vertical Position - "
    RETURN
    Dive:
    DEBUG "Dive Sequence: "
    OUT15=1
    DO WHILE (IN14=0)
    · PAUSE 1000
    · DEBUG "Diving... "
    LOOP
    OUT15=0
    DEBUG "End of Dive Sequence - "
    RETURN
    Rotate_Hor:
    DEBUG" Rotating to Horizontal: "
    · Steps=264000
    · DEBUG DEC Steps
    · DEBUG " "
    · OUTA=$1
    · PAUSE 007
    · DO
    ··· OUTA=$8
    ··· PAUSE 007
    ··· Steps=Steps-1
    ··· IF (Steps=0) THEN EXIT
    ··· DEBUG DEC Steps
    ··· DEBUG " "
    ··· OUTA=$4
    ··· PAUSE 007
    ··· Steps=Steps-1
    ··· IF (Steps=0) THEN EXIT
    ··· DEBUG DEC Steps
    ··· DEBUG " "
    ··· OUTA=$2
    ··· PAUSE 007
    ··· Steps=Steps-1
    ··· IF (Steps=0) THEN EXIT
    ··· DEBUG DEC Steps
    ··· DEBUG " "
    ··· OUTA=$1
    ··· PAUSE 007
    ··· Steps=Steps-1
    ··· IF (Steps=0) THEN EXIT
    ··· DEBUG DEC Steps
    ··· DEBUG " "
    · LOOP
    · PAUSE 1000
    · OUTA=$0
    · Status=0······· 'Position is remembered
    DEBUG "Now in Horizontal Position - "
    RETURN

    attachment.php?attachmentid=53114
  • Keith VandKeith Vand Posts: 3
    edited 2008-04-05 20:42
    I just found out that the program works exactly as intended when I disconnect the motor.· How could the motor cause the stamp to reset? Do I need to put a resistor or diode inbetween the stamp and the high power transisters?
  • phil kennyphil kenny Posts: 233
    edited 2008-04-05 22:17
    Base resistors between the Stamp output pins and the transistors
    driving the motor are needed to limit the current from the Stamp.

    From the Basic Stamp FAQ:

    On the BASIC Stamp I and BASIC Stamp II, each I/O pin is capable of
    sourcing 20 mA and sinking 25 mA. The total across all I/O pins should
    not exceed 40 mA source or 50 mA sink at any given time, however.

    One exception to this rule exists with the BS2-IC. If the BS2-IC is powered
    by an external 5-volt regulator capable of delivering at least 100 mA, the
    total across each group of 8 I/O pins (0 - 7 and 8 - 15) can reach 40 mA source
    or 50 mA sink providing a total of 80 mA source or 100 mA sink overall


    In addition, it may be a power supply issue.

    Try running the Stamp from a separate source.

    phil

    Post Edited (phil kenny) : 4/5/2008 10:23:36 PM GMT
Sign In or Register to comment.