PDA

View Full Version : SEROUT on 16F876A @ 3.2768 MHz 4MHz Defined



brodin
- 14th November 2003, 21:41
I am thinking about changing the crystal i am using(4MHz) to a 3.2768MHz to get a timer work good. What will happen with my serial communication with pc (baud=2400) and my 4-bit LCD? Will they work. It doesn't seems like it is possible to define a 3.2768 MHz crystal in PBP, right?

Melanie
- 16th November 2003, 02:25
Firstly the problem is you can't tell PBP about your 3.27MHz xtal. The closest define is OSC 3 (3.58MHz) which still gives you an error of 310kHz - or almost 10%.

All commands with timing considerations will be shot. Your 4-bit LCD will probably work just fine but all your async comms will require recalculation for the baud rates in order to fool PBP into giving you the correct equivallent rate.

If you tell PBP that you have a 4MHz xtal (the default) you should be able to use the formula in the manual to configure SERIN/SEROUT etc for say 2930 baud, which, if my maths is correct, would give you 2400 baud actual.

How did I work that out?... 4MHz/3.2768MHz gives 1.220703125, which if you multiply by 2400 baud gives 2929.6875 or 2930 rounding to the nearest integer.

Just remember everything will be out by a factor of 1.2207 and account for it by either dividing or multiplying accordingly, eg Pause 819 to pause for approx 1 second, instead of Pause 1000.

Melanie