Write a program that will generate a PWM signal whose duty c
Solution
In this program two input switches are used to control the Duty cycle of PWM signal. S1 for increasing duty cycle and S2 for decreasing the same. Frequency of PWM signal is set to5KHz[cc lang=”C”]void main()
 {
 short duty1 = 16; // initial value for Duty cycle
TRISD = 0xFF; // Set PORTD as input
 TRISC = 0x00; // Set PORTC as output
PWM1_Init(5000); // Initialize PWM1 for 5Kh
 PWM1_Start(); // start PWM1
 PWM1_Set_Duty(duty1); // Set current duty for PWM1
while (1) // endless loop
 {
 if (PORTD.F0==0) //Checking the button pressed or not
 {
 Delay_ms(1);
 duty1++; // increment duty cycle
 PWM1_Set_Duty(duty1); //Change the duty cycle
 }
 if (PORTD.F1==0) // Checking the button pressed or not
 {
 Delay_ms(1);
 duty1–; // decrement duty cycle
 PWM1_Set_Duty(duty1);
 }
 Delay_ms(10);
 }
 }
 [/cc]

