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

How much time does writing to UART require?

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



Joined: 24 May 2007
Posts: 97

View user's profile Send private message

How much time does writing to UART require?
PostPosted: Wed Feb 09, 2011 1:20 pm     Reply with quote

Hello

My project requires me to send 8-10 strings to the UART port of my PIC16F886 every 20ms.

Measuring the values requires about 10-12ms. Betwen 2 sets of values there is a sync period of 10ms which I am hoping is enough time to send out the 10 strings to the UART.

Here is the string which I need to send out:
Code:

.....
int i;
int16 serval[10];
.....
Void sendtouart(){
       For (i=0; i<10; i++){
               printf("255,%u,%Lu\n\r",2,serval[i]);
       {
}


So I am wondering how to calculate how much time does it take to send this out and if it would fit in the 10ms which I have for this task.

Also I am wondering if the buffer of the UART on the PIC16F886 is enough to acomodate this set of data coming every 10 ms without overflow.

Thank you.
Ttelmah



Joined: 11 Mar 2010
Posts: 19372

View user's profile Send private message

PostPosted: Wed Feb 09, 2011 1:55 pm     Reply with quote

Depends on the baud rate.
The hardware buffer is just two characters.
For a larger buffer, use a software buffer (look at EX_SISR).

First two characters, basically instantaneous (into the hardware buffer), then the hardware waits to send the last character, before accepting the next.

If your UART is set to 9600bps, then each character (assuming 8 bits, no parity), takes: 1start bit, 8databits, 1stop bit =10/9600th second = 1.04166mSec.

Your string, is:
4 characters (255,)
2 characters (2,) - why not just include this in the fixed string?...).
1 to 5 characters (0 to 65535)
2 characters (LF, CR)

So 'worst case' 13 characters.
At 9600bps = 13.541666666mSec _per string_.
.1354 seconds for all ten strings

So. No (at 9600bps).
At anything over 130Kbaud, potentially yes (though getting hard - with transmission problems if the line length is significant....).


Best Wishes
SherpaDoug



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

View user's profile Send private message

PostPosted: Wed Feb 09, 2011 2:06 pm     Reply with quote

Count how many bytes are in your string, including the \n\r. Each byte is sent as 10 bits. Each bit takes 1/baud rate time to send. For example 18 bytes at 9600 baud is 180 bits/9600 = 18.75ms. Always leave a little extra time for overhead. Shorter messages or higher baud rates will send faster.

On the PICs I know the hardware UART buffer is 2 bytes. The built in CCS software UART has no buffer. Using interrupts it is possible to create a software buffer for the hardware UART, but the basic transmission time is a simple product of message length and baud rate.
_________________
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