Mikroelektronika MIKROE-738 Datenbogen

Seite von 682
404
mikoC PRO for PIC32
MikroElektronika
 
 if (RB2_bit) {                           
// button on RB2 pressed
      Delay_ms(
1
);
      current_duty1 = current_duty1 + 
5
;     
// increment current_duty
      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(
1
);
      current_duty1 = current_duty1 - 
5
;     
// decrement current_duty
      if (current_duty1 > pwm_period2) {     
// if we decrease current_duty1 greater then 
possible pwm_period1 value (overflow)
        current_duty1 = pwm_period2;       
  // set current_duty to max possible value
      }
      PWM_Set_Duty(current_duty1,  
2
);
     }
    Delay_ms(
1
);                             
// slow down change pace a little
  }
}
HW Connection
PWM demonstration