User manual

mikroPascal PRO for dsPIC30/33 and PIC24
MikroElektronika
434
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 (TRUE) do // endless loop
begin
if RB0_bit = 1 then // button on RB0 pressed
begin
Delay_ms(20);
Inc(current_duty); // increment current_duty
if (current_duty > pwm_period1) then // 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
end;
if RB1_bit = 1 then // button on RB1 pressed
begin
Delay_ms(20);
Dec(current_duty); // decrement current_duty
if (current_duty > pwm_period1) then // if we decrease current_duty greater
then possible pwm_period1 value (overow)
current_duty := pwm_period1; // set current_duty to max possible value
PWM_Set_Duty(current_duty, 1); // set newly acquired duty ratio
end;
if RB2_bit = 1 then // button on RB2 pressed
begin
Delay_ms(20);
Inc(current_duty1); // increment current_duty1
if (current_duty1 > pwm_period2) then // 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
end;
if RB3_bit = 1 then // button on RB3 pressed
begin
Delay_ms(20);
Dec(current_duty1); // decrement current_duty1
if (current_duty1 > pwm_period2) then // if we decrease current_duty1 greater
then possible pwm_period1 value (overow)
current_duty1 := pwm_period2; // set current_duty to max possible value
PWM_Set_Duty(current_duty1, 2);
end;
Delay_ms(5); // slow down change pace a little
end;
end.