Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

SPWM problem for 16f877a with ADC function

Status
Not open for further replies.

teenangel

Newbie level 3
Newbie level 3
Joined
Jan 2, 2013
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,312
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;
}
}
}
 

pwm.png

the frequency for triangular wave is 6K
while the sinusoidal wave is 50Hz

the output wave is as shown in the pic above
 

i want to use spwm as my igbt switching method.
i dont want to use pwm.
so i compare the sine wave with the triangular wave. if the sine wave is bigger than triangular wave the output is 1. if sine < triangular, output will be 0.
 

can i use adc read with comparator? based from my reading, the comparator must be switch off while using adc read right? correct me if im wrong.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top