Help required for sineusoidal PWM

Thread Starter

praveen_palaparthi

Joined Sep 30, 2009
2
Respected sir,
i AM PRAVEEN WORKING ON SINE WAVE UPS USING PIC MICRO CONTROLLER.I am having a problem and not able to solve i need ur to solve.Problem is i have written code for sinusoidal PWM of off line ups,i am getting sine wave at no-load when i put load the shape of sine wave changing to square wave i dont know what happening.At no load it is pure sine wave of harmonics 4% but with load as waveform is changing harmonics are increasing at full load harmonics are 27%.Full load is 160 watts as i have designed for 200VA UPS.


Here i am posting the code and wave forms please help me where in the code it is making square wave.

#include <pic.h>
#define kp 57
#define ki 32


int out_voltage=0,out_voltage_1=0,tim_per=0x80;
int ref_voltage=0; // ref volatge based on feedback
signed int x=0;
int xold=0;
long y=0;
long yold=0;
int duty_cycle=0;
long z=0,z1=0,proportional=0,integral=0;
unsigned char sine_table_count=0,count=0,adc_flag=1; // Index into the sinewave reference table
unsigned char Half_cycle_count=0,i=0; // Determines the halfcycle
unsigned int sine_value=0x00; // Sine table value
unsigned int d1;

bank1 unsigned int const sine_table[32]={39,77,114,151,186,219,250,279,305,328,347,364,377,386,392,394,392,386,
377,364,347,328,305,279,250,219,186,151,114,77,39,15};



void main(void)
{
/* setup stuff */
TRISA= 0x2F; // PORTA pins as input pins
TRISC = 0x00; // PORT C pins as output pins
PORTC=0x00;
TRISB=0xF2;
PORTB=0;
RB3=1;
ADIF=0; // clearing A/D interrupt flag
ADIE=1; // Enable A/D interrupt
ADCON0 = 0x91; //A/D setup. set pin7 (AN4) as Analog input for volatge feedbak
ADCON1 = 0xC0;
TMR0=62; //0x3D; //0x3D;//0x5B; // TMR0 setup
PSA=0;
PS2=0;
PS1=0; //0;
PS0=1; //1;
T0CS = 0; // Timer increments on instruction clock
T0IE = 1; // Enable interrupt on TMR0 overflow
PEIE=1;
GIE=1; // Global interrupt enable
GODONE = 1;
while(1) // Loop forever
{
}
}

static void interrupt isr(void) // Here be interrupt function - the name is unimportant.
{
if(ADIF)
{
ADIF=0;
out_voltage=0;
out_voltage = ADRESH<<8;
out_voltage=out_voltage+ADRESL;
ADCON0 = 0x91;
ADCON1 = 0xC0;
GODONE =1;
if(out_voltage==0)
out_voltage=500;

}

if(T0IF) // Clear interrupt flag, ready for next
{
T0IF = 0;
T0CS = 0; // set up timer0
TMR0=62; //0x3D; //0x5B;
PSA=0;
PS2=0;
PS1=0;
PS0=1;
ref_voltage= sine_table[sine_table_count];
if (Half_cycle_count)
ref_voltage=-ref_voltage;
sine_table_count++;
if(sine_table_count==32)
{
sine_table_count=0x00;
if(Half_cycle_count)
Half_cycle_count=0;
else
Half_cycle_count=1;
}
x =ref_voltage-out_voltage_1;
proportional=(kp*x)>>10;
integral+=ki*x;
y= (integral + proportional)>>6;
if(y>=0)
{
duty_cycle=y;
if(duty_cycle>1023)
duty_cycle=1023;
}
if(y<0)
{
duty_cycle=-y;
if(duty_cycle>1023)
duty_cycle=1023;
}
if(Half_cycle_count) // positive half cycle
{
CCPR2L = duty_cycle>>2;
CCP2CON = ((duty_cycle&&0x03)<<4)+0x0C;
CCP1CON = 0x00;
}
else // Negative half cycle
{
CCPR1L =duty_cycle>>2;
CCP1CON = ((duty_cycle&&0x03)<<4)+0x0C;
CCP2CON = 0x00;
}

}
}
 

Attachments

RolfRomeo

Joined Apr 27, 2009
19
I don't think the load should affect what's going on inside uC. More likely it has something to do with the surrounding hardware that can't quite cope with the load. Post your schematics and call in the EE's :)
 

Tahmid

Joined Jul 2, 2008
343
Hi,
Which Pic Micro controller have you used? What Modulating frequency you have used?
It seems that may be proper feedback is not utilized in your Code and that is why, with full load, harmonics increase and sine wave signals distorted.
 

rjenkins

Joined Nov 6, 2005
1,013
You are storing the ADC reading as out_voltage but comparing the sine ref to out_voltage_1, are you transferring the value somewhere else or is this a mistake?

Also, you appear to be comparing the two without regard for which half of the sine wave you are in? I believe you may need to invert the result (X) during the negative half.
 
Top