PIC32MZ - Oscillator.

0.Contents

PIC32MZ MiniTrainer : PIC32MZ1024EFG064.

1.Internal Oscillator - LPRC.

// Configuration registers.
#pragma config DEBUG = OFF, JTAGEN = ON, ICESEL = ICS_PGx1, TRCEN = OFF
#pragma config BOOTISA = MIPS32, FECCCON = OFF_UNLOCKED, FSLEEP = OFF
#pragma config DBGPER = PG_ALL, SMCLR = MCLR_NORM
#pragma config SOSCGAIN = GAIN_1X, SOSCBOOST = OFF, POSCGAIN = GAIN_1X
#pragma config POSCBOOST = OFF, EJTAGBEN = NORMAL
#pragma config FNOSC = LPRC, DMTINTV = WIN_127_128, FSOSCEN = OFF, IESO = OFF
#pragma config POSCMOD = OFF, OSCIOFNC = ON, FCKSM = CSECME
#pragma config WDTPS = PS1048576, WDTSPGM = STOP, WINDIS = NORMAL
#pragma config FWDTEN = OFF, FWDTWINSZ = WINSZ_25, DMTCNT = DMT31, FDMTEN = ON
#pragma config FPLLIDIV = DIV_8, FPLLRNG = RANGE_34_68_MHZ, FPLLICLK = PLL_FRC
#pragma config FPLLMULT = MUL_128, FPLLODIV = DIV_32, UPLLFSEL = FREQ_24MHZ
#pragma config FMIIEN = OFF, FETHIO = OFF, PGL1WAY = ON, PMDL1WAY = ON
#pragma config IOL1WAY = ON, FUSBIDIO = ON
#pragma config CP = OFF

#include <xc.h>
// PIC32MZ1024EFG064 - Compile with XC32(v1.44).
// Internal Oscillator - LPRC.

// OSC2 -> Oscilloscope Chanel A.
// RB0  -> Oscilloscope Chanel B.

// Definitions.
#define PROBE		LATBbits.LATB0
#define PROBE_TRIS	TRISBbits.TRISB0

// Main.
int main(void)
{
	// Wait LPRC is stable and ready.
	while(!CLKSTATbits.LPRCRDY);
	
	PROBE = 0;
	PROBE_TRIS = 0;
	
	while(1){
		PROBE ^= 1;
	}
	return(0);
}
Fsys ~ 32kHz.

2.Internal Oscillator - FRCDIV.

// Configuration registers.
#pragma config DEBUG = OFF, JTAGEN = ON, ICESEL = ICS_PGx1, TRCEN = OFF
#pragma config BOOTISA = MIPS32, FECCCON = OFF_UNLOCKED, FSLEEP = OFF
#pragma config DBGPER = PG_ALL, SMCLR = MCLR_NORM
#pragma config SOSCGAIN = GAIN_1X, SOSCBOOST = OFF, POSCGAIN = GAIN_1X
#pragma config POSCBOOST = OFF, EJTAGBEN = NORMAL
#pragma config FNOSC = FRCDIV, DMTINTV = WIN_127_128, FSOSCEN = OFF, IESO = OFF
#pragma config POSCMOD = OFF, OSCIOFNC = ON, FCKSM = CSECME
#pragma config WDTPS = PS1048576, WDTSPGM = STOP, WINDIS = NORMAL
#pragma config FWDTEN = OFF, FWDTWINSZ = WINSZ_25, DMTCNT = DMT31, FDMTEN = ON
#pragma config FPLLIDIV = DIV_8, FPLLRNG = RANGE_34_68_MHZ, FPLLICLK = PLL_FRC
#pragma config FPLLMULT = MUL_128, FPLLODIV = DIV_32, UPLLFSEL = FREQ_24MHZ
#pragma config FMIIEN = OFF, FETHIO = OFF, PGL1WAY = ON, PMDL1WAY = ON
#pragma config IOL1WAY = ON, FUSBIDIO = ON
#pragma config CP = OFF

#include <xc.h>
// PIC32MZ1024EFG064 - Compile with XC32(v1.44).
// Internal Oscillator - FRCDIV.

// OSC2 -> Oscilloscope Chanel A.
// RB0  -> Oscilloscope Chanel B.

// Definitions.
#define PROBE		LATBbits.LATB0
#define PROBE_TRIS	TRISBbits.TRISB0

// Main.
int main(void)
{
	// Unlock sequence.
	SYSKEY = 0xAA996655;
	SYSKEY = 0x556699AA;
	OSCCONbits.FRCDIV = 0b000;
	SYSKEY = 0x0;
	// Wait FRC is stable and ready.
	while(!CLKSTATbits.FRCRDY);
	
	PROBE = 0;
	PROBE_TRIS = 0;
	
	while(1){
		PROBE ^= 1;
	}
	return(0);
}
Fsys ~ 8MHz - FRCDIV2.0 = 0 0 0
Fsys ~ 31kHz - FRCDIV2.0 = 1 1 1.

3.Internal Oscillator - FRCPLL

// Configuration registers.
#pragma config DEBUG = OFF, JTAGEN = ON, ICESEL = ICS_PGx1, TRCEN = OFF
#pragma config BOOTISA = MIPS32, FECCCON = OFF_UNLOCKED, FSLEEP = OFF
#pragma config DBGPER = PG_ALL, SMCLR = MCLR_NORM
#pragma config SOSCGAIN = GAIN_1X, SOSCBOOST = OFF, POSCGAIN = GAIN_1X
#pragma config POSCBOOST = OFF, EJTAGBEN = NORMAL
#pragma config FNOSC = SPLL, DMTINTV = WIN_127_128, FSOSCEN = OFF, IESO = OFF
#pragma config POSCMOD = OFF, OSCIOFNC = ON, FCKSM = CSECME
#pragma config WDTPS = PS1048576, WDTSPGM = STOP, WINDIS = NORMAL
#pragma config FWDTEN = OFF, FWDTWINSZ = WINSZ_25, DMTCNT = DMT31, FDMTEN = ON
#pragma config FPLLIDIV = DIV_8, FPLLRNG = RANGE_34_68_MHZ, FPLLICLK = PLL_FRC
#pragma config FPLLMULT = MUL_128, FPLLODIV = DIV_32, UPLLFSEL = FREQ_24MHZ
#pragma config FMIIEN = OFF, FETHIO = OFF, PGL1WAY = ON, PMDL1WAY = ON
#pragma config IOL1WAY = ON, FUSBIDIO = ON
#pragma config CP = OFF

#include <xc.h>
// PIC32MZ1024EFG064 - Compile with XC32(v1.44).
// Internal Oscillator - FRCPLL.

// OSC2 -> Oscilloscope Chanel A.
// RB0  -> Oscilloscope Chanel B.

// Definitions.
#define PROBE		LATBbits.LATB0
#define PROBE_TRIS	TRISBbits.TRISB0

// Main.
int main(void)
{
	PROBE = 0;
	PROBE_TRIS = 0;
	
	while(1){
		PROBE ^= 1;
	}
	return(0);
}
Fsys ~ 256kHz - FPLLMULT = MUL_1 - FPLLODIV = DIV_32
Fsys ~ 256MHz - FPLLMULT = MUL_128 - FPLLODIV = DIV_4

02.2018