Shop OBEX P1 Docs P2 Docs Learn Events
servo control — Parallax Forums

servo control

frosliefroslie Posts: 67
edited 2005-08-27 22:04 in General Discussion
I am considering getting into the Sx. I am familiar with the BS2.

Can anyone tell me how easy it would be to control simple I/O relationships? For insatnce I would like to control a servo from a sensor.

If this is fairly easy to get at, it would seem on a very basic level to be a very cost effective solution over the BS2.

thank you

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,568
    edited 2005-08-27 22:04
    If you compare the BS2 to SX/B (< the "Free" Pbasic compiler for the SX), then the code is virtually the same.


    Code for the BS2 to pan a servo back-n-forth
    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    
    ServoPin  CON 0
    ServoMin  CON 1250  'equals 1mS at 0.8uS resolution
    ServoMax  CON 2500  'equals 2mS at 0.8uS resolution
    ServoTemp VAR W1
    
    LOW    ServoPin
    OUTPUT ServoPin
    
    MainLoop:
    
    FOR ServoTemp = ServoMin TO ServoMax STEP 10
        PULSOUT ServoPin,ServoTemp
        PAUSE 20
    NEXT
    FOR ServoTemp = ServoMax TO ServoMin STEP 10
        PULSOUT ServoPin,ServoTemp
        PAUSE 20
    NEXT
    
    GOTO MainLoop
    
    




    Code for the SX to pan a servo back-n-forth
    DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ            4_000_000
    
    
    ServoPin  VAR RB.0
    ServoMin  CON 100   'equals 1mS at 10uS resolution
    ServoMax  CON 200   'equals 2mS at 10uS resolution
    ServoTemp VAR Byte
    
     LOW    ServoPin
     OUTPUT ServoPin
    
    MainLoop:
    
    FOR ServoTemp = ServoMin TO ServoMax STEP 1
        PULSOUT ServoPin,ServoTemp
        PAUSE 20
    NEXT
    FOR ServoTemp = ServoMax TO ServoMin STEP 1
        PULSOUT ServoPin,ServoTemp
        PAUSE 20
    NEXT
    
    GOTO MainLoop
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
Sign In or Register to comment.