Shop OBEX P1 Docs P2 Docs Learn Events
program for a digital servo — Parallax Forums

program for a digital servo

jaspittmanjaspittman Posts: 22
edited 2008-06-08 22:43 in BASIC Stamp
I tried to program for a digital servo and could not get it to function properly. I have included the code I used. On a slandered servo the program will rotate the servo clockwise one way hold for a few seconds and then rotate it the other way. With a hitec hs-5645mg the servo will move clockwise and then it stutters as it very slowly tries to moves counter clockwise. Any idea why.
'
[noparse][[/noparse]initialization]

reset:
LOW servo

'
[noparse][[/noparse]initialization]

Main:
counter = 0
FOR counter = 1 TO 1000
PULSOUT servo, (1000*/ pwAdj)
PAUSE 20
NEXT

FOR counter = 1 TO 1000
PULSOUT servo, (2000*/ pwAdj)
PAUSE 20
NEXT

END

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-06-08 21:17
    What value is pwAdj and what are you trying to acompish with your program? Could you attach your complete program?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • jaspittmanjaspittman Posts: 22
    edited 2008-06-08 22:03
    I was wanting to test the servo and see if it would operate like a non-digital servo.


    ' {$PBASIC 2.5}


    '
    [noparse][[/noparse]I/O]


    servo PIN 8


    '
    [noparse][[/noparse]constants]

    pwAdj CON $0080 ' pulse width adjust = .5


    '
    [noparse][[/noparse]initialization]

    reset:
    LOW servo

    '
    [noparse][[/noparse]initialization]

    Main:
    counter = 0
    FOR counter = 1 TO 1000
    PULSOUT servo, (1000*/ pwAdj)
    PAUSE 20
    NEXT

    FOR counter = 1 TO 1000
    PULSOUT servo, (2000*/ pwAdj)
    PAUSE 20
    NEXT

    END
  • Mike GreenMike Green Posts: 23,101
    edited 2008-06-08 22:43
    The "*/" operator only works for left operands from 0-255. If you want to use the actual pulse width and adjust it, use "/". In this case, pwAdj would be 2 and the expression in the PULSOUT would be 1000/pwAdj or 2000/pwAdj.
Sign In or Register to comment.