View previous topic :: View next topic |
Author |
Message |
iso9001
Joined: 02 Dec 2003 Posts: 262
|
Need to switch from External Osc to Internal, problem |
Posted: Thu Jun 22, 2006 5:15 pm |
|
|
Hi,
Much as the subject says. I've searched this but only found a little info telling me to use the setup_oscillator() command and adjust the Use Delay if I do infact need delays.
I'm using a 18F4680 w/ 10Mhz xtal with PLL On (H4 fuse). Problem is I read to use:
Code: |
setup_oscillator(OSC_31KHZ);
//and then later
setup_oscillator(OSC_NORMAL);
|
I checked my device header and found this:
Code: |
#define OSC_31KHZ 0
//and
#define OSC_NORMAL 0
|
So either way I'd be setting setup_osc(0);
That can be right, can it ? |
|
|
heath.g
Joined: 20 Jun 2006 Posts: 6
|
|
Posted: Thu Jun 22, 2006 9:34 pm |
|
|
If you look at the constants in the header file you will notice that there is a line between the groups of parameters:
// The following may be OR'ed in with the above using |
They are all using different bits of the same byte.
If you look in the data sheet for the micro have a look at the OSCCON and OSCTUNE registers These will give you an idea of what the parameters for setup_oscillator are doing.
Basically you are passing an INT16 to setup_oscillator. LSB is OSCCON and MSB is OSCTUNE.
Hope this helps. |
|
|
iso9001
Joined: 02 Dec 2003 Posts: 262
|
|
Posted: Fri Jun 23, 2006 12:03 am |
|
|
I saw that, but 0 | 0 == 0
I'll need to take a better look at the datasheet.
But this is possible it seems.
Anyone know of the top of thier head how much power the internal RC at 32khz draws ? |
|
|
Ttelmah Guest
|
|
Posted: Fri Jun 23, 2006 4:52 am |
|
|
The three values for OSC_NORMAL, OSC_INTRC etc., select the oscillator 'source'. The values for OSC_31KHZ etc, then select the prescaler to use. _Normal_, implies the external oscillator. The values affect different nibbles of the data word, and it just happens that the combination of 'normal' (external oscillator), with the prescaler turned off, requires zero in both parts.
For the internal oscillator at 31KHz, you need:
OSC_INTRC | OSC_31KHZ
To run the external oscillator, with the PLL turned on, you require:
OSC_NORMAL | OSC_PLL_ON
The nibble for the prescaler has no effect when the external oscilator is selected, so 'oring' in the bits for this do not affect the final operation.
Best Wishes |
|
|
iso9001
Joined: 02 Dec 2003 Posts: 262
|
|
Posted: Fri Jun 23, 2006 8:19 pm |
|
|
Thanks,
That changed the clock but its no good to me now. I was hoping to use the slow clock for a low-power wake-on-can but it didn't work on anything other then what the BCON registers are set to. I even turned off WakeFilter so I guess it just can't be done.
By the way, I noticed about a 100uA rise in current when the clock was set to 31khz vs clock off. I'll have to remember that trick for other projects. |
|
|
|