Shop OBEX P1 Docs P2 Docs Learn Events
Help with pwm and servos. — Parallax Forums

Help with pwm and servos.

AngelAngel Posts: 4
edited 2006-03-07 07:09 in General Discussion
Would someone help me, I can't get to work the SX for controlling a hobby servo , I tried the PWM command, but its giving me some error that says "byte parameter expected"

what I wrote., well actually I used the template that comes in the help.

**********
'
' Device Settings
'
DEVICE········· SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ··········· 4_000_000
'
' IO Pins
'
Sio············ VAR···· Ra.0··················· ' 1 IO pin
'
· INTERRUPT
'
ISR_Start:
· ' ISR code here
ISR_Exit:
· RETURNINT ' {cycles}································
' =========================================================================
· PROGRAM Start
' =========================================================================
Pgm_ID:
· DATA· "SX/B Template", 0
'
' Program Code
'
Start:
· ' initialization code here

Main:
· ' main code here
pwm RA.0, .0015, 8· 'What I expect here is that on port RA.0 i will get a PWM signal with .0015 seconds of duty cycle and for 8 seconds of duration.

· GOTO Main

********************


the idea·of the·project·is to control a robot and to vary the times on each servo to make it move while the other servos stay in the same position..., I know I am far from that, but, well I gotta make 1 servo move first lol..

thanks.

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-02 22:36
    PWM is not for motor control; it is used for charging an RC network to create an analog ouput (which should be buffered). For servo control you need to use PULSOUT or, when you get more advanced, use an interrupt-driven routine that can update your servos in the "background."

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • AngelAngel Posts: 4
    edited 2006-03-02 22:42
    I had the feeling something was wrong, but aren't the signals that control servos similar to pwm? maybe not.. well thanks , I will check that pulseout command, thanks
  • Mike CookMike Cook Posts: 829
    edited 2006-03-02 23:34

    Angel,

    Here's a little SX/B program that operates a servo. This was just for testing the movement for various positions, should be commented enough to determine it's operation.

    Mike

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "OEM NMEA GPS Module" Now available on ebay for only $17.49

    Product web site: http://www.allsurplus.net/Axiom/

    Post Edited (Mike Cook) : 3/2/2006 11:38:17 PM GMT
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-03-02 23:38
    PULSOUT is used to send the pulse, and you'll need to do it every 20 milliseconds or so (unless you're using a digital servo).· If you want to do it in the background, you'll need an ISR -- which is possible in SX/B as you can see from the attached demo.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • AngelAngel Posts: 4
    edited 2006-03-07 07:09
    Thanks Mike Cook and Jon Williams , I will check the files =)
Sign In or Register to comment.