look at this code this may help...
program Eccp_sine_pwm_403
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' sinusoidal PWM can be found in many power conversion application
'such as UPS or HV AC motor controler.
'This is very simple development example wich can be executed on Easy Pic3
'whit out any external components.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Hardware: EP3 , PIC 18f458 , 4 MHZ crystal
' Configuration: clock 16MHZ
' HSPLL_OCS
' PWRT_ON
' WDT_OFF
' LVP_OFF
' (Can be 16MHz crystal and HS_osc)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Used peripherie: Enhanced CCP1 in full-bridge mode
'
' FORWARD (Positiv half-wave) REVERSE (Negativ half-wave)
' ___________________________________________________________
' RD4 P1A Activ RD4 P1A Inactiv
' RD5 P1B Inactiv RD5 P1B Modulated
' RD6 P1C Inactiv RD6 P1C Activ
' RD7 P1D Modulated RD7 P1D Inactiv
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' PWM Frequncy 16KHz ( Period 62,5uS )
'
' sinusoidal frequency from 0,125Hz to 100HZ step 0,125 HZ
' Initial Frequency 1HZ
'
' RB0 Button -> Frequncy Up
' RB1 Button -> Frequency Down
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' 32 value of the half sine table. Used for up-date duty cycle.
' Second or negativ half-wave using same table, only bridge direction is changed.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
const sin_table as byte[32]=(0,25,49,73,96,118,137,
159,177,193,208,220,231,239,245,249,250,249,245,
239,231,220,208,193,177,159,137,118,96,73,49,25)
DIM TBL_POINTER_NEW AS WORD
DIM TBL_POINTER_OLD AS WORD
DIM TBL_POINTER_SHIFT AS WORD
DIM SET_FREQ as word
DIM DUTY_CYCLE AS BYTE
sub procedure interrupt
IF PIR1.TMR2IF=1 ''''''''''''''''''''''''''
THEN TBL_POINTER_NEW=TBL_POINTER_OLD+SET_FREQ 'IF OVERFLOW, THEN CHANGE
IF TBL_POINTER_NEW < TBL_POINTER_OLD 'DIRECTION OF THE BRIDGE
THEN ''''''''''''''''''''''''''
ASM
BTG ECCP1CON,EPWM1M1
END ASM
END IF '''''''''''''''''''''''''''
TBL_POINTER_SHIFT =TBL_POINTER_NEW >> 11 ' GET 6 BIT WIDE INDEX
DUTY_CYCLE=LO(TBL_POINTER_SHIFT) ' FOR ONE OF 32 VALUE FROM
ECCPR1L=SIN_TABLE[DUTY_CYCLE] ' SINE_TABLE AND UP-DATE
TBL_POINTER_OLD=TBL_POINTER_NEW ' DUTY CYCLE
PIR1.TMR2IF=0 '''''''''''''''''''''''''''
END IF
END SUB
main: '''''''''''''''''''''''''''''''''''''''''''''
cmcon=7 '
SET_FREQ=8 ' initial frequency 1Hz
TBL_POINTER_SHIFT=0 '
TBL_POINTER_NEW=0 '
TBL_POINTER_OLD=0 '
DUTY_CYCLE=0 '
TRISD=255 '
PR2=249 ' 16KHz
ECCPR1L=0 '
ECCP1CON=%01001100 'FULL-BRIDGE, FORWARD
PIR1.TMR2IF=0 '
T2CON.T2CKPS0=0 '
T2CON.T2CKPS1=0 ' PRESCALER TMR2=1
T2CON.TMR2ON=1 ' START TMR2
''''''''''''''''''''''''''''''''''''''''''''''''
WHILE PIR1.TMR2IF=0 ''''''''''''''''''''''''''''''''''''''''''''''''
WEND ' Starting-up ECCP
PIR1.TMR2IF=0 ' Recommended by Data-Sheet
TRISD=0 '
PIE1.TMR2IE=1 '
INTCON.PEIE=1 '
INTCON.GIE=1 ''''''''''''''''''''''''''''''''''''''''''''''''
WHILE 1=1 '''''''''''''''''''''''''''''''''''''''''''''''
if button(portb,0,10,1) ' Frequency UP/Down
then '
if SET_FREQ<819 ' 100HZ
then '
SET_FREQ=SET_FREQ+1 '
end if '
end if '
if button(portb,1,10,1) '
then '
if SET_FREQ>1 '0.125HZ
then '
SET_FREQ=SET_FREQ-1 '
end if '
end if '''''''''''''''''''''''''''''''''''''''''''''''
WEND
END.