PDA

View Full Version : 18.432 and 14.7456 oscillator.



Ziko87
- 14th July 2011, 09:48
Hi,

I must use one of this oscillaltor value, for interfacing with a mcp2120 device. Rading the manual I have see that the value accepted are 3 4 8 10 12 16 20 etc etc. What happen if I write DEFINE OSC 18.432?

Thank you. And sorry for my bad english.

ScaleRobotics
- 14th July 2011, 11:52
You need to use the values that are given in the manual for the DEFINE OSC, otherwise, you will just get errors trying to compile. What microcontroller are you going to use with the MCP2120? It sounds like you are trying to share the crystal? That won't work at these "weird" values. But with a separate crystal, you should be able to get to the baud rates you need. There are some newer chips that can run on internal OSC at fast baud rates.

mister_e
- 14th July 2011, 19:53
Yup, you just need to use the closer value, all timing will be slightly off, but in many situation it doesn't really matter. However SERIN, SERIN2, DEBUG and all bit-banged will not worrk as expected, nothing you can really do with odd OSC value, however with HSERIN/HSEROUT you can calculate the value of TXSTA/SPBRG (using PicMultiCalc) and specify them in the according DEFINEs, then your baudrate will be spot on.

Same goes for HPWM.

I2CREAD/SHIFTIN/I2CWRITE/SHIFTOUT are synchronous routines... no problem at all if the timings are a bit off.

hth

HenrikOlsson
- 14th July 2011, 22:14
Do you intend to use the same crystal for both the PIC and the MCP2120? If not I can't see why you can't use 14.7456 for the MCP2120 and whatever for the PIC. With a 20Mhz crystal on the PIC you'll be off less than 1% at 115200 baud.

Ziko87
- 15th July 2011, 07:14
I made a mistake in indicating the device. I was referring to mcp2122 that does not have a clock. Fortunately I have both chips, so I think using the mcp2120 solve my problems.

But the problem remains if I decided to use the mcp2122 which requires only an external clock with oscillator ottenible of 14.7456MHz.

From what I understand you can not change oscillator and hope that everything keeps working?

Charles Linquis
- 21st July 2011, 05:26
You can change the PICs oscillator to whatever you want. Microchip gives formulas for calculating baud rates given any oscillator frequency. PBP will work as well. The only problem is that any routine that uses software timing routines will be off. If you use DEFINE OSC 10, and you are actually running at 14.7456 Mhz, then PAUSE 100 will actually be a PAUSE 68 (it will pause for 68 mSec). Likewise, the SERIN/SEROUT routines will be off by the 10/14.7456 ratio. If you use SERIN2/SEROUT2, you can simply use the formulas given in the PBP manual to choose the correct value. If you use HSERIN/HSEROUT, you simply set BRG and the associated registers according to Microchip's formulas. You won't be able to DEFINE HSER BAUD !

Everything will work - if you take into account the new frequency.