In pic16f877a 10bit adc is there. I have configured CCP module for PWM operation. I am facing the problem that
CCPRL is 8bit register and adc result is 10bit and it is in two registers ADRESH and ADRESL. I have taken it in single variable by using following method-
adcval=(ADRESH<<8)|ADRESL;
but now problem is that how to load this 10 bit value in 8-bit CCPRL register as a new timebase?.
please help..
this code is running very good for pic16f72(8 bit adc).
The pwm also has ten bit resolution.
Quote from data sheet:
The PWM duty cycle is specified by writing to the
CCPR1L register and to the CCP1CON<5:4> bits. Up
to 10-bit resolution is available. The CCPR1L contains
the eight MSbs and the CCP1CON<5:4> contains the
two LSbs. This 10-bit value is represented by
CCPR1L:CCP1CON<5:4>.
Code:
/*--- Set Duty Cycle ---*/
void set_duty_cycle(unsigned int dc)
{
unsigned char lsb;
if(dc > MAXDUTY){
dc = MAXDUTY;
}
lsb = dc & 0x0003;
CCP1CON &= 0xcf;
CCP1CON |= (lsb << 4);
CCPR1L = (dc >> 2);
}