PDA

View Full Version : PIC18f25k22 help with OSC configs



brid0030
- 6th February 2012, 22:32
This is a case of trying too many new things at once. I'm using a PIC18f25k22 (a new device for me) with a standalone, 3-pin 20 Mhz oscillator (also new to me - see photo), and PBP 3 (new to everyone). Right now I'm just starting with a blinky program. I can flash an LED no problem using the internal oscillator, but when I try the external oscillator, the led flashes way too slow--about 20 times too slow to be more precise. If I change the DEFINE OSC statement from 20 to 4 the flashing speeds up, but it is still too slow. It is as if the oscillator is actually working at 1 Mhz instead of 20.
6259

Here is what works (internal oscillator):



asm
__CONFIG _CONFIG1H, _FOSC_INTIO67_1H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_INTMCLR_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
endasm


OSCCON = 110000; ' 16mHz


DEFINE OSC 16


ANSELA = 0
ANSELB = 0
ANSELC = 0


TRISA = 0
TRISB = 0
TRISC = 0


PORTA = 0
PORTB = 0
PORTC = 0


FLASHLOOP:
HIGH PORTB.4
pause 500
LOW PORTB.4
PAUSE 500
GOTO FLASHLOOP


eND


And here is what works way too slow:



asm
__CONFIG _CONFIG1H, _FOSC_XT_1H
__CONFIG _CONFIG3H, _PBADEN_OFF_3H & _MCLRE_INTMCLR_3H
__CONFIG _CONFIG4L, _LVP_OFF_4L & _XINST_OFF_4L
endasm


DEFINE OSC 20


ANSELA = 0
ANSELB = 0
ANSELC = 0


TRISA = 0
TRISB = 0
TRISC = 0


PORTA = 0
PORTB = 0
PORTC = 0


FLASHLOOP:
HIGH PORTB.4
pause 500
LOW PORTB.4
PAUSE 500
GOTO FLASHLOOP


eND


I'm hopeful that someone will see an obvious error. I've been playing around with configuration settings and datasheets, but I am far from exhausting all possible options.

brid0030
- 6th February 2012, 22:45
Nevermind. Figured it out 5 minutes later. I needed to specify a high speed, high power oscillator and I had to turn off the clock multiplier thingy. In other words:


_CONFIG _CONFIG1H, _FOSC_HSHP_1H & _PLLCFG_OFF_1H

MOUNTAIN747
- 6th February 2012, 23:11
Brid0030,
I can’t see the connection with your EXT OSC CONFIG’S but there is a note in the OSC module section of the data sheet that says the default output freq of HFINTOSC is 1 Mhz. Did you include in your post all of your EXT OSC code?

Wayne

brid0030
- 7th February 2012, 14:26
Not sure what you are getting at, Wayne. Yes, all the code is there. The 1 Mhz default condition might explain why the PIC seemed to operate at 1 Mhz when I specified the wrong OSC configuration (XT and not HFHP).

Demon
- 7th February 2012, 18:23
Read his edit where he says oops!

Robert
:)