Shop OBEX P1 Docs P2 Docs Learn Events
Problem with controlling a simple servo — Parallax Forums

Problem with controlling a simple servo

Scott BScott B Posts: 5
edited 2012-01-12 10:50 in BASIC Stamp
I have a problem when I try to control a simple servo with the following code it appear the loop is not working correctly. All that happens is the servo moves to the 850 position and the debug screen shows "Program Running" over and over and over as if the loop never ends and it never does go to the second clockwise loop. I have a BS2 homework board and I am new to this, does anyone know what is wrong? Is there a setting or something that I should have changed? Thanks!



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




DEBUG "Program Running!"
counter VAR Word
FOR counter = 1 TO 120 ' Loop for three seconds
PULSOUT 14, 850 ' P14 servo counterclockwise
PAUSE 20
NEXT
FOR counter = 1 TO 124 ' Loop for three seconds
PULSOUT 14, 650 ' P14 servo clockwise
PAUSE 20
NEXT


END

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2012-01-11 21:31
    What's wrong is that your battery is weak. The attempt to move the servo exhausts the battery and its voltage drops enough to cause the Stamp to reset, then the battery gets a moment to rest and it all starts over again. Try a fresh battery. 9V alkalines don't have much capacity.
  • ercoerco Posts: 20,256
    edited 2012-01-12 08:46
    Per Mike, a new battery is in order. Far better than a 9V, use 4 alkaline AAs (4 C's or D's even better) in series in a battery box from Radio Shack or such, hooked to your HW board's Vin and Vss connections.
  • Scott BScott B Posts: 5
    edited 2012-01-12 10:50
    Thanks guys I was going crazy with this.
Sign In or Register to comment.