# Setting the internal oscillator speed on PIC12F1822

I'm trying to get a PIC12F1822 to run at 32 MHz. Here are the relevant bits of code:

__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
__CONFIG _CONFIG2, _WRT_OFF & _PLLEN_ON & _STVREN_OFF & _BORV_19 & _LVP_OFF

MOVLW   b'11110000' ; 32MHz HFINTOSC

BANKSEL OSCCON
MOVWF   OSCCON

BANKSEL OSCSTAT
btfss OSCSTAT, HFIOFR      ; Is internal oscillator running?
goto $-1 btfss OSCSTAT, HFIOFL ; Is internal oscillator locked? goto$-1

BANKSEL TRISA
CLRF    TRISA

BANKSEL PORTA

ON
BSF      PORTA,2          ; 1 cycle
GOTO    OFF               ; 2 cycles

OFF
BCF      PORTA,2          ; 1 cycle
GOTO     ON               ; 2 cycles


I'm getting a 1.33MHz square wave from PORTA,2, meaning that the clock is running at 8MHz... The PLL is definitely working though, as if I switch it off, the freqency drops to 333KHz (2MHz)

According to the debugger (PicKit3), OSCCON is getting the correct value.

The chip is running at 5 V.

Any ideas?

• D'oh... Instruction speed is 1/4 clock frequency, so it's all working fine :) Commented Sep 13, 2012 at 12:37

The instruction clock on this part (and most PICs in general) runs at $\frac{F_{OSC}}{4}$.
Each instruction cycle is $\frac{4}{32 MHz} = 125ns$
(6 total clocks = $750ns$ = 1.33 MHz)
• Er... isn't 6 $\times$ 125 ns equal to 750 ns? Commented Sep 13, 2012 at 13:01