Why does hardware serial add padding between bytes at baud rates above 9600 ?
At 9600 baud all is well. When the baud rate is set to 19200 an extra 300us is added between data bytes. When set to 38400 an extra 700us is added between bytes. The bit rate remains accurate in all case.
This behavior means that it takes approximately the same about of time to send 8 bytes of data regardless of whether the baud rate is 9600, 19200, or 38400.
Is this a compiler problem or am I doing something wrong?
Here is my test code using a PIC16F1829. (I have the same issue with PIC16F886)
#chip 16F1829, 16
#config FOSC_INTOSC, CLKOUTEN_OFF, WDTE_OFF
#config LVP_OFF, PLLEN_ON
#define USART_BAUD_RATE 38400
#define USART_BLOCKING true
#define SerInPort PORTB.5
#define SerOutPort PORTB.7
'Pin directions
Dir SerOutPort Out
Dir SerInPort In
do
hserPRINT "UUUUUUUU" ' Send 8 bytes for Logic Analyzer
wait 10 ms
loop
Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
My tests using a logic analyzer show that the delay varies depending upon baud rate. The higher the baud rate, the longer the delay. At 9600 baud there is no 1ms delay. The added delay only comes in to play somewhere between 9600 and 19200 baud rate. I looked at the USART.H file and could not see any obvious reason that the delay time should vary.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
It may be noteworthy that with the default setting of 1ms and a baud rate setting of 9600 that there is no added delay. In order to get a 1 ms delay with a baud rate of 9600, the delay value must be increased to 2 ms.
With the default delay of 1ms, the delay does not actually begin to show up until the baud rate reaches about 10500.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
Why does hardware serial add padding between bytes at baud rates above 9600 ?
At 9600 baud all is well. When the baud rate is set to 19200 an extra 300us is added between data bytes. When set to 38400 an extra 700us is added between bytes. The bit rate remains accurate in all case.
This behavior means that it takes approximately the same about of time to send 8 bytes of data regardless of whether the baud rate is 9600, 19200, or 38400.
Is this a compiler problem or am I doing something wrong?
Here is my test code using a PIC16F1829. (I have the same issue with PIC16F886)
Thanks!
Welcome to the forum.
To slow down serial print we have a default delay: USART_DELAY
Setting to 0 ms will remove all delays, the example below sets to 1 ms.
You can changed this delay to improve performance. Please change in you main program as it is not recommended to change the default file set.
Hope this helps.
Last edit: Anobium 2014-06-12
That solved it.
Thanks
May I ask.
Did you complete a search of the Help File for a solution?
I will update the Help File to better reflect this aspect of the configuration.
Anobium
It sounds from OP's description that the default delay varies. Can you dimension what the default is and if/how/when it varies?
Joe
Last edit: joe rocci 2014-06-12
I will review the code and update the Help File. From my initial review it is a 1 ms delay.
I will update at the next release.
Why not just eliminate the default delay and give the user the option to use it if desired?
Sorry cannot. The would cause backward compatibility issues. I hope you understand the rationale.
My tests using a logic analyzer show that the delay varies depending upon baud rate. The higher the baud rate, the longer the delay. At 9600 baud there is no 1ms delay. The added delay only comes in to play somewhere between 9600 and 19200 baud rate. I looked at the USART.H file and could not see any obvious reason that the delay time should vary.
It may be noteworthy that with the default setting of 1ms and a baud rate setting of 9600 that there is no added delay. In order to get a 1 ms delay with a baud rate of 9600, the delay value must be increased to 2 ms.
With the default delay of 1ms, the delay does not actually begin to show up until the baud rate reaches about 10500.