View Full Version : [SOLVED !] Cpu_mhz ??

23rd June 2003, 13:34


Does this mean that the compiler will take all of its timings from 19X Mhz crystal freq and not the XTAL=20.

If yes can I get away with setting :-

Symbol CPU_MHZ = 18432000

As I am using external uarts on the PIC 16f877 device that use an 18.432 Mhz crystal so I want a single clock, run both at the 18.432, and still let the PIC send out at 38400 baud.

I hope this makes sense !!!!


23rd June 2003, 17:47

You can use Symbol CPU_MHZ = 18432000 but its what you expect to do with the value that counts.

There are set freqs that P+ will work with they are:-

4, 8, 10, 12, 16, 20, 24 and 40. There may be more but i am unaware of them.

This does not mean you cannot use other Freqencys XTALs on your pic. It just will be that P+ will not calculate delays etc correctly

Does that help?


24th June 2003, 09:08
As Tim has mentioned, the compiler only works with a range of fixed crystal frequencies. This allows the library routines to time accurately.

However, there is no reason that you cannot use another frequency crystal for the PICmicro, it simply means that timings will be out by whatever difference there is between XTAL value and the actual frequency crystal used.

For example, setup the compiler to use a 20MHz crystal

XTAL = 20

but actually use a 18.432MHz crystal.

Timings will be out by the difference, which is 1568000Hz or 1.568MHz.

As long as you take the difference into consideration, no problems should arise.

Of course, the USART's baud rate will be calculated according to the XTAL declared, which is 20MHz. This is taken care of by the compiler.

But adding a single line of code can change the baud rate for any crystal frequency.

'SPBRG = (((18432000 / 38400) + 32) / 64) - 1 ' Uncomment For BRGH = 0

'SPBRG = (((18432000 / 38400) + 8) / 16) - 1 ' Uncomment For BRGH = 1

SPBRG is the baud rate generator for the USART, and BRGH is also a part of it.

Jeremy's code also uses TMR1, so you will need to take the frequency of the crystal into consideration, when calculating its timing (if you're using Jeremy's code, that is).

I have ran the PROTON net board using a 20Mhz crystal with no problems.

Hope this helps