Parallax Servo Controller
Delus123
Posts: 9
I'm trying to connect my servo controller http://www.parallax.com/detail.asp?product_id=28023, to my prop using full duplex serial object but can't seem to get it to work. the code i'm using is:
pub Set(servo,pos,ra)
· 'servo-servo to be set(0-31), pos-servo position(280-1220), ra-ramp rate(1-64)
· ser.str(string("!SC"))
· ser.dec(servo)
· ser.dec(ra)
· ser.dec(pos)
· ser.hex($0D,2)
and the example in the manuel is(for the BS2):
baud CON 396
pw = 1250
SEROUT 15, baud+$8000,[noparse][[/noparse]"!SC", ch, ra, pw.LOWBYTE, pw.HIGHBYTE, CR]
i've called the start function of "ser", which is fullduplexserial.spin, setting the baud rate to 2400 and my tx pin to the pin that the controller is connected to.
if anyone has done anything like this help would be greatly apreciated.·· i've tryed using the BS2 object but am not sure about all the variables it calls for such as "bits" int the serout_string.
the servo 32 function works great but i ran out of pins .
Post Edited (Delus123) : 12/19/2006 11:26:17 PM GMT
pub Set(servo,pos,ra)
· 'servo-servo to be set(0-31), pos-servo position(280-1220), ra-ramp rate(1-64)
· ser.str(string("!SC"))
· ser.dec(servo)
· ser.dec(ra)
· ser.dec(pos)
· ser.hex($0D,2)
and the example in the manuel is(for the BS2):
baud CON 396
pw = 1250
SEROUT 15, baud+$8000,[noparse][[/noparse]"!SC", ch, ra, pw.LOWBYTE, pw.HIGHBYTE, CR]
i've called the start function of "ser", which is fullduplexserial.spin, setting the baud rate to 2400 and my tx pin to the pin that the controller is connected to.
if anyone has done anything like this help would be greatly apreciated.·· i've tryed using the BS2 object but am not sure about all the variables it calls for such as "bits" int the serout_string.
the servo 32 function works great but i ran out of pins .
Post Edited (Delus123) : 12/19/2006 11:26:17 PM GMT
Comments
Harrison
Harrison
CON
·· _clkmode = xtal1 + pll16x
·· _xinfreq = 5_000_000
OBJ
·· ser : "FullDuplexSerial"
PUB Main
·· dira[noparse][[/noparse]16] := 1
·· Start(7,21)· 'Im just using the set function which dosnt return anything so 21 is an unused pin.··
·· set(0, 1240, 7)
·· repeat
····· waitcnt(50_000_000+cnt)
····· !outa[noparse][[/noparse]16]·············· 'pin 16 is conected to an led to show me that it's at least doing some thing
····· set(1, 260, 7)
PUB Start(rxpin, txpin)
·· ser.start(rxpin, txpin, 2, 2400)
PUB Set(servo, pos, ra)
·· ser.str(string("!SC"))
·· {ser.tx($21)
·· ser.tx($53)
·· ser.tx($43)}
·· ser.tx(servo)
·· ser.tx(ra)
·· ser.tx((pos & $FF00) >> 8)
·· ser.tx(pos & $FF)
·· ser.tx($0D)
PUB stop
·· ser.stop
I've been looking at the simple serial object and if i can get it to work whold probably be perfect.· The controller manual, http://www.parallax.com/dl/docs/prod/motors/ServoControllerManualRevBv2_4.pdf, specifies the default baud rate as "2400 N 8 2, (no parity, eight data·bits, two stop bits)true data, open-drain (driven low, pulled high)."
Your mode was set to decimal 2, which is %0010 in binary. This evaluates to invert tx, which is definately not what you want since you want to send non-inverted 'true' serial data. So what you need to do is change mode to %0100 or decimal 4 to use open drain true mode.
So change your start to:
Harrison
Good to hear it works.
Harrison
Mike