Here is a code snippet to initialize the PWM module. It is not yet been tested since I had set that project aside for now. I hope it helps you get started.
You define the value of PTPER_VAL to set the PWM frequency. See table 17-2 of the PIC18F4431 datasheet for the suggested values.
Code:
;-----------------------------------------------------------
; Init PWM module
;
MOVLW 1<<PTMOD1 ; 1:1 prescale,1:1 postscale, up/down
MOVWF PTCON0
;
MOVLW 1<<PWMEN2|1<<PWMEN1|1<<PMOD1|1<<PMOD0
MOVWF PWMCON0
;
MOVLW 0 ; 1:1 Postscale
MOVWF PWMCON1
;
MOVLW LOW PTPER_VAL
MOVWF PTPERL
MOVLW HIGH PTPER_VAL
MOVWF PTPERH
;
CLRF DTCON
;
BSF PTCON1,PTEN ; Fire up the PWM module