Announcement

Collapse
No announcement yet.

Calculating Serial Out timing

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Calculating Serial Out timing

    How does one calculate the time it takes for a serial out command, with a 4 Mhz internal oscillator at 9600 baud with 8 bytes of data?

  • #2
    ((1/9600) * 10) * 8 ;8 Bytes take 10 bits when you consider Start & Stop bits. 1 Second divided by Baudrate (9600) gives you bits per second, which takes 0.000 104 167 seconds per bit. Times 10 = 0.001 041 667 seconds per byte. Times 8 bytes = 8.333 milliseconds. You might want to add ((Fosc/4) * 3) for reloading the TXREG; 0.000 003 seconds between bytes. Tally = 0.008 333 + (0.000 003 * 7) = 8.354 milliseconds total (or pretty close).

    To rehash:
    - 1 / Baud = bits per second, regardless of Fosc
    - 1 byte of data = 10 bits sent (Start bit + Byte + Stop bit)
    - It takes approximately 3 cycles to reload the TXREG; at 4 MHz Osc, Fosc/4 = 1 MHz; (1/1 MHz) * 3 = 0.000 003 seconds
    - There are only 7 reloads to send 8 bytes
    We can crack this cotton PIC'n thang!

    Comment


    • #3
      Thanks Mike. Excellent tutorial.

      Comment


      • #4
        Is there a list somewhere of other command times?

        Comment


        • #5
          Execution times vary too much to create a meaningful list. Variable type and variable placement in RAM are the big factors, but there are more. The math operators alone require over six thousand different macros, each with a different execution time. That doesn't take into account the varying time for bank-switching that's determined by variable placement.
          Charles Leo
          ME Labs, Inc.
          http://melabs.com

          Comment

          Working...
          X