PIC18F2620 - Oscillator.

0.Contents

PIC18F Trainer : PIC18F2620.

1.Internal Oscillator.

// Configuration registers.
#pragma config IESO = OFF, FCMEN = OFF, OSC = INTIO7
#pragma config BORV = 3, BOREN = OFF, PWRT = OFF
#pragma config WDTPS = 32768, WDT = OFF
#pragma config MCLRE = ON, LPT1OSC = OFF, PBADEN = OFF, CCP2MX = PORTC
#pragma config DEBUG = OFF, XINST = OFF, LVP = OFF, STVREN = ON
#pragma config CP3 = OFF, CP2 = OFF, CP1 = OFF, CP0 = OFF
#pragma config CPD = OFF, CPB = OFF
#pragma config WRT3 = OFF, WRT2 = OFF, WRT1 = OFF, WRT0 = OFF
#pragma config WRTD = OFF, WRTB = OFF, WRTC = OFF
#pragma config EBTR3 = OFF, EBTR2 = OFF, EBTR1 = OFF, EBTR0 = OFF
#pragma config EBTRB = OFF

#include <xc.h>
// PIC18F2620 - Compile with XC8(v1.44).

// MCU.RA6 -> PROBE A - Fosc/4 - Output on RA6.
// MCU.RA0 -> PROBE B - Output on RA0.

// Definitions.
#define PROBE_LAT		LATAbits.LATA0
#define PROBE_TRIS		TRISAbits.TRISA0

// Main.
int main(void)
{
	PROBE_LAT = 0;
	PROBE_TRIS = 0;

	// Internal Oscillator Frequency Select bits.
	// IRCF2.0 = 1 1 1 - 8MHz.
	// IRCF2.0 = 1 1 0 - 4MHz.
	// IRCF2.0 = 1 0 1 - 2MHz.
	// IRCF2.0 = 1 0 0 - 1MHz.
	// IRCF2.0 = 0 1 1 - 500kHz.
	// IRCF2.0 = 0 1 0 - 250kHz.
	// IRCF2.0 = 0 0 1 - 125kHz.
	// IRCF2.0 = 0 0 0 - 31kHz.
	OSCCONbits.IRCF2 = 0;
	OSCCONbits.IRCF1 = 0;
	OSCCONbits.IRCF0 = 0;
	// Frequency Tunning.
	// TUN4.0 = 0 1 1 1 1 1 - Maximum frequency.
	// ...
	// TUN4.0 = 0 0 0 0 0 0 - Center frequency, Calibrated frequency.
	// ...
	// TUN4.0 = 1 0 0 0 0 0 - Minimum frequency.
	OSCTUNE = 0b00000000;
	// PLL - Frequency Multiplier PLL for INTOSC Enable bit.
	// PLLEN0 = 0 - PLL Disabled.
	// PLLEN0 = 1 - PLL Enabled for INTOSC 4MHz & 8MHz only.
	OSCTUNEbits.PLLEN = 0;
	// Wait frequency is stable.
	while(!OSCCONbits.IOFS);

	while(1){
		PROBE_LAT ^= 1;
	}
	return(0);
}
Fosc = 31kHz - IRCF2.0 = 0 0 0 - PLLEN = 0
Fosc = 125kHz - IRCF2.0 = 0 0 1 - PLLEN = 0
Fosc = 250kHz - IRCF2.0 = 0 1 0 - PLLEN = 0
Fosc = 500kHz - IRCF2.0 = 0 1 1 - PLLEN = 0
Fosc = 1MHz - IRCF2.0 = 1 0 0 - PLLEN = 0
Fosc = 2MHz - IRCF2.0 = 1 0 1 - PLLEN = 0
Fosc = 4MHz - IRCF2.0 = 1 1 0 - PLLEN = 0
Fosc = 8MHz - IRCF2.0 = 1 1 1 - PLLEN = 0
Fosc = 16MHz - IRCF2.0 = 1 1 0 - PLLEN = 1
Fosc = 32MHz - IRCF2.0 = 1 1 1 - PLLEN = 1

03.2018