hi, i am new with C programming, this is my 1st time doing programming for my hardware.
well im doing a sinusoidal pulse width modulation (SPWM) signal using ADC conversion.
i compare the sinusoidal waveform with triangularwave. i use 6kHz for triangular wave and 50Hz for sine wave.
however my signal cannot get the result for 6kHz triangular frequency. the maximum it can capture the wave is only 2kHz, can any one help me?
this is the coding i use:
unsigned int ADCRead( unsigned char ch){
unsigned int ADR,l_byte, h_byte ;
ADCON0 = 0x81 | (ch<<3);//configuring analog channel
//selecting analog channel
delay_us(50);
GO_DONE_bit =1;//Start conversion
while(GO_DONE_bit==1); //wait for the conversion to finish
l_byte=ADRESL;
h_byte=ADRESH;
ADR=(h_byte<<8)|l_byte;
return ADR;
}
void main() {
unsigned int Vgrid,Vref,Vtri,Vnew; //adc value
CMCON=7;//Disable comparator
TRISD = 0;
PORTD=0;
ADCON0=0x81;
ADCON1=0xCE;
while(1){
//always true condition. Endless loop
Vsine=ADCRead(0);
Vtri=ADCRead(1);
if (Vsine<Vtri){
RD0_bit=1;
}
else
{
RD0_bit=0;
}
}
}