Author Topic: dsPIC MCPWM period skipping  (Read 1825 times)

0 Members and 1 Guest are viewing this topic.

Offline NiHaoMikeTopic starter

  • Super Contributor
  • ***
  • Posts: 9375
  • Country: us
  • "Don't turn it on - Take it apart!"
    • Facebook Page
dsPIC MCPWM period skipping
« on: June 09, 2014, 02:49:57 am »
I'm working on an inverter with a dsPIC controller. I have the sine wave generation code running well, but now I want to add period skipping at particularly high or low duty cycles in order to improve efficiency. For those who don't specialize in power electronics, period skipping is a trick that involves alternating between periods of full on or full off and periods where the on time or off time is doubled, effectively halving the switching frequency.

Here's (part of) the code:
Code: [Select]
unsigned int pwm;
//code to calculate initial PWM value
if(pwm>600) {
     if(PWMtick&0x1) { //PWMtick is a variable that increments every PWM period
          pwm=(pwm<<1)-801; //this doesn't seem to work
          if(pwm>775)
               pwm=801; //801 commands 100% duty cycle
     }
     else
          pwm=801;
}
else if(pwm<200) {
     if(PWMtick&0x1) {
          pwm=pwm<<1; //but this does!
          if(pwm<25)
               pwm=0;
     }
     else
          pwm=0;
}
The result is that at low duty cycles, it does indeed skip periods as intended. But at high duty cycles, it just abruptly switches to full on. The code for the high and low duty cycles are identical except for some comparison constants and the PWM value calculation. Is there something peculiar about the dsPIC and/or the XC16 compiler that causes that calculation to fail?
Cryptocurrency has taught me to love math and at the same time be baffled by it.

Cryptocurrency lesson 0: Altcoins and Bitcoin are not the same thing.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf