15.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 a 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 15-40.
PWM Generator 1 is configured as a 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 15-44 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.
Three-Phase Sinusoidal PMSM/ACIM Motor Control Code
void PWMInitialization(void);
#include <xc.h>
#include <stdint.h>
int main(void)
{
PWMInitialization();
while (1)
{
}
}
void PWMInitialization(void)
{
PCLKCON = 0x0000;
//Set PWM master clock to 400MHz from PLL2 through CLKGEN5
configure_PLL2_Fout_400MHz();
clock_PWM_from_PLL2_Fout();
/* PWM Clock Divider Selection bits
0b11 = 1:16 ; 0b10 = 1:8 ;0b01 = 1:4 ; 0b00 = 1:2 */
PCLKCONbits.DIVSEL = 0;
/* PWM Master Clock Selection bits
0b01 = CLKGEN5 ; 0b00 = UPB clock */
PCLKCONbits.MCLKSEL = 1;
/* Lock bit: 0 = Write-protected registers and bits are unlocked */
PCLKCONbits.LOCK = 0;
/* Initialize Master Period Register */
MPER = 40000;
/* Set PWM Phase Register - No phase shift */
MPHASE = 0;
/* Set PWM Duty Cycles */
PG1DC = 10000;
PG2DC = 20000;
PG3DC = 30000;
/* Set Dead Time Registers */
PG1DT = 0x06400640;
PG2DT = 0x06400640;
PG3DT = 0x06400640;
PG1CON = 0x00000000;
/* Select PWM Generator Duty Cycle Register as PG1DC */
PG1CONbits.MDCSEL = 0;
/* Select PWM Generator Period Register as MPER */
PG1CONbits.MPERSEL = 1;
/* Select PWM Generator Phase Register as MPHASE */
PG1CONbits.MPHSEL = 1;
/* PWM Generator broadcasts software set of UPDREQ *
* control bit and EOC signal to other PWM generators. */
PG1CONbits.MSTEN = 1;
/* Start of Cycle is Local EOC */
PG1CONbits.SOCS = 0;
/* PWM Generator uses Master Clock selected by
the PCLKCONbits.MCLKSEL bits */
PG1CONbits.CLKSEL = 1;
/* PWM Generator operates in Center-Aligned mode*/
PG1CONbits.MODSEL = 4;
PG1IOCON1 = 0x00000000;
/* PWM Generator Output operates in Complementary Mode */
PG1IOCON1bits.PMOD = 0;
/* PWM Generator controls the PWMxH output pin */
PG1IOCON1bits.PENH = 1;
/* PWM Generator controls the PWMxL output pin */
PG1IOCON1bits.PENL = 1;
PG1EVT1 = 0x00000000;
/* Time base interrupts are disabled */
PG1EVT1bits.IEVTSEL = 3;
/* A write of the PGxDC register automatically sets the UPDREQ bit */
PG1EVT1bits.UPDTRG = 0;
/* PWM generator trigger output is EOC*/
PG1EVT1bits.PGTRGSEL = 0;
PG2CON = 0x00000000;
/* Select PWM Generator Duty Cycle Register as PG2DC */
PG2CONbits.MDCSEL = 0;
/* Select PWM Generator Period Register as MPER */
PG2CONbits.MPERSEL = 1;
/* Select PWM Generator Phase Register as MPHASE */
PG2CONbits.MPHSEL = 1;
/* Start of Cycle is PG1 trigger output selected by
PG1EVTbits.PGTRGSEL<2:0> bits */
PG2CONbits.SOCS = 1;
/* PWM Generator uses Master Clock selected by
the PCLKCONbits.MCLKSEL bits */
PG2CONbits.CLKSEL = 1;
/* PWM Generator operates in Center-Aligned mode */
PG2CONbits.MODSEL = 4;
PG2IOCON1 = 0x00000000;
/* PWM Generator output operates in Complementary Mode */
PG2IOCON1bits.PMOD = 0;
/* PWM Generator controls the PWMxH output pin */
PG2IOCON1bits.PENH = 1;
/* PWM Generator controls the PWMxL output pin */
PG2IOCON1bits.PENL = 1;
PG3CON = 0x00000000;
/* Select PWM Generator Duty Cycle Register as PG2DC */
PG3CONbits.MDCSEL = 0;
/* Select PWM Generator Period Register as MPER */
PG3CONbits.MPERSEL = 1;
/* Select PWM Generator Phase Register as MPHASE */
PG3CONbits.MPHSEL = 1;
/* Start of Cycle is PG1 trigger output selected by
PG1EVTbits.PGTRGSEL<2:0> bits */
PG3CONbits.SOCS = 1;
/* PWM Generator uses Master Clock selected by
the PCLKCONbits.MCLKSEL bits */
PG3CONbits.CLKSEL = 1;
/* PWM Generator operates in Center-Aligned mode */
PG3CONbits.MODSEL = 4;
PG3IOCON1 = 0x00000000;
/* PWM Generator output operates in Complementary Mode */
PG3IOCON1bits.PMOD = 0;
/* PWM Generator controls the PWMxH output pin */
PG3IOCON1bits.PENH = 1;
/* PWM Generator controls the PWMxL output pin */
PG3IOCON1bits.PENL = 1;
/* Turning ON the PWM Generator 3 */
PG3CONbits.ON = 1;
/* Turning ON the PWM Generator 2 */
PG2CONbits.ON = 1;
/* Turning ON the PWM Generator 1;
Thus starting all the PWM modules in unison */
PG1CONbits.ON = 1;
}