/*unsigned char sin_table[64]={0, 7, 15, 22, 29, 36, 44, 51, 57, 64,
71, 77, 83, 89, 95, 101, 106, 111, 116, 120, 125, 129, 132,
136, 139, 141, 144, 146, 147, 148, 149, 150, 150, 150, 149,
148, 147, 146, 144, 141, 139, 136, 132, 129, 125, 120, 116, 111, 106, 101, 95,
89, 83, 77, 71, 64, 57, 51, 44, 36, 29, 22, 15, 7}; */
unsigned char sin_table[64]={0, 10, 21, 31, 41, 50, 59, 68, 76, 83, 89,
94, 99, 102, 105, 106, 107, 106, 105, 102, 99, 94, 89, 83, 76, 68, 59,
50, 41, 31, 21, 10};
unsigned int TBL_POINTER_NEW, TBL_POINTER_OLD, TBL_POINTER_SHIFT, SET_FREQ;
unsigned int TBL_temp;
unsigned char DUTY_CYCLE;
void interrupt(){
if (TMR2IF_bit == 1){
TBL_POINTER_NEW = TBL_POINTER_OLD + SET_FREQ;
if (TBL_POINTER_NEW < TBL_POINTER_OLD){
CCP1CON.P1M1 = ~CCP1CON.P1M1; //Reverse direction of full-bridge
}
TBL_POINTER_SHIFT = TBL_POINTER_NEW >> 11;
DUTY_CYCLE = TBL_POINTER_SHIFT;
CCPR1L = sin_table[DUTY_CYCLE];
TBL_POINTER_OLD = TBL_POINTER_NEW;
TMR2IF_bit = 0;
}
}
void main() {
SET_FREQ = 340;
TBL_POINTER_SHIFT = 0;
TBL_POINTER_NEW = 0;
TBL_POINTER_OLD = 0;
DUTY_CYCLE = 0;
PR2=149; ///for 20Khz at 12MHZ of quartz
TRISB=0x00;
CCP1CON=0x4C;
TMR2IF_bit = 0;
T2CON = 4; //TMR2 on, prescaler and postscaler 1:1
while (TMR2IF_bit == 0);
TMR2IF_bit = 0;
TRISB=0;
TMR2IE_bit = 1;
GIE_bit = 1;
PEIE_bit = 1;
while(1);
}