Need Help, Servo Activity #3 Problem Chap 4 "What's a MicroController?"
I'm doing Activity #3 in the What's a MicroController and was doing great, till I had to hold different positions for servo. I wrote the code exactly the way the text has it written (which is the copy you see below) and it doesn't work. When I execute the code, servo just twitched to the right about 2 degrees every one second. That gives me the feeling that the "PAUSE 1000" must somehow affect the servo in the FOR NEXT. I also know that it ignores the counter Variable because servo keeps displaying "Position = 45 degrees" on the terminal way after 15 times ( 150/50 = 15 ). Can someone help me? I tried putting the whole FOR NEXT inside the a DO LOOP and then tried nesting DO LOOP inside of FOR NEXT, then tried both :thumb:, but it did the same PAUSE 1000 twitch to the right by 2 degrees again.
The problem is, It just gets stuck and doesn't position it's self. The code is suppose to let servo rotate to 45 degrees, hold position for 3 seconds, then rotate to 90 degrees, hold for 3 secs, rotate to 135 degrees and hold for 3 secs, then code END.
Thank You![:smile: :smile:](https://forums.parallax.com/resources/emoji/smile.png)
The problem is, It just gets stuck and doesn't position it's self. The code is suppose to let servo rotate to 45 degrees, hold position for 3 seconds, then rotate to 90 degrees, hold for 3 secs, rotate to 135 degrees and hold for 3 secs, then code END.
Thank You
![:smile: :smile:](https://forums.parallax.com/resources/emoji/smile.png)
' {$STAMP BS2}
' {$PBASIC 2.5}
counter VAR Word
PAUSE 1000
DEBUG "Position = 45 degrees...", CR
FOR counter = 1 TO 150
PULSOUT 14, 500
PAUSE 20
NEXT
DEBUG "Position = 90 degrees...", CR
FOR counter = 1 TO 150
PULSOUT 14, 750
PAUSE 20
NEXT
DEBUG "Position = 130 degrees...", CR
FOR counter = 1 TO 150
PULSOUT 14, 1000
PAUSE 20
NEXT
DEBUG "All done.", CR, CR
END
Comments
The BoE switch has to be all the way over to the right. (There's Off - On - Servos_On)
It should hold each position for approx 3 sec.
Makes me think your Stamp keeps resetting when the servo tries to move. This is a very common problem when trying to drive servos. They pull a lot of current when they start to move which causes the voltage to drop, which in turn resets the microcontroller.
You need a good power source (not a 9V battery). A wall-wart transformer might work but I've had better luck with a good rechargable battery pack.
Thanks a lot, it was the battery problem. I didn't use an Alkaline Battery and now I just bought one.
That's too bad WAM adds to the problem of people under powering their servos. It seems like this problem comes up at least once a week on the fourm.