int i = 0; float j =0; float ADC_Value; void main() { TRISA = 0XFF; // PORTA is input PORTA = 0X00; // Clear PORTA ADC_Init(); // Initialize ADC module PWM1_Init(1000); // Initialize PWM1 at 1KHz PWM1_Start(); // Start PWM1 while(1){ // Endless loop ADC_Value = ADC_Read(0); ADC_Value = ADC_Value * 4.89; ADC_Value = ADC_Value /1000; i = ADC_Value * 20 ; j = (i*255)/100; // calculate the duty cycle for Pusle Width Modulation //duty cycle = (percent of duty cycle*255)/100; PWM1_Set_Duty(j); } }