Shop OBEX P1 Docs P2 Docs Learn Events
Sending commands to the Parallax Servo Controller (PSC) — Parallax Forums

Sending commands to the Parallax Servo Controller (PSC)

PengatomPengatom Posts: 21
edited 2006-01-25 16:24 in General Discussion
Hello [noparse]:)[/noparse]

I've started a project with a µC that should controll a PSC. The µC is programmed in C/C++ and the commandoes are sendt on a serial tx line with the "sendByte" commando.

This is a sample of the code:

[b][color=#7f0055]void[/b][/color][color=#000000] update(unsigned-char channel, unsigned-char ramp, unsigned-short pulseWidth){[/color]
[color=#3f7d5f]//Code to send new position for servo to PSC
[/color][b][color=#7f0055]  if[/b][/color](ready_to_send_new_message){ [color=#3f7d5f]//timer_int_handler() in interrupt_handling.c[/color]
    ready_to_send_new_message = 0; [color=#3f7d5f]//1 msg every sec[/color]
 
    msgbuffer[noparse][[/noparse]0] = [color=#2a00ff]'!'[/color];           [color=#3f7d5f]//Servo[/color]
    msgbuffer[noparse][[/noparse]1] = [color=#2a00ff]'S'[/color];           [color=#3f7d5f]//controller[/color]
    msgbuffer[noparse][[/noparse]2] = [color=#2a00ff]'C'[/color];           [color=#3f7d5f]//identifier[/color]
    msgbuffer[noparse][[/noparse]3] = channel;       [color=#3f7d5f]//Channel that the Servo is on (0-15)[/color]
    msgbuffer[noparse][[/noparse]4] = ramp;          [color=#3f7d5f]//Ramp Value (speed at which servo will attempt to reach new position)[/color]
    msgbuffer[noparse][[/noparse]5] = pulseWidth;    [color=#3f7d5f]//Value you want the servo to move to (250-1250,750=center)[/color]
    msgbuffer[noparse][[/noparse]6] = pulseWidth>>8; [color=#3f7d5f]//Shifts all bites one byte to the right[/color]
    msgbuffer[noparse][[/noparse]7] = 0x0D;          [color=#3f7d5f]//End command[/color]
    next_char = 0;
  }
 
[b][color=#7f0055]  if[/b][/color](next_char < 8){             [color=#3f7d5f]// Is the message sendt?[/color]
[color=#7f0055]    [b]if[/b][/color](new_char_can_be_sendt){   [color=#3f7d5f]// Is the serialport ready for a new char?[/color]
      new_char_can_be_sendt = 0; [color=#3f7d5f]// Sends msgbuffer[noparse][[/noparse]next_char] out to the PSC[/color]
      XUartLite_SendByte(XPAR_PSC_BASEADDR,msgbuffer[noparse][[/noparse]next_char]);
      next_char++;
    }
  }
}



So, my question is simple really, will the psc understand this? I'ts especially the "!SC" part that concernes me... Everywhere else its sent as a string...

regards
Pengatom


▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
1 + 1 = 10· |· 4 + 4 = 10· |· 5 + 5 = 10· |· 8 + 8 = 10

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-18 18:57
    Strings are sent serially one byte at a time, so the "!SC" section of your code should present no problem (if you connections and baud settings are correct).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • PengatomPengatom Posts: 21
    edited 2006-01-18 23:43
    Thanx so much [noparse]:)[/noparse]

    No I'll just wait for the PSC to arrive in the mail so I can test it [noparse]:)[/noparse]

    regards
    Pengatom

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 + 1 = 10· |· 4 + 4 = 10· |· 5 + 5 = 10· |· 8 + 8 = 10
  • PengatomPengatom Posts: 21
    edited 2006-01-25 12:53
    For testing I've setup the syntax right, I'm now sending one byte pr second to a LCD. I'm getting everything right, except for the pulswidth hi and lo byte... There I'm getting som wierd (expletive).

    pw.lobyte: q524
    pw.hibyte:   01
    

    Guess it something to do with ascii/not ascii format... I'll dig into this later today.

    As I said, I'm sending one byte every second, but I don't know how fast I can send this to the PSC so it will understand it?


    Regards

    Pengatom

    Edit: redused the pulswidth variable from 500 to 5, and now I'm getting the result that want. Seems like·the variable I'm using is probably not "big enough"...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 + 1 = 10· |· 4 + 4 = 10· |· 5 + 5 = 10· |· 8 + 8 = 10

    Post Edited (Pengatom) : 1/25/2006 1:45:00 PM GMT
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-25 15:26
    You're not showing your code, so I'll just remind you that LCDs expect strings of ASCII characters. I'm not much of a C programmer, so I don't know the name of the function that converts a number to its string equivalent, but that's what you want to use (in PBASIC we have a formatter called DEC that does it for us).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • PengatomPengatom Posts: 21
    edited 2006-01-25 15:47
    The LCD is okey, for now [noparse];)[/noparse]
    My problem, or rather question, is about the psc.
    What is the minimum time between each byte sendt to the psc?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    1 + 1 = 10· |· 4 + 4 = 10· |· 5 + 5 = 10· |· 8 + 8 = 10
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-25 16:24
    It's fastest baud rate is 38.4K (8N1) -- a stop bit at that rate is 26 microseconds. The PSC has a hardware UART so you're not going to overrun it if you have your baud parameters set correctly (True mode, which means a start and "1" bit are at 0v, the line idle state and "0" bits are at 5v).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.