16F18877 CONFIG with PPS register settings
32MHz internal
Config:
Code:
#CONFIG
__config _CONFIG1, _FEXTOSC_OFF & _RSTOSC_HFINT32 & _CLKOUTEN_OFF & _CSWEN_OFF & _FCMEN_ON
__config _CONFIG2, _MCLRE_ON & _PWRTE_OFF & _LPBOREN_OFF & _BOREN_ON & _BORV_LO & _ZCD_OFF & _PPS1WAY_OFF & _STVREN_ON & _DEBUG_OFF
__config _CONFIG3, _WDTCPS_WDTCPS_11 & _WDTE_ON & _WDTCWS_WDTCWS_7 & _WDTCCS_LFINTOSC
__config _CONFIG4, _WRT_OFF & _SCANE_available & _LVP_OFF
__config _CONFIG5, _CP_OFF & _CPD_OFF
#ENDCONFIG
Oscillator:
Code:
DEFINE OSC 32
OSCCON1 = %01100010
' bit 7 n/a
' 6-4 NOSC New Oscillator Source Request bits
' 110 HFINTOSC
' 3-0 NDIV New Divider Selection Request bits
' 0010 Clock divider = 4
OSCCON3 = %00000000 ' Default values
OSCEN = %00000000 ' Default values
OSCFRQ = %00000110
' bit 7-3 n/a
' 2-0 HFFRQ Frequency Selection bits
' 110 32 MHz
OSCTUNE = %00000000 ' Default values
PPS pin definitions to use CCP3 and CCP4 on Ports D2 and D3 respectively:
Code:
PinD2 CON %011010 ' Datasheet table 13-2
PinD3 CON %011011
CCP3PPS = PinD2 ' CCP3 Peripheral input selection
CCP4PPS = PinD3 ' CCP4 Peripheral input selection
PeripheralCCP3 CON %001011 ' Datasheet table 13-3
PeripheralCCP4 CON %001100
RD2PPS = PeripheralCCP3 ' Pin D2 output source selection
RD3PPS = PeripheralCCP4 ' Pin D3 output source selection
HPWM on pins D2 and D3:
Code:
HPWM 3,160,1953 ' Sample Pulses
HPWM 4,180,1953
Thanks go to TimB and Top204 on the Proton forum (that's where I got the Config from):
https://protoncompiler.com/index.php?topic=528.0
Re: 16F18877 CONFIG with PPS register settings
With those config1 settings you really shouldn't need to program any of the osc registers in code... it should run at 32Mhz at startup
Re: 16F18877 CONFIG with PPS register settings
Yup. I can confirm it will work without the register definitions in this case (LCDOUT and heartbeat LED working properly).
Re: 16F18877 CONFIG with PPS register settings
NOTE: When moving a feature away from a pin, make sure to clear the PPS register for that pin.
Code:
RB5PPS = 0 ' Disable CCP3
RB0PPS = 0 ' Disable CCP4
Or else you risk having all sorts of annoying surprises; like having a regular pulse coming out of what you thought was an input pin.
In my case, I moved CCP3 and CCP4 to other pins and was trying to use B0 and B5 for a rotary encoder signal. Took me WAAAAY too long to realize what was going on, but a quick google and Ric over at Microchip had the answer:
https://forum.microchip.com/s/topic/...ment=P-2930284