Shop OBEX P1 Docs P2 Docs Learn Events
PULSOUT command hassles — Parallax Forums

PULSOUT command hassles

TimmyTimmy Posts: 10
edited 2005-09-26 12:28 in BASIC Stamp
g'day all,

having some hassles with pulsout which i am using to instruct my servo. I've included my code. The problem is, that the servo is moving to the far right and trying to go beyond, ie 2ms. If I remove the "pulse" variable from the PULSOUT command and replace it with an integer like 750, the pulsout command works fine. I am certain that you can use a variable label for the pulsewidth value in PULSOUT.

' {$STAMP BS2}
' {$PBASIC 2.5}

servo VAR OUT0
pulse VAR byte
pulse = 500

start:
pulse = 20 + pulse
PULSOUT servo, pulse
PAUSE 20
IF pulse >= 1000 THEN endseq
GOTO start

endseq:
END

Comments

  • TimmyTimmy Posts: 10
    edited 2005-09-26 10:11
    hi folks,
    i have solved my own problem, I set up a debug window and noticed that there was an overflow. Once I changed the variable from byte to word it worked.

    cheers,
    tim
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-09-26 12:28
    Another way to handle that bit of code is with a FOR-NEXT loop.· Note, too, that you should initialize servo outputs low before using PUSLOUT:

    Servo··· PIN··· 0

    pulse··· VAR··· Word

    Setup:
    · LOW Servo

    Main:
    · FOR pulse = 500 TO 1000 STEP 20
    ··· PULSOUT Servo, pulse
    ··· PAUSE 20
    · NEXT




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