;--------
PWMInit
;--------
;--Sets up PIC for PWM outputs on CCP1 and CCP2, sets period and initial duty cycles
;---Setup CCP/PWM/PORTC pins as outputs
BANKSEL TRISC ;bank1
bcf TRISC, 2 ;CCP1
bcf TRISC, 1 ;CCP2
;---Set PWM period for both modules
movlw .128
movwf PR2
BANKSEL PIR1 ;bank0
;---Setup Timer2
bcf T2CON, T2CKPS0
bcf T2CON, T2CKPS0 ;prescaler set to 1
bsf T2CON, TMR2ON ;start timer2
;---Setup CCP1 for PWM
movlw .100 ;bits 2-9
movwf CCPR1L ;****duty cycle****
bcf CCP1CON, CCP1Y ;bit 0
bcf CCP1CON, CCP1X ;bit 1
bsf CCP1CON, CCP1M3
bsf CCP1CON, CCP1M2 ;set CCP1 module to PWM
;---Setup CCP2 for PWM
movlw .100 ;bits 2-9
movwf CCPR2L ;****duty cycle****
bcf CCP2CON, CCP2Y ;bit 0
bcf CCP2CON, CCP2X ;bit 1
bsf CCP2CON, CCP2M3
bsf CCP2CON, CCP2M2 ;set CCP2 module to PWM