There are two issues with the code snippet you have posted:
Code:
OSCCON = 0xF2; // INTOSC 32MHZ
[COLOR="#FF0000"]OSCTUNE = 0X1F; // MAX FREQUNCY[/COLOR]
Firstly, in this case this is no need to alter the value contained in the OSCTUNE register, it is akin to the vernier adjustment on a scope, intended to fine tune the oscillator frequency out of calibration, leave it set to the startup value of 0x00.
Reference: **broken link removed**, Section: 5.2.2.3 Internal Oscillator Frequency Adjustment, Page:57
5.2.2.3 Internal Oscillator Frequency Adjustment
The 500 kHz internal oscillator is factory calibrated.
This internal oscillator can be adjusted in software by
writing to the OSCTUNE register (Register 5-3). Since
the HFINTOSC and MFINTOSC clock sources are
derived from the 500 kHz internal oscillator a change in
the OSCTUNE register value will apply to both.
The default value of the OSCTUNE register is ‘0’. The
value is a 6-bit two’s complement number. A value of
1Fh will provide an adjustment to the maximum
frequency. A value of 20h will provide an adjustment to
the minimum frequency.
When the OSCTUNE register is modified, the oscillator
frequency will begin shifting to the new frequency. Code
execution continues during this shift. There is no
indication that the shift has occurred.
OSCTUNE does not affect the LFINTOSC frequency.
Operation of features that depend on the LFINTOSC
clock source frequency, such as the Power-up Timer
(PWRT), Watchdog Timer (WDT), Fail-Safe Clock
Monitor (FSCM) and peripherals, are not affected by the
change in frequency.
Code:
[COLOR="#FF0000"]OSCCON = 0xF2; // INTOSC 32MHZ[/COLOR]
OSCTUNE = 0X1F; // MAX FREQUNCY
Secondly, some of the settings required to configure a 32MHz FOSC using the internal oscillator can either be set using the configuration registers or OSCCON register, the specific details depend on your startup configuration register settings, specifically, the FOSC bits and the PLLEN bit, which should be set to INTOSC and ON masks respectfully.
If the configuration registers are configured as outlined above, setting the bits SCS<1:0> = "00" of the OSCCON register, the default on powerup and reset, and setting the bits IRCF<3:0> = "1110" of the OSCCON register, 8MHz OSC setting, or OSCCON = "0x70" should achieve a 32MHz FOSC.
If the configuration registers are set as outlined above:
NOTE: If the PLL is not enabled in the configuration register settings, then the SPLLEN bit of the OSCCON register will need to be set as well:
Reference: **broken link removed**, Section: 5.2.2.6 32 MHz Internal Oscillator Frequency Selection, Page: 58
5.2.2.6 32 MHz Internal Oscillator Frequency Selection
The Internal Oscillator Block can be used with the 4X
PLL associated with the External Oscillator Block to
produce a 32 MHz internal system clock source. The
following settings are required to use the 32 MHz
internal clock source:
• The FOSC bits in Configuration Words must be
set to use the INTOSC source as the device
system clock (FOSC<2:0> = 100).
• The SCS bits in the OSCCON register must be
cleared to use the clock determined by
FOSC<2:0> in Configuration Words
(SCS<1:0> = 00).
• The IRCF bits in the OSCCON register must be
set to the 8 MHz HFINTOSC set to use
(IRCF<3:0> = 1110).
• The SPLLEN bit in the OSCCON register must be
set to enable the 4xPLL, or the PLLEN bit of the
Configuration Words must be programmed to a
‘1’.
Note: When using the PLLEN bit of the
Configuration Words, the 4xPLL cannot
be disabled by software and the 8 MHz
HFINTOSC option will no longer be
available.
The 4xPLL is not available for use with the internal
oscillator when the SCS bits of the OSCCON register
are set to ‘1x’. The SCS bits must be set to ‘00’ to use
the 4xPLL with the internal oscillator.
BigDog