# Serial Communication and Local Clock error calculation

For a 24MHz system, the local clock error associated with transmitting 10-bit character frames at 38.4 Kbaud using the SCI of a Freescale Micro is 0.16%.

How? I can't figure out the math that actually makes sense to get that number. Any ideas? I'm sure it's easy.

• @Keegan - you will have to let us know which Freescale part you are using to give you an accurate answer. Commented Nov 30, 2010 at 17:14

Typically an asynchronous communication pin is sampled at 16 times the bit rate. This implies a baudrate generator of:

$\frac{24000000}{16}\frac{1}{38400} = 39.0625$

Since the resulting integer value is 39, the resulting error is:

$\frac{0.0625}{39.0625} = 0.0016$

or 0.16%

Here's a tool (for AVR) that demonstrates the calculations. It's all about integer divison of the baud rate and system clock.

http://www.wormfood.net/avrbaudcalc.php

I don't have the Freescale datasheet.

But 24MHz / 38400 baud is exactly 625 cycles per symbol.

I will guess that there is an unavoidable divide in the clock or baudrate generator, so the desired ratio is half of 625 or 312.5. The closest an integer counter can come is 312.

312 is 0.16% lower than 312.5

• i also do not have the datasheet. i would bet markrages is spot on. Commented Nov 30, 2010 at 16:56
• @markrages - Could you please explain why the desired ratio is half? Commented Nov 30, 2010 at 17:17
• I'd guess that the divide by two is because the hardware is oversampling the RS232 bits Commented Nov 30, 2010 at 17:23
• @Joby, I don't believe this is correct. For an asynchronous port such as RS232, the hardware typically oversamples by a factor of 16x, not 2x. Commented Nov 30, 2010 at 17:27
• @semaj 2^4=16 so assuming you don't divide to be less then 1 the percent error will work out the same. Commented Nov 30, 2010 at 17:33