2009/02/19 14:45:44
Robotics Guy
Is there a way to find how many bytes per second are being sent or received for a certain baud rate?

For example, if the baud rate is 9600, how many bytes could be sent per second?

With a PIC, if I try to write more bytes in one second then the baud rate can handle, what would happen? Would it be a TX buffer overflow?

Thanks for the help!
2009/02/19 15:04:19
Sending eight bits of data per character with the required start and stop bits will take up 10 times the bit time for ach byte sent. At 9600 baud, the bit time is about 104 microseconds which makes each character sent take 1.04 milliseconds. This corresponds to a transfer rate of about 960 bytes per second.
Before sending a byte, you should check that the UART transmitter is ready to accept the byte. This will be indicated by the TXIF bit (sorry, I forget which register that's in) being set. If the TXIF bit is clear, wait for it to go high before writing the next byte to the TXREG register. If you don't, the character will be dropped from the transmission.
2009/02/19 21:59:27
One more point...Smile

PIC18 supports back to back transmission, that means you can load TXREG twice before TXIF gets cleared. In PIC24 there is a 4 deep FIFO in the TXREG, that means you can load TXREG 5 times before getting the TXIF cleared.

2009/02/20 12:22:10
Robotics Guy
So how do you know what the bit time is? Does it vary from device to device?

Thanks for explaining!
2009/02/20 12:52:49
bit_time = 1 / baud_rate

At 9600, bit time is 104.166666666666 microseconds.
At 19200, bit time is 52.083333333333 microseconds.

If you want to calculate word timing, then you first need to know baud rate, data bits, parity and stop bits.

For example 9600 8 N 1 uses 10 bits per word (1 start bit, 8 data bits, and 1 stop bit). Each word would take 10/9600 = 1041.66666666 microsecs.

19200 7 E 2 uses 11 bits per word ( 1 start bit, 7 data bits, 1 parity bit and 2 stop bits). Each word would take 11/19200 = 572.91666666666 microsecs.

Hope that helps.

© 2019 APG vNext Commercial Version 4.5

Use My Existing Forum Account