swapan
Full Member level 4

Hi guys,
I am trying to implement PWM MC of dsPIC30F2010. PWM1L and PWM1H has been used in complementary mode. 2 LEDs (Green and Red) has been connected to PWM1L (Red) and PWM1H (Green) respectively. Please see my code. on powering up, intensity of the Red LED reduces gradually whereas the same of Green LED increases gradually simultaneously. Then the Green LED (PWM1H) remains in full glow instead of reversing the process as desired in code.
I am trying to implement PWM MC of dsPIC30F2010. PWM1L and PWM1H has been used in complementary mode. 2 LEDs (Green and Red) has been connected to PWM1L (Red) and PWM1H (Green) respectively. Please see my code. on powering up, intensity of the Red LED reduces gradually whereas the same of Green LED increases gradually simultaneously. Then the Green LED (PWM1H) remains in full glow instead of reversing the process as desired in code.
C:
unsigned int duty;
void main() {
TRISD = 0x0;
duty = 0;
PWM1_MC_Init(5000, 0, 0x11, 0);
PWM1_MC_Set_Duty(duty, 1);
PWM1_MC_Start();
do {
do {
duty++;
PWM1_MC_Set_Duty(duty, 1);
delay_ms(1);
} while (duty < 32767);
do {
duty--;
PWM1_MC_Set_Duty(duty, 1);
delay_ms(1);
} while (duty > 0);
} while (1);
}