17.5.2 Three-Phase Sinusoidal Control of PMSM/ACIM Motors

Three-phase sinusoidal control applies voltages to the three-phase motor windings, which are Pulse-Width Modulated to produce sinusoidal currents as the motor spins. This eliminates the torque ripple and commutation spikes associated with trapezoidal commutation. Typically, Center-Aligned Complementary PWMs are used for sinusoidal control of a Permanent Magnet Synchronous Motor (PMSM) or three-phase AC Induction Motor (ACIM). Center-aligned PWM signals reduce the level of harmonics in output voltages and currents as compared to edge-aligned PWMs. Three PWM Generators are connected to the three-phase power bridge driving the motor, as shown in Figure 17-39.

PWM Generator 1 is configured as host, and PWM Generator 2 and PWM Generator 3 are configured as client PWMs. PWM configuration used in three-phase sinusoidal control is summarized below:

  • PG1-PG3: Uses master period and independent duty cycles
  • PG1-PG3: PWM Operating mode is selected as Center-Aligned mode
  • PG1-PG3: Configured to operate in Single Trigger mode
  • PG1-PG3: PWM Output mode is configured as Complementary Output mode
  • PG2-PG3: Uses PG1 trigger output as Start-of-Cycle, whereas PG1 is self-triggered
  • PG2-PG3: Enabled during initialization
  • PG1 is enabled only after configuring all the control registers; whenever PG1 is enabled, all the generators will start in unison

Figure 17-43 shows the PWM waveforms for a given point in time. Center-Aligned mode uses two timer cycles to produce a PWM cycle and maintains symmetry at the center of each PWM cycle. Each timer cycle can be tracked using the status bit, CAHALF (PGxSTAT[1]), of the respective PWM Generator. The leading edge is produced when CAHALF = 0 and the falling edge is produced when CAHALF = 1. Note that with Center-Aligned mode, as long as the duty cycles are different for each phase, the switching instants occur at different times. (In Edge-Aligned mode, the turn-on times are coincident.) This generally reduces electromagnetic interference.

Figure 17-43. Three-Phase Center-Aligned Waveforms

Three-Phase Sinusoidal PMSM/ACIM Motor Control Code

void PWMInitialization(void);

int main() {
    
    PWMInitialization();
    
    while(1) {
        //Anything to do here?
    }
    
    return 0;
}

void PWMInitialization(void) {
    
    //Set PWM master clock to 400MHz from PLL2 through CLKGEN5
    configure_PLL2_Fout_400MHz();
    clock_PWM_from_PLL2_Fout();
    
    //Set PWM Master Phase Register - No phase shift
    MPHASE = 0;
    
    //Set PWM Period (frequency 100kHz, given a 400MHz PWM master clock)
    //Note that center-aligned mode takes 2 timer cycles to produce 1 PWM cycle.
    MPER = (2000 << 4); //Time units are 1/16 of PWM period
    
    //Set PWM Duty Cycles
    PG1DC = (500 << 4); //25%
    PG2DC = (1000 << 4); //50%
    PG3DC = (1500 << 4); //75%
    
    //Ensure PWM Generators 1-3 are disabled before initializing
    PG1CONbits.ON = 0;
    PG2CONbits.ON = 0;
    PG3CONbits.ON = 0;
    
    //Set Dead Time Registers
    PG1DTbits.DTL = (200 << 4);    //200 PWM clocks of dead time on PWM1L
    PG1DTbits.DTH = (200 << 4);    //200 PWM clocks of dead time on PWM1H
    PG2DTbits.DTL = (200 << 4);    //200 PWM clocks of dead time on PWM2L
    PG2DTbits.DTH = (200 << 4);    //200 PWM clocks of dead time on PWM2H
    PG3DTbits.DTL = (200 << 4);    //200 PWM clocks of dead time on PWM3L
    PG3DTbits.DTH = (200 << 4);    //200 PWM clocks of dead time on PWM3H

    
    PG1CONbits.MDCSEL = 0;         //Select PG1DC as PWM Generator 1's duty cycle register  
    PG1CONbits.MPERSEL = 1;        //Select MPER as PWM Generator 1's period register
    PG1CONbits.MPHSEL = 1;         //Select MPHASE as PWM Generator 1's phase register
    PG1CONbits.MSTEN = 1;          //PWM Generator 1 broadcasts software set of UPDREQ control bit and EOC signal to other PWM generators.  
    PG1CONbits.UPDMOD = 0b000;     //PWM Buffer Update Mode is at start of next PWM cycle if UPDREQ = 1
    
    PG1CONbits.TRGMOD = 0b00;      //PWM generator 1 operates in Single Trigger Mode 

    PG1CONbits.CLKSEL = 1;         //PWM Generator 1 uses PWM Master Clock, undivided and unscaled
    PG1CONbits.MODSEL = 0b100;     //PWM Generator 1 operates in Center-Aligned mode
    PG1CONbits.SOCS = 0b0000;      //Start of Cycle is Local EOC
    
    PG1IOCONbits.PMOD = 0b00;      //PWM Generator 1 Output operates in Complementary Mode
    PG1IOCONbits.PENH = 1;         //PWM Generator 1 controls the PWM1H output pin
    PG1IOCONbits.PENL = 1;         //PWM Generator 1 controls the PWM1L output pin
    
    
    PG1EVTbits.ADTR1EN1 = 1;       //PGxTRIGA register compare event is enabled as trigger source for ADC Trigger 1
    PG1EVTbits.UPDTRG = 0b01;      //A write of the PGxDC register automatically sets the UPDREQ bit
    PG1EVTbits.PGTRGSEL = 0b000;   //PWM generator trigger output is EOC

    
    PG2CONbits.MDCSEL = 0;         //Select PG2DC as PWM Generator 2's duty cycle register
    PG2CONbits.MPERSEL = 1;        //Select MPER as PWM Generator 2's period register
    PG2CONbits.MPHSEL = 1;         //Select MPHASE as PWM Generator 2's phase register
    PG2CONbits.MSTEN = 0;          //PWM generator 2 does not broadcast UPDATE status bit or EOC signal to other PWM generators
    PG2CONbits.UPDMOD = 0b011;     //PWM Buffer Update Mode is client immediate
    PG2CONbits.TRGMOD = 0b00;      //PWM generator 2 operates in Single Trigger Mode
    PG2CONbits.SOCS = 0b0001;      //Start of Cycle is PG1 trigger output selected by PG1EVTbits.PGTRGSEL<2:0> bits
    
    
    PG2CONbits.CLKSEL = 1;         //PWM Generator 2 uses PWM Master Clock, undivided and unscaled
    PG2CONbits.MODSEL = 0b100;     //PWM Generator 2 operates in Center-Aligned mode
    
    
    PG2IOCONbits.PMOD = 0b00;      //PWM Generator 2 output operates in Complementary Mode
    PG2IOCONbits.PENH = 1;         //PWM Generator 2 controls the PWM2H output pin
    PG2IOCONbits.PENL = 1;         //PWM Generator 2 controls the PWM2L output pin
    
    
    PG3CONbits.MDCSEL = 0;         //Select PG3DC as PWM Generator 3's duty cycle register
    PG3CONbits.MPERSEL = 1;        //Select MPER as PWM Generator 3's period register
    PG3CONbits.MPHSEL = 1;         //Select MPHASE as PWM Generator 3's phase register
    PG3CONbits.MSTEN = 0;          //PWM generator 3 does not broadcast UPDATE status bit or EOC signal to other PWM generators

    PG3CONbits.UPDMOD = 0b011;     //PWM Buffer Update Mode is client immediate
    PG3CONbits.TRGMOD = 0b00;      //PWM generator 3 operates in Single Trigger Mode
    PG3CONbits.SOCS = 0b0001;      //Start of Cycle is PG1 trigger output selected by PG1EVTbits.PGTRGSEL<2:0> bits
    

    PG3CONbits.CLKSEL = 1;         //PWM Generator 3 uses PWM Master Clock, undivided and unscaled
    PG3CONbits.MODSEL = 0b100;     //PWM Generator operates in Center-Aligned mode
    
    PG3IOCONbits.PMOD = 0b00;      //PWM Generator 3 output operates in Complementary Mode
    PG3IOCONbits.PENH = 1;         //PWM Generator 3 controls the PWM3H output pin
    PG3IOCONbits.PENL = 1;         //PWM Generator 3 controls the PWM3L output pin
    
    
    //Enable all PWM generators; PWM generator 1 will start the sequence