PIC 18F4520 clock frequency calculations

Thread Starter

ddonn

Joined Feb 10, 2010
13
Hi,
I am trying to calculate the number of clock cycles at a clock frequency of 8MHz that corresponds to 2 bits at 9600 baud.
Any suggestions?

Also, what is the scaler value for 9600 baud @ 8 MHz and is there a relationship between the two?

Thanks in advance.
 

t06afre

Joined May 11, 2009
5,934
Hi,
I am trying to calculate the number of clock cycles at a clock frequency of 8MHz that corresponds to 2 bits at 9600 baud.
Any suggestions?
Also, what is the scaler value for 9600 baud @ 8 MHz and is there a relationship between the two?
Thanks in advance.
I am not sure what you are talking about here. Do you want to setup your uart to fit 9600 baud using a 8MHz clock speed? Also which compiler do you use?
 

AlexR

Joined Jan 16, 2008
732
PIC controllers use 4 clock cycles per instruction cycle so at 8MHz 1 instruction cycle takes 500nSec. Data at 9600 baud takes 104.17uSec per bit (1/9600, that's what baud rate means) so 2 bits will take 208.33uSec.

A 8MHz clock will never give you exactly 9600baud, the closest it gets is 9615 baud. That is an error if 0.16% which is close enough for most applications.

If you simply must have exactly 9600 baud then you you will need to change your crystal to either 4.9152Mhz or 9.8304MHz, there are other frequencies you can use but those 2 will divide down to provide all the common communication baud rates.
 
Top