Debug Servo controller code please...
RN
Posts: 28
I am trying to run the servo controller USB from the stingray. Initially i tried it from matlab through the USB port. I opened the serial port in matlab and sent the follwing command and the servo moved
B=[33,83,67,0,0,50,1,13];
fwrite(s,B,'char');
Next I coded the propeller chip with the following code and connected the '0' pin of the propeller board to the serial in of the usb board. The servo is not responding please suggest
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
serial : "FullDuplexSerial.spin"
var
byte ServoCommand[8]
pub main
serial.start(-1,0,0,2_400)
pst.Start(2400)
ServoCommand[ 0 ] := "!"
ServoCommand[ 1 ] := "S"
ServoCommand[ 2 ] := "C"
ServoCommand[ 3 ] := 0
ServoCommand[ 4 ] := 0 'ramp-value
ServoCommand[ 5 ] := 55 'lowbyte of servo-position-value (250-1250)
ServoCommand[ 6 ] := 1 'highbyte of servo-position-value (250-1250)
ServoCommand[ 7 ] := 13
repeat
serial.str(@ServoCommand)
I have also tried this code but it is not running
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
serial : "FullDuplexSerial.spin"
pub main
repeat
serial.tx(33)
serial.tx(83)
serial.tx(67)
serial.tx(0)
serial.tx(0)
serial.tx(55)
serial.tx(1)
serial.tx(13)
B=[33,83,67,0,0,50,1,13];
fwrite(s,B,'char');
Next I coded the propeller chip with the following code and connected the '0' pin of the propeller board to the serial in of the usb board. The servo is not responding please suggest
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
serial : "FullDuplexSerial.spin"
var
byte ServoCommand[8]
pub main
serial.start(-1,0,0,2_400)
pst.Start(2400)
ServoCommand[ 0 ] := "!"
ServoCommand[ 1 ] := "S"
ServoCommand[ 2 ] := "C"
ServoCommand[ 3 ] := 0
ServoCommand[ 4 ] := 0 'ramp-value
ServoCommand[ 5 ] := 55 'lowbyte of servo-position-value (250-1250)
ServoCommand[ 6 ] := 1 'highbyte of servo-position-value (250-1250)
ServoCommand[ 7 ] := 13
repeat
serial.str(@ServoCommand)
I have also tried this code but it is not running
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
serial : "FullDuplexSerial.spin"
pub main
repeat
serial.tx(33)
serial.tx(83)
serial.tx(67)
serial.tx(0)
serial.tx(0)
serial.tx(55)
serial.tx(1)
serial.tx(13)
Comments
Note that FullDuplexSerial isn't designed to accept a -1 pin number. It will treat the -1 as 31 (5 one bits). Try the Simple_Serial object instead if you're just transmitting.
Try your second example, but use Simple_Serial instead and include the initialization call (.start) for it.
yesterday i wrote another program
OBJ
PSC : "ServoControllerSerial"
CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
COMPIN = 16 'Pin used for communication with the PSC
PSC_BAUD = 1 'Baud rate (0 - 2400, 1 - 38400)
PUB MAIN
PSC.START(COMPIN, PSC_BAUD)
waitcnt(clkfreq + cnt)
PSC.SETPOS(0, 0, 500)
This program is also not responding
doubts:
1) what r the chances that sth is wrong with the TTL of the controller board because USB is working fine
2) The first pgm which i initially posted what should be the correction(u were saying that zero bytes r being transmitted)...
2) The fix for sending zero bytes is to use tx() on individual bytes as you did in the second case.