Menu

Hardware Serial adds padding above 9600 Baud

Help
2014-06-12
2014-06-13
  • William Roth

    William Roth - 2014-06-12

    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)

    
    
    #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!

     
  • Anobium

    Anobium - 2014-06-12

    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.

     #define USART_DELAY 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
    • William Roth

      William Roth - 2014-06-12

      That solved it.

      Thanks

       
  • Anobium

    Anobium - 2014-06-12

    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.

     
  • joe rocci

    joe rocci - 2014-06-12

    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
  • Anobium

    Anobium - 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.

     
  • joe rocci

    joe rocci - 2014-06-12

    Why not just eliminate the default delay and give the user the option to use it if desired?

     
  • Anobium

    Anobium - 2014-06-12

    Sorry cannot. The would cause backward compatibility issues. I hope you understand the rationale.

     
  • William Roth

    William Roth - 2014-06-12

    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.

     
  • William Roth

    William Roth - 2014-06-13

    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.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.