User manual
mikroC PRO for dsPIC
MikroElektronika
459
pwm_period1 = PWM_Init(5000 , 1, 1, 2);
pwm_period2 = PWM_Init(10000, 2, 1, 3);
PWM_Start(1);
PWM_Start(2);
PWM_Set_Duty(current_duty, 1); // Set current duty for PWM1
PWM_Set_Duty(current_duty1, 2); // Set current duty for PWM2
while (1) { // endless loop
if (RB0_bit) { // button on RB0 pressed
Delay_ms(20);
current_duty++; // increment current_duty
if (current_duty > pwm_period1) { // if we increase current_duty greater then
possible pwm_period1 value
current_duty = 0; // reset current_duty value to zero
}
PWM_Set_Duty(current_duty, 1); // set newly acquired duty ratio
}
if (RB1_bit) { // button on RB1 pressed
Delay_ms(20);
current_duty--; // decrement current_duty
if (current_duty > pwm_period1) { // if we decrease current_duty greater then
possible pwm_period1 value (overow)
current_duty = pwm_period1; // set current_duty to max possible value
}
PWM_Set_Duty(current_duty, 1); // set newly acquired duty ratio
}
if (RB2_bit) { // button on RB2 pressed
Delay_ms(20);
current_duty1++; // increment current_duty1
if (current_duty1 > pwm_period2) { // if we increase current_duty1 greater
then possible pwm_period2 value
current_duty1 = 0; // reset current_duty1 value to zero
}
PWM_Set_Duty(current_duty1, 2); // set newly acquired duty ratio
}
if (RB3_bit) { // button on RB3 pressed
Delay_ms(20);
current_duty1--; // decrement current_duty1
if (current_duty1 > pwm_period2) { // if we decrease current_duty1 greater then
possible pwm_period1 value (overow)
current_duty1 = pwm_period2; // set current_duty to max possible value
}
PWM_Set_Duty(current_duty1, 2);
}
Delay_ms(5); // slow down change pace a little
}
}