Shop OBEX P1 Docs P2 Docs Learn Events
Need Help, Servo Activity #3 Problem Chap 4 "What's a MicroController?" — Parallax Forums

Need Help, Servo Activity #3 Problem Chap 4 "What's a MicroController?"

mchistimchisti Posts: 11
edited 2012-02-04 19:13 in BASIC Stamp
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:
' {$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

  • PJAllenPJAllen Banned Posts: 5,065
    edited 2012-02-04 11:28
    You're using a BoE or HWB or what?
    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.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    counter VAR Word
    
    PAUSE 1000
    
    Routine:
      DEBUG "45", CR
    
      FOR counter = 1 TO 150
        PULSOUT 14, 500
        PAUSE 19
        NEXT
    
      DEBUG "90", CR
      FOR counter = 1 TO 150
        PULSOUT 14, 750
        PAUSE 19
        NEXT
    
      DEBUG "130", CR
    
      FOR counter = 1 TO 150
        PULSOUT 14, 1000
        PAUSE 19
        NEXT
    
      GOTO Routine
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-02-04 11:48
    What are you using for a power supply.
    keeps displaying "Position = 45 degrees" on the terminal

    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.
  • mchistimchisti Posts: 11
    edited 2012-02-04 14:55
    It was a Homework Board.
    Duane Degn wrote: »
    What are you using for a power supply.



    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. :lol:
  • ercoerco Posts: 20,256
    edited 2012-02-04 18:50
    IIRC, WAM even shows the HW board's 9V battery being used to power the servo. Convenient, but not desirable. First choice would be a seperate battery, at least 4x AA cells.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-02-04 19:13
    erco wrote: »
    IIRC, WAM even shows the HW board's 9V battery being used to power the servo. Convenient, but not desirable. First choice would be a seperate battery, at least 4x AA cells.

    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.
Sign In or Register to comment.