CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PC to Controller Board communication

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
umka



Joined: 28 Aug 2007
Posts: 99
Location: New Zealand

View user's profile Send private message

PC to Controller Board communication
PostPosted: Thu Nov 27, 2008 11:13 pm     Reply with quote

I have done a search to see if I could find any relevant info but unfortunately found nothing on ccs.

I want to build an autonomous robot that uses two dc motors (CCP1 and CCP2) and has several inputs and outputs and communicates with a PC via a hard wire. The pc will have a program written in VB6 to control the robot.

Question 1: Would it make sense to use a device like a PIC18F4550 that has built in USB so I can emulate a serial connection to perform the pc to robot control communication or is there a better or simpler way to do this.

Question 2: I was thinking of sending strings like “Left,fwd,60”- for left motor forwards at 60%, “Output,12,1”- for output high pin 12 and “Input,3”- to check the input on pin 3. Is this a good way of doing it? Was thinking would read in the string then copy the characters up to the , into 3 different buffers and then compare them to set string to enter different control loops. Is there code that does this already that I didn’t find or a similar way that I could use?

Cheers for the help
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Nov 28, 2008 10:56 am     Reply with quote

Question 1: USB or RS232
There is no general answer for the on being better than the other, it depends a lot on how you are going to use the device.
USB is a bit more difficult to program but with the example programs provided by CCS this shouldn't be a problem. Most of the newer PC's don't have an RS232 connector, especially true for laptops. Another advantage of USB is that it can provide power to your electronics.
But... a disadvantage of USB is the limited cable length of maximum 5m. (link). Using the maximum of 5 USB hubs you could extend this up to 30m but this is not very practical.

RS232 is easy to program and can be used over a distance up to 15m at a data rate of 256kbs. With good quality cables and lower data rates the maximum distance can be increased.

Question 2: Commands as strings?
Sending the commands as human readable strings has the advantage that on the transmitting PC you can use a standard terminal program like Hyperterm to enter the commands. Also easy for debugging. A disadvantage is that on the receiving PIC you will have to parse the commands into something understandable by the processor. This includes all kind of user input errors (small or capital letters, extra spaces, empty lines, too large values, etc.).
The alternative is to send the commands as binary codes, for example: 1 2 60
Where 1 is the left motor, 2 means forward and 60 is the speed.
Not easy to read for humans but a lot easier for the PIC, you can even add a checksum to detect communication errors. On the PC side this requires a dedicated program with a nice user interface for translating the user commands to the binary format.

For the string command parser several example programs have been posted in this forum, here are just a few examples:
Ttelmah: http://www.ccsinfo.com/forum/viewtopic.php?t=28159
Mark (C18 compiler): http://www.ccsinfo.com/forum/viewtopic.php?t=28159
CCS: the ex_fat.c example program
umka



Joined: 28 Aug 2007
Posts: 99
Location: New Zealand

View user's profile Send private message

PostPosted: Sat Nov 29, 2008 4:47 pm     Reply with quote

Cheers for the advice ckielstra. Have got it working and working well at that I think.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group