I have problems reading ADC value, I have left justified result and need to read the bit 7 & 6 from ADRESL and save the value into CCP1X and CCP1Y to control the lowest bits of my PWM duty cycle.
I have searched in my header file, but cannot find there how I can read the bits from ADRESL, I have been looking in my compiler manual aswell without finding any advice on how to read a single bit from a register. The circuit works now, but it never has a really 100% duty cycle or 0% percent duty cycle depending on if CCP1X and CCP1Y are set.
Code:
void run(){
init();
CCPR1L = 0x00;
while(1){
unsigned int adres;
adres = getad();
set_pwmduty(adres);
}
}
int getad(){
unsigned int adc_result;
__delay_ms(20);
ADGO = 1;
while(ADGO) continue;
adc_result = ADRESH;
adc_result = ADRESH;
return(adc_result);
}
void set_pwmduty(int duty){
CCP1X = ADRESL >> 6;
CCP1Y = ADRESL >> 7;
duty = duty;
CCPR1L = duty;
Any help is appreciated :-D