swapan
Full Member level 4
- Joined
- Feb 20, 2009
- Messages
- 204
- Helped
- 27
- Reputation
- 54
- Reaction score
- 24
- Trophy points
- 1,298
- Location
- Kolkata
- Activity points
- 2,839
Hi Friends,
I am trying my best to test the basic of “generation of sine wave” which is a kind contribution of Mr. Tahmid Mahbub in this forum. After a long study I have more of less grasped the conception. Now I want to carry out a practical test. So far it appears to me, there is no dead-band delay in the code. If I am wrong, please point out the same. For the purpose of incorporating dead-band delay, is it practical to add a portion in the code as per the following? Please see the portion marked in red colour.
regards,
swapan
I am trying my best to test the basic of “generation of sine wave” which is a kind contribution of Mr. Tahmid Mahbub in this forum. After a long study I have more of less grasped the conception. Now I want to carry out a practical test. So far it appears to me, there is no dead-band delay in the code. If I am wrong, please point out the same. For the purpose of incorporating dead-band delay, is it practical to add a portion in the code as per the following? Please see the portion marked in red colour.
regards,
swapan
Code:
unsigned char sin_table[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};
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){
PORTC = 0x00; // [COLOR="#FF0000"]Turn OFF P1A to P1D.[/COLOR]
Delay_10uS; // [COLOR="#FF0000"]Dead-band delay.[/COLOR]
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 = 410;
TBL_POINTER_SHIFT = 0;
TBL_POINTER_NEW = 0;
TBL_POINTER_OLD = 0;
DUTY_CYCLE = 0;
ANSEL = 0; //Disable ADC
CMCON0 = 7; //Disable Comparator
TRISC = 0x3F;
CCP1CON = 0x4C;
TMR2IF_bit = 0;
T2CON = 4; //TMR2 on, prescaler and postscaler 1:1
while (TMR2IF_bit == 0);
TMR2IF_bit = 0;
TRISC = 0;
TMR2IE_bit = 1;
GIE_bit = 1;
PEIE_bit = 1;
while(1);
}