Is it possible to change the clock source for a PIC.

Status
Not open for further replies.
Hello,

I wanted to know if it is possible to change between the internal rc oscillator and an external oscillator midway through a program. Currently, the program i've written runs off the internal 4 MH z oscillator, but i want to change to a high speed external oscillator so i can recieve GPS. Is this possible?

thanks.
 
That depends on the PIC. PIC24 devices, for example allows clock switching at runtime.
 
Ok, i'll try it with the 4MHz oscillator. I know the 4 Mhz can go as high as 9600, but 9600 is not a multiple of 4 Mhz so the will be some error whatever a value is loaded in to SPBRG.

thanks for your help,
ed.
 
Which PIC is it that you're running? If it's the 16F628, bit BRGH in the TXSTA register has to be set (in "High" mode) with an error code of 0x19 (or decimal 25) for 9600 baud on a 4MHz oscillator with only a 0.16% error (actually comes out to 9615). There's always going to be SOME error...you can never get them perfect, which is why they allow a certain amount of tolerance percentage.
 
With a UART the sample position is determined by the start bit for each byte. This makes it fairly tolerant of 'not quite right' baud rates.
 
I use the 16F886 and switch between internal and external. Set the config to external and then set bit 0 of OSCCON to switch to internal.

Mike.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…