[SOLVED] PIC16F877a HITECH C read ADRESL

Status
Not open for further replies.

ChrilDoggy

Newbie level 2
Joined
Dec 31, 2015
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
17
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 = ADRESLbits.7; wrong according to compiler
    CCP1Y = ADRESLbits.6; wrong according to compiler
    duty = duty;
    CCPR1L = duty;


Any help is appreciated :-D
 


Try the way I corrected your code.
Code:
    CCP1X = ADRESL >> 6;
    CCP1Y = ADRESL >> 7;
 
Last edited:

Thanks, it works perfectly now
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…