I normally like to code all of my own hardware using the direct access to registers however PBP has included a very nice HPWM Command that makes all of this very simple... However i feel a bit confused as to what is all required in the code to make the HPWM function work correctly in PBP3.

Does anyone have an simple and or basic code that can be used for my 18F45K22 device?

The 18F45K22 has select-able ccp channels and it is unclear to me (even after reading the datasheet section) how to align these cpp channels correctly using the registers.

I am using 4 LED's that i would like to control using HPWM. I am running the cpu from its internal 16Mhz OSC

LED 1: RC2/CCP1
LED 2: RC1/CCP2
LED 3: RE0/CCP3
LED 4: RD1/CCP4

I have already set the pins. but I am not sure about the additional registers and defining the timers. Example "define CCP1_REG & define CCP1_BIT" etc...

TRISC.2 = 0 ' Set Pin to Output
ANSELC.2 = 0 ' Set Pin to Digital
Mode_LED_R var PortC.2 ' Digital PWM Output: Mode LED Red Element

TRISC.1 = 0 ' Set Pin to Output
ANSELC.1 = 0 ' Set Pin to Digital
Mode_LED_G var PortC.1 ' Digital PWM Output: Mode LED Green Element

TRISE.0 = 0 ' Set Pin to Output
ANSELE.0 = 0 ' Set Pin to Digital
Mode_LED_B var PortE.0 ' Digital PWM Output: Mode LED Blue Element

TRISD.1 = 0 ' Set Pin to Output
ANSELD.1 = 0 ' Set Pin to Digital
Bluetooth_Link_LED var PortD.1 ' Digital PWM Output: Blue Link Status LED


define HPWM1_TIMER 1
define HPWM2_TIMER 2
define HPWM3_TIMER 3
define HPWM4_TIMER 4
CCP1CON = %00001100 ' Turn CCP1 to PWM Mode
CCP2CON = %00001100 ' Turn CCP2 to PWM Mode
CCP3CON = %00001100 ' Turn CCP3 to PWM Mode
CCP4CON = %00001100 ' Turn CCP4 to PWM Mode
CCP5CON = %00000000 ' Dissable Comparator / PWM Module


Any help or example code of how to use the HPWM on this chip would be GREATLY Appreciated!!!