I'd like to run a Microchip PIC18F25K50 at its maximum speed of 48MHz from its internal oscillator.

Here is the overview of the oscillator system from the datasheet:

enter image description here

The 16MHz from the HFINTOSC can be fed directly to the CPU by setting SCS = 0b10 (INTOSC). When doing so, I get exactly what I expect:

enter image description here

My code toggles an output, and the pulses have a width of ~250ns / 4MHz, which is the execution speed of the MCU of 16MHz/4.

Now, the 16MHz INTOSC is also fed into the primary clock module, so enabling the 3x PLL, setting the PLL postscaler to /1 , and choosing SCS=00 (Primary clock) should give a 48MHz clock / 12MHz execution speed.

However, that does not work. The MCU shows an extreme capacitive sensivity, it normally doesn't produce any pulses. When I put my hands nearby or even touch it, it starts to produce pulses of various, but extreme lengths. To me, it seems the MCU somehow catches noise and derives its clock from it. By the way, I also bypassed the PLL by CFGPLLEN=0, that doesn't change anything.

Does anyone know how to run the MCU at 48MHz from internal oscillator?

Here are my config bits:

#pragma config PLLSEL = 1    // PLL multiplier: 0->4x 1->3x  
#pragma config CFGPLLEN = 0  // PLL enabled?
#pragma config CPUDIV = 0    // CPU Clock divider: 0-> No divider
#pragma config LS48MHZ = 1   // USB clock: System@48MHz->0 System@24MHz->1

#pragma config FOSC = 0b1001 // OscillatorConfig: InternalOscClockOut->1001
#pragma config PCLKEN = 0    // Primary clock: disable by software ->0 alwaysEnabled->1
#pragma config FCMEN = 0     // Fail-Safe Clock Monitor?
#pragma config IESO = 0      // Internal/External Oscillator Switchover?

and here my code:

void main(void)
    OSCCONbits.IRCF=0b111; // No divide -> 16MHz
    OSCCONbits.SCS=0b00;  // Primary clock
    //OSCCONbits.SCS=0b10;  // INTOSC
    ANSELA=0;            //Make PortA digital
    TRISAbits.TRISA0=0;  //Make PortA output

    while (1){    
  • \$\begingroup\$ Is it doing the same thing when probe it with an oscope? Unless that chart above is an oscope reading, I'm unfamiliar with that user interface. \$\endgroup\$
    – user103380
    Aug 16, 2018 at 21:09
  • \$\begingroup\$ I don't see a config to disable MCLR. Or do you drag it high? \$\endgroup\$
    – glen_geek
    Aug 16, 2018 at 21:23
  • \$\begingroup\$ Note there is a “datasheet clarification” in the errata relating to the oscillator diagram you posted. \$\endgroup\$
    – David
    Aug 16, 2018 at 22:35
  • 2
    \$\begingroup\$ +1 for using a scope when developing firmware. \$\endgroup\$ Aug 16, 2018 at 22:48

1 Answer 1


Data sheet page 31 has this table for PLL setup:

from PIC18F25K50 data sheet, Microchip

Looks like OSCCON2 register should have the PLLEN set high. It defaults to low on powerup or reset.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.