PDA

View Full Version : PIC18F25K22 Oscillator Settings



electromark
- 25th November 2012, 19:34
Major brain moment here:

I am using (newly) a PIC18F25K22. I have having some major difficulty for some reason finding the correct, easy to understand settings to use the internal osc with PBP, generally just basic settings, 4 Mhz is fine, 8, 10 15 whatever. Im currently not in the need of a specific speed.

I do have timer and counter settings that are just not cooperating.


Help!


Thanks

Darrel Taylor
- 26th November 2012, 00:20
PBP's default configuration for the 18F25K22 uses the Internal Oscillator for the Primary Oscillator.
So all you need to do is set the OSCCON register.

OSCCON = %01010000 ; 4Mhz
OSCCON = %01100000 ; 8Mhz
OSCCON = %01110000 ; 16Mhz

Or, if you enable the PLL with ...

OSCTUNE.6 = 1 ; Enable 4x PLL

Then ...

OSCCON = %01010000 ; 16Mhz
OSCCON = %01100000 ; 32Mhz
OSCCON = %01110000 ; 64Mhz

Make sure your DEFINE OSC matches.

electromark
- 26th November 2012, 01:52
Thanks Darrel...


But, I guess that was not the only reason I am not getting this to work:

Take a look below. I have simplified what I am trying to do. Everything was working fine with my PICDEM PIC18 explorer board. But when I went off and built my own circuitry, nothing is happening.

I have external pull ups on the inputs. They are being pulled low, but the "output" pin is not doing anything at all. I dont 'think' it's electrical per se, because I am grounding the input pin manually.

What am I missing??

and by the way, it is OSCCON = %01010000 it does not show up correct on the code snippet for some reason.


DEFINE OSC 4
OSCCON = 010000 ; 4Mhz
ADCON1 = 15 ' All pins digital

STROBE var PORTA.0
STROBEOUT var PORTB.0

STROBEOUT = 0 'just making sure that it is off

do
IF STROBE = 0 THEN
PAUSE 10
STROBEOUT = 1
ELSE
STROBEOUT = 0
ENDIF
loop

Darrel Taylor
- 26th November 2012, 03:58
ADCON1 = 15 ... Sets the Positive and Negative Voltage references to invalid "Reserved" values.
It does not configure "All Digital" like it might on other chips.
For the 18F25K22, it should be ...

ANSELA = 0
ANSELB = 0
ANSELC = 0
Your STROBEOUT pin hasn't been set to OUTPUT.
Either set the TRIS bit, use the OUTPUT command, or use HIGH and LOW commands.

electromark
- 8th January 2013, 01:05
It has been operating somewhat well now, but I have noticed that the delays and thresholds that I have put in place are not actually working properly, meaning that the actual delay is much greater than entered and expected. Any reason why this may be??

Fo instance, if I declare a pause 3000, it seems to take almost 5 seconds, and 750 is almost 2 seconds.

connortop
- 13th September 2016, 08:20
Hello,

i am new to programming and am using a pic18f25k22 im trying to set it up to use an external 8mHz oscillator but from looking at the datasheet i am confused about how i do this any help would be appreciated

thanks connor