CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

how to calculate crystal for exact baudrate?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Kari
Guest







how to calculate crystal for exact baudrate?
PostPosted: Wed Dec 13, 2006 3:04 am     Reply with quote

I am using 4MHz crystal and 9600baud with software uart. Now I need to get exact 9600 baudrate. How to calculate suitable crystal? Chip is 18F252 or 16F876. Some standard crystal maybe?
Ttelmah
Guest







PostPosted: Wed Dec 13, 2006 3:35 am     Reply with quote

Your best bet, will be 3.9964MHz, which is fairly common, or 3.6864MHz. Take the baud rate you want (9600) multiply it by 16 (153600), and then divide the approximate frequency you want to use on the basis of the 'speed' you want your processor to be going at, by this. So:
4000000/153600 = 26.04
Now take the integer part only of this,and multiply the 153600 by this:
153600*26 = 3993600
This would be the closest frequency to 4MHz, which would give a perfect baud rate, but is an unusual crystal. However 3.9964, is only 0.07% in error from this, and is common.
You can test any frequency by performing the division, and if the result is an integer, then this is a 'good' crystal to use. So:
3.6864MHz, gives 24, and is 'perfect'.
However, your 4MHz crystal, should be perfectly acceptable, being only 0.16% off frequency, while around 4% is often considered to be an acceptable 'limit for this error. Few PC's, manage better than a couple of percent, and most USB to serial adapters are worse than this...

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group