0

I am using a PIC18F45K20 to take in an external oscillation from a 25Mhz crystal instead of using the internal clock. However, what do I include in the code to set this external oscillator as an input (I presume OSC1 on PIC device)? Below are the typical config pragmas I have in a .h file.

    // CONFIG1H
    #pragma config FOSC = HSPLL     
    #pragma config FCMEN = OFF      
    #pragma config IESO = OFF       

    // CONFIG2L
    #pragma config PWRT = OFF       
    #pragma config BOREN = SBORDIS  
    #pragma config BORV = 18        

    // CONFIG2H
    #pragma config WDTEN = OFF      
    #pragma config WDTPS = 32768  

    // CONFIG3H
    #pragma config CCP2MX = PORTC  
    #pragma config PBADEN = ON     
    #pragma config LPT1OSC = OFF    
    #pragma config HFOFST = ON      
    #pragma config MCLRE = ON      

    // CONFIG4L
    #pragma config STVREN = ON      
    #pragma config LVP = OFF         
    #pragma config XINST = OFF      

    // CONFIG5L
    #pragma config CP0 = OFF        
    #pragma config CP1 = OFF       
    #pragma config CP2 = OFF        
    #pragma config CP3 = OFF        

    // CONFIG5H
    #pragma config CPB = OFF        
    #pragma config CPD = OFF        

    // CONFIG6L
    #pragma config WRT0 = OFF       
    #pragma config WRT1 = OFF       
    #pragma config WRT2 = OFF     
    #pragma config WRT3 = OFF       

    // CONFIG6H
    #pragma config WRTC = OFF      
    #pragma config WRTB = OFF       
    #pragma config WRTD = OFF       

    // CONFIG7L
    #pragma config EBTR0 = OFF     
    #pragma config EBTR1 = OFF      
    #pragma config EBTR2 = OFF      
    #pragma config EBTR3 = OFF      

    // CONFIG7H
    #pragma config EBTRB = OFF      

    #define _XTAL_FREQ 25000000
    #ifndef MCC_H
    #define MCC_H
    #include <xc.h>
    #include "pin_manager.h"
    #include <stdint.h>
    #include <stdbool.h>
    #include "eusart.h"

However, when I try to build this, I get errors:

    mcc_generated_files/mcc.h:46: error: (1389) attempt to reprogram configuration setting "FOSC" with HSPLL (is HSPLL)
    mcc_generated_files/mcc.h:68: error: (1389) attempt to reprogram configuration setting "LVP" with OFF (is OFF)

Am I doing something wrong? What do these errors even mean? All I want to do is change from using the internal clock to using an external 25Mhz crystal.

noobling
  • 21
  • 5

1 Answers1

0

Line: #pragma config FOSC = HSPLL is wrong because the maximum CPU frequency is 64 MHz. PLL option multiply frequency by 16, so use only HS option for 25 Mhz crystal.

Line: #pragma config LVP = OFF, what kind programer you are using? If you are programming your device inSingle-Supply mode than you can't switch off this mode.

GJ.
  • 10,810
  • 2
  • 45
  • 62
  • When I changed it to HS, I still got the same error (attempt to reprogram ... with HS (is HS). And I am using a PICkit3 to program my device. However, I can't even go through with just a build. Turning LVP on seemed to get rid of that particular error though. – noobling Sep 25 '17 at 16:38