Shop OBEX P1 Docs P2 Docs Learn Events
Parallax Servo Controller Code question — Parallax Forums

Parallax Servo Controller Code question

cutsrockcutsrock Posts: 32
edited 2007-11-01 12:45 in BASIC Stamp
Hope this question is in the correct forum.

I am using the PSC with a BS2 and have been working with the code to drive multiple servos.· The code I am working with is:

' {$STAMP BS2}
' {$PBASIC 2.5}
'PSC - Controlling four servos - Servos 0 & 2 rotate same direction and
'Servos 1 & 15 rotate same direction.

ch······ VAR···· Byte···················· · 'PSC channel
pw0···· VAR···· Word····················· 'Pulsewidth for Servos 0 & 2
pw1···· VAR···· Word····················· 'Pulsewidth for Servos 1 & 15
ra······ ·VAR···· Byte···················· · 'Ramp rate
Sdat··· CON···· 15························ ·'Serial data pin
baud··· CON···· 396······················· ·'Constant for 2400 baud
· ra· = 7
· ch = 0

DO
· pw0 = 1200
· pw1 =· 300

· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", ch,······ra, pw0.LOWBYTE, pw0.HIGHBYTE, CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", ch+1,· ·ra, pw1.LOWBYTE, pw1.HIGHBYTE, CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", ch+2,·· ra, pw0.LOWBYTE, pw0.HIGHBYTE, CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", ch+15, ra, pw1.LOWBYTE, pw1.HIGHBYTE, CR]
· PAUSE 1000

· pw0 =· 300
· pw1 = 1200

· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", ch,····· ra, pw0.LOWBYTE, pw0.HIGHBYTE, CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", ch+1,· ·ra, pw1.LOWBYTE, pw1.HIGHBYTE, CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", ch+2,· ·ra, pw0.LOWBYTE, pw0.HIGHBYTE, CR]
· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", ch+15,· ra, pw1.LOWBYTE, pw1.HIGHBYTE, CR]
· PAUSE 1000
LOOP

Is there a way to operate the pulsewidth similar to the channel.· "ch", ch+1, ch+2, ch+15.
Instead of pw0 or pw1 use a statement like:

·pw = 1200

· SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", ch, ra, pw-900.LOWBYTE, pw-900.HIGHBYTE, CR]

I know the above statement does not work, but is there a way to set the aliases and Modifiers to do so?

Thanks


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
EPIC FAILURE -·When everyday run-of-the-mill failure just isn't good enough.

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-11-01 03:01
    Cutsrock -

    Yes, you can but just slightly differently since you're working with a WORD sized variable and not a BYTE sized variable. Here is what you had that DOESN'T work:

    SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", ch, ra, pw-900.LOWBYTE, pw-900.HIGHBYTE, CR]

    Change it to something like this:

    PW_work VAR WORD

    PW_work = pw - 900

    SEROUT Sdat, Baud+$8000,[noparse][[/noparse]"!SC", ch, ra, PW_work.LOWBYTE, PW_work.HIGHBYTE, CR]

    There are other ways to do it, but that's about the cleanest, and most understandable.

    Regards,

    Bruce Bates

    Post Edited (Bruce Bates) : 11/1/2007 3:17:43 AM GMT
  • cutsrockcutsrock Posts: 32
    edited 2007-11-01 12:45
    Thanks Bruce.· I will implement your solution.



    Thanks again.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    EPIC FAILURE -·When everyday run-of-the-mill failure just isn't good enough.
Sign In or Register to comment.