Shop OBEX P1 Docs P2 Docs Learn Events
Debug Servo controller code please... — Parallax Forums

Debug Servo controller code please...

RNRN Posts: 28
edited 2010-08-17 06:29 in Propeller 1
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)

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-16 08:03
    Your first example can't work because the string that you're trying to transmit has zero bytes in it and all of the string routines stop at the first zero byte. Your second example can't work because you don't initialize the FullDuplexSerial object. The sequence of bytes to transmit is correct, but nothing is transmitted.

    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.
  • RNRN Posts: 28
    edited 2010-08-17 05:55
    actually i started the fullduplexserial but still it is not responding

    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)...
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-17 06:29
    1) Could be. The Stingray has voltage translators by default on the I/O pins so its Propeller can talk to 5V devices and these can have problems with some 3.3V logic inputs. I think (but I'm not sure) that putting a resistor in series (like 2.2K to 10K) will help. Alternatively, you can disable the voltage translator on an 8 I/O pin block basis (see the Stingray controller manual).

    2) The fix for sending zero bytes is to use tx() on individual bytes as you did in the second case.
Sign In or Register to comment.