PDA

View Full Version : Changing OSC type & speed during program execution (for power control)



flotulopex
- 16th May 2008, 11:31
Hello,

Is it possible to change the OSC speed and type (from Xtal to Internal Oscillator) during the program's execution within the program (=originated by the program, not by an external switch)?

In other words, can I start my application using a 20MHz Xtal and then, after some operation needing this "high" speed, I can switch over to the internal 4MHz oscillator?

Charles Linquis
- 16th May 2008, 13:27
Yes, you can change oscillator types and speeds at runtime.

Jerson
- 16th May 2008, 13:34
If you're using a device like the 16F917, I think you can change the speed on the fly by writing to the OSCCON register. However, there is a catch. How will you inform PBP about the speed change? The define OSC 8 will set the speeds for most of their functions like pause and I2C timings. I dont know if they read the OSCCON to decide or just use the define. So, I guess you'll have to tread with caution

tenaja
- 16th May 2008, 13:55
Hello,

Is it possible to change the OSC speed and type (from Xtal to Internal Oscillator) during the program's execution within the program (=originated by the program, not by an external switch)?

In other words, can I start my application using a 20MHz Xtal and then, after some operation needing this "high" speed, I can switch over to the internal 4MHz oscillator?
As the others have said, you can, depending on the pic. To change the internal clock speed (typically they range from 31kHz to 8MHz) with most pic's it is the osccon register. You'll have to read the datasheet on your specific pic to know what it can do, and how to do it. They usually have a section on the Oscillator.

flotulopex
- 16th May 2008, 14:35
Thanks to All.

I'm going to do some testing...