Richard Prosser wrote: > On 21/08/07, Jinx wrote: >> I was trying to decide which reference voltage to use for a project >> and had one of those 'moments'. I need a reality check please >> >> PICs are said in their manuals to have 1024 steps, but 0 to 0x3ff >> is 1023 steps. There are 1024 digital output values, including 0 >> >> So, if you have a 4.096V Vref, that actually equates to, according >> to me, 4.0039mV per step, not a tidy 4.0000mV. And with 5.120V >> Vref it's 5.0049mV per step, not 5.0000mV >> >> Have I overlooked that for all these years ? I'm not sure it will have >> too great an effect on most A/D useage, but wonder if (assuming I'm >> correct) anyone compensates at all for it, eg with an adjusted Vref >> >> Or am I still in the 'moment' ? > 0 to 0x3FF is 1023 steps - but 1024 levels. > > And it's the voltage level you're measuring. > > I think. Let's have our moment together :) Basically it depends on the transfer function of the ADC. There are several possibilities. Microchip is not really very forthcoming with this, but in the Midrange Manual there is one, which goes like this: Vin < 1 Lsb: ADCOut=0 Vin < 2 Lsb: ADCOut=1 . . . Vin < 1023 Lsb: ADCOut=1022 Vin < 1024 Lsb: ADCOut=1023 Where 1 Lsb = Vref/1024 So if you were to take the average input for e.g. ADCOut=0 as 0.5 Lsb (the center of the interval covered by ADCOut=0), you'd get Vin = (Out + 0.5) * Vref/1024 There are other transfer functions that yield other results. Gerhard -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist