clock frequency

Thread Starter

Jeeny

Joined Apr 9, 2012
5
i mean how clock freq relate with baud rate calculation? for example the formula of x (SPBRG)=(156250/DESIRED BAUD RATE)-1
 

t06afre

Joined May 11, 2009
5,934
I guess we are talking about asynchronous transmission here. The baud rate generator use the system clock. The system clock is divided down to create the correct baud, and also correct reading of incoming data.
 

MrChips

Joined Oct 2, 2009
30,707
In many cases, the clock frequency of the UART circuitry is 16 times the baud rate.
For example, 9600 baud requires a clock frequency of 153,600 Hz.
If your MCU system clock is 4MHz, the closest you can get to the required clock is to divide 4MHz by 26.
 

t06afre

Joined May 11, 2009
5,934
In many cases, the clock frequency of the UART circuitry is 16 times the baud rate.
For example, 9600 baud requires a clock frequency of 153,600 Hz.
If your MCU system clock is 4MHz, the closest you can get to the required clock is to divide 4MHz by 26.
I think I recognize this formula from PIC MCUs. And for a PIC the correct number will actually be 25 to be loaded into the SPBRG. All this is explained in the datasheet UART section
 

@android

Joined Dec 15, 2011
178
what is the significant of clock frequency in baud rate calculation?? thx
Clock rate is like heart bit! Its nothing but a reference for baud rate generator in the circuit. Simply for any digital circuit you need the CLOCK! That is the root of digitization.
Hope that helped
 

panic mode

Joined Oct 10, 2011
2,715
you need clock to generate timing for everything, including the baud rate.

if your baud rate is 9600 bps (bit per second or Hz) and your clock is 9600 Hz, there is no problem creating proper timing because both things match (even if you won't be able to do anything else).

but you don't want your micro to run this slow and only do uart. you want it to run as fast as possible and do several things at the "same" time.

then your clock need to be higher and some multiple of the selected bitrate. if the clock is sufficiently high, getting suitable divider is less of a problem (but still need to be an integer).

for example, suppose you pick crystal of 32768kHz (commonly found in watches).

32768/9600= 3.41333

bad choice, 3.41333 is not an integer. to get correct timing for 9600Hz you need to divide original clock by that weird number and that is hard. when company is designing chip, they try to make things simple so the real estate of the silicon is optimally used and cost of the finished product is low. dividing frequency in digital world is simple using counters. but counters count (and divide by) integers.

exact division factor depends on structure of circuitry inside the micro controller but the goal is the same - get divisor that will produce correct timing for your baud rate.
to help you with that, manufacturers publish formula in their datasheet. you just have to use it.

as an exercise, get few TTL chips and try to make counters with base 4, 8, 16, 10 and 4.75. guess which one will be the hardest to do.
 

MrChips

Joined Oct 2, 2009
30,707
Couple of corrections:

1) Watch and RTC crystals are 32768Hz, not 32768kHz.

2) As I mentioned in post #5, the UART clock is 16 times the baud rate. Hence for 9600 baud, the UART clock is 153600Hz or 153.6kHz. Why is this?
The transmitter hardware can work with a clock of 9.6kHz but the receiver cannot.
The receiver needs to detect the leading edge of the UART NRZI data and then clock the data bits in the middle of the data window. The hardware does this by sampling on the 8th clock pulse and at every 16th clock pulse following.

Many MCU UARTs are driven from the MCU clock which tend to be 4MHz or multiples.
Hence using an integer divisor of 26, we get a baud rate of 9615 which is off from 9600 by 0.15% and that is well within the signal transmission specs.
 
Top