PIC18F4420 10bit A/D result to 7bit

Thread Starter

thejmh

Joined Jul 3, 2009
12
Hi! I have a 10K pot used as voltage divider into AN2 and I want to use it to adjust the result value between 0-127. I can get the 10bit result, but how can I convert the 10bit result to 7bit so that I can use the whole range of pot?

Also how can I calibrate the A/D output to be always 0-127? I measured my pot and the max value it gives to AN2 is 4.97Volts, so i miss some bits. I'd like to have a calibration routine that can measure max and min values of the pot and then always adjust the output to be 0-127, no matter what pot is used. Is this possible?
 

n9352527

Joined Oct 14, 2005
1,198
Hmm. The easiest way is to shift the 3 LS bits off.

You might not need to calibrate it. Your supply might be only 4.97V, so that's what the maximum the pot can output. And if you convert with Vdd as Vref+ and Vss as Vref-, that is converted into full value. Anyway, with 7 bits the step is 5/128 = 0.03906V, not significant enough to warrant a calibration for full value.
 

Thread Starter

thejmh

Joined Jul 3, 2009
12
I got the 7bit result and that part is ok now.

I'm using A/D to control midi. I would like to be able to use higher value pots, like some guitar volume or expression pedals with 250k or 500k pot. The max recommended impedance for analog sources is 2.5k, so what kind of external circuit is needed to match the input impedance?
 
Top