![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
oxxyfx
Joined: 24 May 2007 Posts: 97
|
How much time does writing to UART require? |
Posted: Wed Feb 09, 2011 1:20 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19372
|
|
Posted: Wed Feb 09, 2011 1:55 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Feb 09, 2011 2:06 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|