View previous topic :: View next topic |
Author |
Message |
cfernandez
Joined: 18 Oct 2003 Posts: 145
|
Time Delay between Byte in Serial Comunication |
Posted: Sun Feb 05, 2006 11:45 am |
|
|
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!!!!!!! |
|
![](templates/subSilver/images/spacer.gif) |
cfernandez
Joined: 18 Oct 2003 Posts: 145
|
|
Posted: Sun Feb 05, 2006 11:46 am |
|
|
I NOT WANT USE INTERRUPT ROUTINE !!!!!!
THANK YOU |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Feb 05, 2006 12:48 pm |
|
|
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, |
|
![](templates/subSilver/images/spacer.gif) |
cfernandez
Joined: 18 Oct 2003 Posts: 145
|
|
Posted: Sun Feb 05, 2006 2:38 pm |
|
|
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!! |
|
![](templates/subSilver/images/spacer.gif) |
cfernandez
Joined: 18 Oct 2003 Posts: 145
|
|
Posted: Sun Feb 05, 2006 2:58 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Feb 05, 2006 3:01 pm |
|
|
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 |
|
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
Bit Timing |
Posted: Sun Feb 05, 2006 3:10 pm |
|
|
Apparently doesn't want it...
Last edited by dyeatman on Sun Feb 05, 2006 3:45 pm; edited 1 time in total |
|
![](templates/subSilver/images/spacer.gif) |
cfernandez
Joined: 18 Oct 2003 Posts: 145
|
|
Posted: Sun Feb 05, 2006 3:40 pm |
|
|
ckielstra,
Can you tell me the values for your variable?, This is your inter-character delay formula?
Thank you very much! |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Feb 05, 2006 4:37 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
cfernandez
Joined: 18 Oct 2003 Posts: 145
|
|
Posted: Sun Feb 05, 2006 4:45 pm |
|
|
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) |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Feb 05, 2006 5:02 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Sun Feb 05, 2006 5:16 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Eugeneo
Joined: 30 Aug 2005 Posts: 155 Location: Calgary, AB
|
|
Posted: Sun Feb 05, 2006 6:18 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Sun Feb 05, 2006 7:29 pm |
|
|
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](images/smiles/icon_exclaim.gif) _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
![](templates/subSilver/images/spacer.gif) |
|