jean12
Advanced Member level 2
- Joined
- Aug 27, 2013
- Messages
- 529
- Helped
- 5
- Reputation
- 12
- Reaction score
- 6
- Trophy points
- 18
- Activity points
- 5,497
unsigned char sin_table[64]={0, 12, 25, 37, 50, 62, 74, 86, 97, 108,
120, 130, 141, 151, 161, 170, 179, 187, 195, 203, 210, 217, 222,
228, 233, 237, 241, 244, 246, 248, 249, 250, 250, 249, 248, 246,
244, 241, 237, 233, 228, 222, 217, 210, 203, 195, 187, 179, 170, 161, 151,
141, 130, 120, 108, 97, 86, 74, 62, 50, 37, 25, 12,0};
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 >> 10;
DUTY_CYCLE = TBL_POINTER_SHIFT;
CCPR1L = sin_table[DUTY_CYCLE];
TBL_POINTER_OLD = TBL_POINTER_NEW;
TMR2IF_bit = 0;
}
}
void main() {
SET_FREQ = 256;
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=0x4D;
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);
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?