lalgpt
Junior Member level 3
Hi all
this the program that i have tried to generate sine wave PWM but has a problem when without adding the ADC
it works fine but when adding ADC read it lowers the switching frequency
const unsigned char sinetable[123]={0,6,13,19,25,32,38,44,51,57,63,69,75,81,88,93,99,105,111,117,122,128,
133,139,144,149,154,159,164,169,173,178,182,187,191,195,199,203,206,210,
213,217,220,223,225,228,231,233,235,237,239,241,243,244,245,247,248,248,
249,249,250,250,250,250,249,249,248,248,247,245,244,243,241,239,237,235,
233,231,228,225,223,220,217,213,210,206,203,199,195,191,187,182,178,173,
169,164,159,154,149,144,139,133,128,122,117,111,105,99,93,88,81,75,69,63,
57,51,44,38,32,25,19,13,6};
int i=0;
void main(void)
{
PORTB = 0;
TRISC=0xFB;
TRISB = 0;
LATC=0;
CCP1CON=0x0C;
PR2=249;
T2CON=0x00;
while(1)
{
i=0;
for(i=0; i <123; i++)
{
CCPR1L= sinetable;
TMR2=0x0;
PIR1.TMR2IF=0;
T2CON.TMR2ON=1;
while(PIR1.TMR2IF ==0);
}
PORTB.F1 = !PORTB.F1 ;//RB1
voltage = ADC_read(0); // when adding this switching frequency reduces
}
}
this the program that i have tried to generate sine wave PWM but has a problem when without adding the ADC
it works fine but when adding ADC read it lowers the switching frequency
const unsigned char sinetable[123]={0,6,13,19,25,32,38,44,51,57,63,69,75,81,88,93,99,105,111,117,122,128,
133,139,144,149,154,159,164,169,173,178,182,187,191,195,199,203,206,210,
213,217,220,223,225,228,231,233,235,237,239,241,243,244,245,247,248,248,
249,249,250,250,250,250,249,249,248,248,247,245,244,243,241,239,237,235,
233,231,228,225,223,220,217,213,210,206,203,199,195,191,187,182,178,173,
169,164,159,154,149,144,139,133,128,122,117,111,105,99,93,88,81,75,69,63,
57,51,44,38,32,25,19,13,6};
int i=0;
void main(void)
{
PORTB = 0;
TRISC=0xFB;
TRISB = 0;
LATC=0;
CCP1CON=0x0C;
PR2=249;
T2CON=0x00;
while(1)
{
i=0;
for(i=0; i <123; i++)
{
CCPR1L= sinetable;
TMR2=0x0;
PIR1.TMR2IF=0;
T2CON.TMR2ON=1;
while(PIR1.TMR2IF ==0);
}
PORTB.F1 = !PORTB.F1 ;//RB1
voltage = ADC_read(0); // when adding this switching frequency reduces
}
}