Sending commands to the Parallax Servo Controller (PSC)
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:
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
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 Williams
Applications Engineer, Parallax
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
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 Williams
Applications Engineer, Parallax
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 Williams
Applications Engineer, Parallax