Okay.
Here is the code for SPWM:
#include <xc.h>
#define _XTAL_FREQ 20000000
unsigned char sin_table[25]={0,2,4,7,9,11,12,14,15,16,17,18,18,18,18,17,16,15,14,12,11,9,7,4,2};
unsigned int TBL_POINTER_NEW, TBL_POINTER_OLD, TBL_POINTER_SHIFT, SET_FREQ;
unsigned int TBL_temp;
unsigned char DUTY_CYCLE;
void interrupt tc_int (void){
if (PIR1bits.TMR2IF == 1){
TBL_POINTER_NEW = TBL_POINTER_OLD + SET_FREQ;
if (TBL_POINTER_NEW < TBL_POINTER_OLD){
CCP1CONbits.P1M1 = ~CCP1CONbits.P1M1; //Reverse direction of full-bridge
}
TBL_POINTER_SHIFT = TBL_POINTER_NEW >> 12;
DUTY_CYCLE = TBL_POINTER_SHIFT;
CCPR1L = sin_table[DUTY_CYCLE];
TBL_POINTER_OLD = TBL_POINTER_NEW;
PIR1bits.TMR2IF = 0;
}
}
void main() {
SET_FREQ = 205;
TBL_POINTER_SHIFT = 0;
TBL_POINTER_NEW = 0;
TBL_POINTER_OLD = 0;
DUTY_CYCLE = 0;
ANSEL = 0; //Disable ADC
CMCON0 = 7; //Disable Comparator
PR2 = 24;
TRISC = 0x3F;
CCP1CON = 0x4C;
PIR1bits.TMR2IF = 0;
T2CON = 4; //TMR2 on, prescaler and postscaler 1:1
while (PIR1bits.TMR2IF == 0);
PIR1bits.TMR2IF = 0;
TRISC = 0;
PIE1bits.TMR2IE = 1;
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
while(1);
}
But, also, I want to design filter which will place just after the H-Bridge. I gone through with many article and research paper, but I am unable to find right L.C.R value. Can someone help me?