17.5.3 Simple Complementary PWM Output
This complementary PWM example uses a single PWM Generator and can be used for half-bridge applications. The PWM is configured as follows:
- Independent Edge PWM mode
- Complementary Output mode
- Self-Triggered mode
Figure 17-44 shows the timing relations of the PWM signals. In this example, continuous triggering (local EOC) is used in addition to a phase offset (PG1PHASE). Dead time is implemented to prevent simultaneous switch conduction.
Complementary PWM Output Mode
void PWMInitialization(void);
int main() {
PWMInitialization();
while(1);
return 0;
}
void PWMInitialization(void) {
//clock_PWM_at_400MHz_from_PLL2_Fout();
clock_PWM_from_UPB_clock();
//PWM Generator 1 uses PG1DC, PG1PER, PG1PHASE registers
PG1CONbits.MDCSEL = 0;
PG1CONbits.MPERSEL = 0;
PG1CONbits.MPHSEL = 0;
PG1CONbits.CLKSEL = 1; //PWM Generator 1 uses PWM Master Clock, undivided and unscaled
PG1CONbits.MODSEL = 0b000; //Independent edge triggered mode
PG1CONbits.TRGMOD = 0b00; //PWM Generator 1 operates in Single Trigger mode
PG1CONbits.SOCS = 0b0000; //Start of cycle (SOC) = local EOC
PG1IOCONbits.PMOD = 0b00; //PWM Generator 1 outputs operate in Complementary mode
//PWM Generator controls the PWM1H and PWM1L output pins
PG1IOCONbits.PENH = 1;
PG1IOCONbits.PENL = 1;
//PWM1H and PWM1L output pins are active high
PG1IOCONbits.POLH = 0;
PG1IOCONbits.POLL = 0;
//Given the 400MHz input clock from CLKGEN5, this period will result in 100kHz PWM frequency
PG1PER = (4000 << 4); //Time base units are 1/16 of a PWM clock
PG1DC = (1000 << 4); //25% duty cycle
PG1PHASE = (400 << 4); //Rising edge has 400 PWM clocks of phase time
PG1DTbits.DTH = (80 << 4); //80 PWM clocks of dead time on PWM1H
PG1DTbits.DTL = (80 << 4); //80 PWM clocks of dead time on PWM1L
//Enable PWM Generator 1
PG1CONbits.ON = 1;
}