Write a program that will generate a PWM signal whose duty c

Write a program that will generate a PWM signal whose duty cycle is controlled by the value in location $D000. The value of $00 represents zero percent duty cycle and the value SFF represents hundred percent duty cycle. Pick any convenient frequency. Before any convenient frequency. Before running the program, use memory modify to change the value in location $D000 to generate the required signal. Modify the above program so that it will monitor the analog voltage on PE5 and generate a PWM signal, so that the duty cycle is proportional to the voltage. The duty cycle should be zero percent if the input voltage is zero and hundred percent if the input voltage is 5 volts

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]

 Write a program that will generate a PWM signal whose duty cycle is controlled by the value in location $D000. The value of $00 represents zero percent duty cy

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site