Sine PWM

Thread Starter

FBorges22

Joined Sep 11, 2008
109
Greetings,

I am working in a project that I need to develop a SPWM Inverter for an induction motor or an UPS.

Few days ago, I started to develop a small program that uses a sine lookup table and the PWM peripheral to generate the SPWM pulses in the PWML1 and PWMH1 pins of an dsPIC33FJ32MC202.

The sine lookup table comparison are not yet implemented. I am currently using this code to just test the PWM pins of the dsPIC.

However, when I simulated my code in the Proteus ISIS nothing happens and unfortunately I am quite new to the dsPICs. Here is my current code.

Rich (BB code):
#include <p33FJ32MC202.h>

_FOSCSEL(FNOSC_FRCPLL)                // configures the fast oscillator with PLL
_FOSC(FCKSM_CSECMD & OSCIOFNC_ON)    // enables only clock switching and digital I/O
_FWDT(FWDTEN_OFF)                    // disables the watchdog timer
_FPOR(FPWRT_PWR1)                    // disables the power on reset 
_FICD(ICS_PGD2 & JTAGEN_OFF)        // disables the JTAG and the ICS

#define OC5_IO    22            // define OC5 output function number for PPS

unsigned char sine[42]={0,9,19,28,38,47,57,66,75,84,93,102,111,120,128,136,144,152,160,167,174,181,188,194,200,206,211,217,221,226,230,234,238,241,244,246,249,251,252,253,254,254};
unsigned char pwmFHtimes;    // PWM frequency hopping times, it is based on PWM cycle

void MCU_init(void)
{
    TRISB=0x00;                // PORT B as output
    RCONbits.SWDTEN=0;        // Disable Watch Dog Timer
    pwmFHtimes=0;
    OC1CONbits.OCM=0;         // Output compare channel is disabled
    OC1R= 0x0099;            // Initialize Compare Register1 with 50% duty cycle
    OC1RS= 0x0099;            // Initialize Secondary Compare Register1 with 50% duty cycle
    OC1CONbits.OCSIDL= 0;    // Output capture will continue to operate in CPU Idle mode
    OC1CONbits.OCFLT= 0;    // No PWM Fault condition has occurred (this bit is only used when OCM<2:0> = 111)
    OC1CONbits.OCTSEL= 0;    // Timer2 is the clock source for output Compare
    OC1CONbits.OCM= 0x6;    // PWM mode on OC, Fault pin disabled
    PR2= 0x0132;            // Initialize PR2 with 0x0132 = 0d306 as PWM cycle
    IFS0bits.T2IF=0;        // Clear Output Compare interrupt flag
    IEC0bits.T2IE=1;        // Enable Output Compare interrupts
    T2CONbits.TON=1;        // Start Timer2 with assumed settings
}

int main (void)
{
    while(1)
    {
        Idle();
    }
    return 0;
}

void __attribute__ ((__interrupt__, no_auto_psv)) _T2Interrupt(void)
{
    IFS0bits.T2IF = 0;
    
    if (++pwmFHtimes == 5) 
    {    
        // every 5 cycles for update
        pwmFHtimes = 0;
        // update the duty cycle for PWM
        if (OC1RS == 0x0099)
        {
            OC1RS = 0x00E5;    // 75% duty cycle
        }
        else
        {
            OC1RS = 0x0099;    // 50% duty cycle
        }
    }
}
Any ideas what is wrong, please? The PWMH1 and PWML2 pins should be pulsing...

Thanks,
FBorges22
 

shortbus

Joined Sep 30, 2009
10,045
If your going to use the inverter to run a motor. What your trying to do is usually done by comparing a sine wave with a triangle wave. the result is then used to switch a pair of mosfets or IGBT's, one for the positive going and one for the negative going current. It will only approximate a sine wave. This is done because the switching devices can't make a true sine wave and live.
 
Top