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 CCS Technical Support

Packet over serial: Header and values collisions
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 20063

View user's profile Send private message

PostPosted: Fri Jan 23, 2015 2:16 am     Reply with quote

Agreed.

I'd say there are two approaches possible here. 9bit, or timing.

Key is that there needs to be 'something' that distinguishes the start of packet.

9bit (unfortunately), is quite hard at the PC end. Dead easy if you use something like a USB PIC, for the PC interface, but for 'off the shelf' some work is needed. I have a PIC that does this for an industrial RS485 network, and the data is returned to the PC as a complete packet, which has already been checksum tested (or rejected), with the source ID attached. Transmission is handled similarly, with the PIC adding the target ID, 9bit marker, and the checksum.
The FT232R, is used as the core of quite a few PC to 485 converters, that do support 9bits, but custom drivers are normally used. Several suppliers offer boards supporting 9bit.
Timing is relatively simpler, but (of course), costs time, and requires you to guarantee the 'relatively unbroken' nature of the packets in each direction. Interrupt driven RS232 transmit at the PIC end, with a buffer large enough that the code can always 'keep ahead' of the actual transmission, and adding timer code at the PC end to 'know' when a break is seen (the standard PC drivers 'timeout' ability may in some cases be used).

Using timing, with a packet checksum, is relatively simple to do at both ends, and allows recovery if the ends get out of sync, and rejection of damaged data.
ckielstra



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

View user's profile Send private message

Re: Packet over serial: Header and values collisions
PostPosted: Fri Jan 23, 2015 9:45 am     Reply with quote

ELCouz wrote:
I need to send very simple packets from PC to PIC very fast! (100 times per sec.)
100 times / second isn't very fast for a processor. It could however be too fast for RS232 communications...
What distance are you thinking of? Longer wires mean slower baudrates.

Quote:
The 16 values are 12-bit.
What baudrate are you considering?
Without any overhead we are talking:
16 values * 12 bits * 100 per second = 19200 baud

More realistically: 12 bits packed in 2 bytes, start bit and stop bit for every byte. And using the Modbus method of synchronizing by using an inter-message time of 3.5 bytes minimum.
(16 values * (16 bits value + start bit + stop bit) + 3.5 byte inter-message timing)) * 100 per second = 31,600 baud minimum

I agree that for synchronization the two most likely options are using a 9th bit to mark the start byte, or using an inter-message time-out. The 9-bit solution is easiest to program but depends on available hardware, many PICs have something called an 'addressable' UART which would be perfect as this generates an interrupt on detecting the 9th bit. Your PIC can even go into a low-power sleep and be awakened on receiving the header byte.
The time-out based mechanism is more universal as it uses common hardware but is tiny bit more difficult to program as you have trigger a hardware timer on every received byte.
Ttelmah



Joined: 11 Mar 2010
Posts: 20063

View user's profile Send private message

PostPosted: Fri Jan 23, 2015 9:53 am     Reply with quote

As an ongoing comment, consider encoding the 12bit value as two 6bit pieces, rather than an 8 and 4 bit piece.
Then you only use 64 possible values in a byte, so can use values >63 as the markers. No timing, no 9bit needed.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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