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

Time Delay between Byte in Serial Comunication

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



Joined: 18 Oct 2003
Posts: 145

View user's profile Send private message

Time Delay between Byte in Serial Comunication
PostPosted: Sun Feb 05, 2006 11:45 am     Reply with quote

Hi,

Which is the best method for calculate the time delay between bytes in a serial comunication?

I use this routine:

Code:


int MSG_RecvFrame( char *sData )
{
   int      iLen = 0;
   int      iTimeOut;
   int16          lTimeOut = MSG_RESPONSE_TIMEOUT;

   while ( !kbhit( MSG_SERIAL_PORT ) && --lTimeOut );

   while ( kbhit( MSG_SERIAL_PORT ) && iLen < MSG_BUFFER_SIZE )
   {
      sData[ iLen++ ] = fgetc( MSG_SERIAL_PORT );

                //
                // IS NECESARY THIS DELAY FOR NOT LOST BYTES!!!!!!
                //
      iTimeOut = MSG_TRANSMIT_TIMEOUT;
      while ( !kbhit( MSG_SERIAL_PORT ) && --iTimeOut );
   }





But the problem is that ITimeOut change for different Baud Rate. Somebody know the best way for calculate the right value for iTimeOut for differente baud rate?

Thank you very much!!!!!!!
cfernandez



Joined: 18 Oct 2003
Posts: 145

View user's profile Send private message

PostPosted: Sun Feb 05, 2006 11:46 am     Reply with quote

I NOT WANT USE INTERRUPT ROUTINE !!!!!!


THANK YOU
ckielstra



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

View user's profile Send private message

PostPosted: Sun Feb 05, 2006 12:48 pm     Reply with quote

Your curent protocol is depending on time outs between the messages? That would be is a poor designed protocol and is a garuantee for troubles to come.

You would make life a lot easier on yourself if you can change the message protocol so each message will start with a known header and end-of-message marker.


The inter-character time out changes lineair with the selected baudrate. Just pass the selected baudrate to your MSG_RecvFrame function as a correction factor,
cfernandez



Joined: 18 Oct 2003
Posts: 145

View user's profile Send private message

PostPosted: Sun Feb 05, 2006 2:38 pm     Reply with quote

ckielstra

The protocol is ok and the function work ok. My question is how to calculate the correct inter-character time out for diferents baud rate and PIC clock?

You know this?

Thank you!!
cfernandez



Joined: 18 Oct 2003
Posts: 145

View user's profile Send private message

PostPosted: Sun Feb 05, 2006 2:58 pm     Reply with quote

Dear ckielstra,

How to get a serial string without INT and if this string not have a protocol?. How to know when not exist more bytes?.

Can you send me a example?

Thanks
ckielstra



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

View user's profile Send private message

PostPosted: Sun Feb 05, 2006 3:01 pm     Reply with quote

Quote:
The protocol is ok
In my current product I have to work with a similar protocol and have a lot of problems when synchronisation is lost. If you think it's OK, that's it up to you.

Quote:
My question is how to calculate the correct inter-character time out for diferents baud rate and PIC clock?
I already told you in a cryptic form.
Unless you are using autobaud features of the UART there is one point in your software where you are setting the baudrate. Manually calculate the desired time-out value at 115kbaud once. Then in your program do something like:
Code:
  TimeOutCurrentBaudRate = (115kbaud / current baudrate) * timeout-value-at-115k
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

Bit Timing
PostPosted: Sun Feb 05, 2006 3:10 pm     Reply with quote

Apparently doesn't want it...

Last edited by dyeatman on Sun Feb 05, 2006 3:45 pm; edited 1 time in total
cfernandez



Joined: 18 Oct 2003
Posts: 145

View user's profile Send private message

PostPosted: Sun Feb 05, 2006 3:40 pm     Reply with quote

ckielstra,

Can you tell me the values for your variable?, This is your inter-character delay formula?

Thank you very much!
ckielstra



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

View user's profile Send private message

PostPosted: Sun Feb 05, 2006 4:37 pm     Reply with quote

Quote:
Can you tell me the values for your variable?, This is your inter-character delay formula?
The exact value for the time-out to detect an end of message is very dependent on your application. It depends on how sure you want to be, how often the other side is sending messages and if the data output of the other side is always continous or may be interrupted. A correct timeout value is not easy to determine, a bit like magic. That's why I'm not happy with your approach, though sometimes you have to live with bad protocols.

Quote:
How to get a serial string without INT and if this string not have a protocol?. How to know when not exist more bytes?.
Without you giving us more information about the contents of the string it is hard to give detailed help. Very often the strings in these kind of protocols end with a Carriage Return (CR) character.
cfernandez



Joined: 18 Oct 2003
Posts: 145

View user's profile Send private message

PostPosted: Sun Feb 05, 2006 4:45 pm     Reply with quote

ckielstra,

I think that you not understandme, I not know when finish my message, I need to know who calculate the exactly inter-character time for a specific baud rate and clock PIC.

If in my example remark the delay inter-character the PIC is very fast that the comunication and I not received all characters from message, for this I put this delay, but this delay generate a time delay for the last byte, for example if my delay is 100ms when I received all message my function have a delay of 100ms before return and I want that this delay shorty possible. This is my question and this time delay is for each baud rate (2400 to 115kb)
ckielstra



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

View user's profile Send private message

PostPosted: Sun Feb 05, 2006 5:02 pm     Reply with quote

You are right when you say I don't completely understand your problem, but you don't give me a lot of information. What does the data look like that you are receiving?

Still, as I see it, your protocol sucks. If there is no character at the end of the string to indicate to you that the end is reached, then you' ll have to live with a long delay at the end of your receive function. The only thing you can do then is to adjust this delay depending on the baudrate.
dyeatman



Joined: 06 Sep 2003
Posts: 1933
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Feb 05, 2006 5:16 pm     Reply with quote

I pointed him to a document that gave him exactly the information he is asking for and he ignored it so I figured the only information he was interested in was from you
Eugeneo



Joined: 30 Aug 2005
Posts: 155
Location: Calgary, AB

View user's profile Send private message

PostPosted: Sun Feb 05, 2006 6:18 pm     Reply with quote

Would this work

1 Setup a timer
2 Set your start com setting
3 Wait and look for a start bit
4 Using the timer, see if the stop bit repeatedly falls on the testing com settings. If not change com settings and goto step 3
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sun Feb 05, 2006 7:29 pm     Reply with quote

I would like to point out that if your serial data is coming from a complex function like PRINTF() printing a float there can be a lot of variation in the time between bytes. It may take a while to convert the float to ASCII chars, and the time may depend on the value of the float.

This is not a good idea Exclamation
_________________
The search for better is endless. Instead simply find very good and get the job done.
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