void duty(unsigned int adcvaule) { if(adcvaule<1023) //total 10bit data { //adc 10bit conver back*duty formula duty cycle //adc converter Vin=ADdata*(Vref+ - Vref-)/1023(2^10 bits) adcvaule=(((float)adcvaule)/1023)*(4*(PR2+1)); //duty cycle * 4*pr2+1 // adcvaule = ((float)adcvaule/1023)*(_XTAL_FREQ/(PWM_freq*1)); //CCP1 select FMT0 H 2bit L 8bit // duty reg is CCPR1H CCPR1L //define CCPW is total CPPR1H<1:0>+CCPR1L<7:0> sum of the 10 bits reg // CCPR1H<1:0> is using CCPW <9:8> bits // CCPR1L<7:0> is using CCPW <7:0> bits CCPR1H =(adcvaule>>8);// put duty first data still at 0 & 1 need to put at 8&9 CCPR1L = (adcvaule & ADRESL); //CCPR1L has 8 bit use or left it and leave the last over 2bit