mamech
Full Member level 3
hello
I found a very strange and weird performance of custom made ADC function.
I used the following code:
what is really strange, is that this code works, but the limit of max conversion (when input equals reference) is not 1023, but it is a number less than 930 !! and and even sometimes in range of 600 or 700!!
this was strange enough , but what was more strange, is what was the source of the problem!
I found that the source of problem was shutting down the ADC module after conversion , using ADCON0bits.ADON = 0 !!
once I commented this line, the conversion became normal, and it reaches the limit of 1023 normally.
can anyone explains to me, what is the relation between shutting down the ADC module after conversion ends, and the weird number that I get from conversion??
I found a very strange and weird performance of custom made ADC function.
I used the following code:
Code:
int CustomADC_Read (unsigned char k) // needs to be modified to get inut from user
{
int Adc_Result=0; // the variable that we will use to put the result of conversion in it
ADCON0=0b10000000;
ADCON0 = ADCON0|k<<3;
ADCON1=0b10000000;
ADCON0bits.ADON = 1; // start A/D converter module is powered up so this means
ADCON0bits.GO_DONE = 1; //that if A/D Conversion Status bit When ADON = 1 ,
// then A/D conversion in progress (setting this bit starts the
// A/D conversion which is automatically cleared by hardware when the A/D conversion is complete)
while(ADCON0bits.GO_DONE); //this will make it looping until conversion to finish
ADCON0bits.ADON = 0; //switch off adc so it consumes no power
Adc_Result = (ADRESH<<8)|ADRESL; // shifting ADRESH 8 times so we can add it to ADRESL , an so we can get the result correctly
return Adc_Result;
}
what is really strange, is that this code works, but the limit of max conversion (when input equals reference) is not 1023, but it is a number less than 930 !! and and even sometimes in range of 600 or 700!!
this was strange enough , but what was more strange, is what was the source of the problem!
I found that the source of problem was shutting down the ADC module after conversion , using ADCON0bits.ADON = 0 !!
once I commented this line, the conversion became normal, and it reaches the limit of 1023 normally.
can anyone explains to me, what is the relation between shutting down the ADC module after conversion ends, and the weird number that I get from conversion??