hi , i want to convert output of 10-bit adc to speciaifc 8-bit adc with highly accuracy....
actually my sensor output is varing from 0-24v so i used potenteometer to limit it from 0-5v now i gave it as input of adc and now i want its result into 8bit adc?
how can i do it?
if i further more decrease my sensor input from 0-2.5v or similar so can my output is 8-bit?
What is the reference voltage to your ADC? If it is 5V, then, with a signal level of between 0V to 5V, you'll get a 10-bit result. With signal level between 0V to 2.5V, you'll get 9-bit result. And, with signal level between 0V to 1.25V, you'll get 8-bit result. Actually, in each case the result is 10-bit, but the signal level is such that the peak value for the corresponding lower resolution is not crossed and can be assumed to be of that resolution.
If your reference voltage is 5V, then you can carry out the reading and discard the lower 2 bits in software to obtain 8-bit result. You can also set justification to left justification and read the "high" result register to obtain 8-bit result.
Code:
ADC_Init(); //Initialize ADC
ADVar = ADC_Get_Sample(0); //Get ADC reading from channel 0
ADVar = ADVar >> 2; //Turn into 8-bit result
All you need to do is to select a 5v reference voltage for the ADC. Also configure it for left adjusted. After the conversion is complete, the 8 bit result can be directly read from the ADC High byte register.
To make it more accurate, you can try rounding this 8-bit value. Just add bit-1 of the 10 bit result to the 8 bit value.
Decreasing your input will not make any difference to the number of bits. You will in fact lose some resolution.