CalibAdc10, where does this figure come from?

The bear

Senior Member
Hi Everyone,
CalibAdc10, where does this figure come from?
The figure in question is 10475 from a snippet/answer of Hippys (25.05.2012)

#Picaxe o8M2
#Terminal 4800

Disablebod
Do
CalibAdc10 w7

W7 = 10475 / w7

BinToAscii w7, b1,b2,b3,b4,b5
SerTxd (b4,".",b5,"V",CR,LF )
Pause 1000
Loop

Does it relate to CalibAdc10 (08M2) 1023, or Vref of 1.024

Regards, Bear..
 

marks

Senior Member
The Bear,
yes correct 1023 x 1.024 = 1047.552
multiplying this by 10 gives us a decimal result (10475)

Code:
[color=Black]picaxe 18m2    [/color][color=Green]'version 2.A * marks                               [/color]
[color=Navy]#terminal 4800[/color]

[color=Green]'  VoltageReference.
'  0.6V     20M, 28X1, 40X1
'  1.2V     28X2-3V, 28X2-3V
'  1.024V   All other parts that support this command
'Note that this command is not available on 28X2-5V/40X2-5V[/color]

[color=Blue]SYMBOL [/color][color=Black]ADCvalue      [/color][color=DarkCyan]= [/color][color=Purple]W1[/color]
[color=Blue]SYMBOL [/color][color=Black]Vsupply       [/color][color=DarkCyan]= [/color][color=Purple]b4[/color]
[color=Blue]SYMBOL [/color][color=Black]D1            [/color][color=DarkCyan]= [/color][color=Purple]b5[/color]
[color=Blue]SYMBOL [/color][color=Black]D2            [/color][color=DarkCyan]= [/color][color=Purple]b6[/color]

[color=Black]Main:[/color]

[color=Blue]CALIBADC10 [/color][color=Black]ADCvalue          [/color][color=Green]'(ADCvalue  = VoltageReference * 1023 / Vsupply )[/color]

[color=Black]Vsupply [/color][color=DarkCyan]= [/color][color=Navy]10475 [/color][color=DarkCyan]/ [/color][color=Black]ADCvalue   [/color][color=Green]'(Vsupply   = VoltageReference * 1023 / ADCvalue)[/color]


[color=Blue]BinToAscii [/color][color=Black]Vsupply,D2,D2,D1[/color]
[color=Blue]sertxd (CR[/color][color=Black], [/color][color=Blue]LF[/color][color=Black],D2,[/color][color=Red]"."[/color][color=Black],D1,[/color][color=Red]"v" [/color][color=Black],[/color][color=Blue]CR[/color][color=Black], [/color][color=Blue]LF)[/color][color=Green]'display eg 5.0v[/color]

[color=Blue]pause [/color][color=Navy]1000[/color]
[color=Blue]GOTO [/color][color=Black]Main[/color]
 

AllyCat

Senior Member
Hi,

CALIBADC{10} measures the "fractional" part (of 256 or 1024) that the FVR (Fixed Voltage Reference, nominally 1.024 volts) is of the "Full-Scale" value set by the supply rail (Vdd). So to calculate the supply rail voltage, it's necessary to divide the CALIBADC{10} value into the product of the full-scale value of 256 {or 1024} and the (FVR) reference voltage in the units of the required result.

Typically, the voltage is calculated in "decivolts" (tenths of a volt) so the FVR = 10.24 needs to be multipled by 1024 (if CALIBADC10). PICaxe Basic can't handle the 10.24 accurately, so you need to pre-calculate 10.24 * 1024 to give 10486.

I see that marks and hippy have assumed a "fullscale" of 1023 to give 10475, but I think 1024 is theoretically correct. However, the 1.024 volts is only a nominal value, so the actual "constant" really should be calibrated for your specific PICaxe device.

Incidentally, I'm preparing some "improved" (higher resolution) CALIBADC subroutines for the code snippetts section. I'll probably post a note here when they're finished. ;)

Cheers, Alan.
 
Last edited:

hippy

Technical Support
Staff member
There's also an explanation in the online CALIBADC10 command page -

http://www.picaxe.com/BASIC-Commands/Advanced-PICAXE-Configuration/calibadc10

Calibadc10 will give a result (Nref) which will depend on the reference voltage (Vref) and the PICAXE power supply vltage (Vpsu) as follows -

Nref = Vref * 1023 / Vpsu

This can be rearranged to determine the power supply voltage (Vpsu) from the calibadc10 result (Nref) -

Vpsu = Vref * 1023 / Nref

If the Vref were 1.024 volts then this will be -

Vpsu = 1.024 * 1023 / Nref

Vpsu = 1047.552 / Nref

Rounded to the nearest whole number -

Vpsu = 1048 / Nref
Using 10475 rather than 1048 gives the result in units of tenths of a volt rather than volts.

Technically that 10475 ought to be 10476 when rounded but doubt it makes much of a difference.
 

hippy

Technical Support
Staff member
I see that marks and hippy have assumed a "fullscale" of 1023 to give 10475, but I think 1024 is theoretically correct.
Possibly but the real issue is expecting a specific value to be determined when the ADC can only say which range of values the input falls in. Put 5V in and people expect to see "5V", not something less, which they will instinctively feel is wrong even if it isn't.

IMO it's easier to give someone the "5V" they expect than try to explain how "4.9V" is right and does show that 5V is being put in.
 

AllyCat

Senior Member
Hi,

Hmm, I was wondering whether to "argue the toss" on 1023 versus 1024, even though of course in practice the difference will be "lost in the noise" with variations of the exact reference voltage and comparator offset voltages, etc.. But actually isn't my 10486 (derived from 1024) more likely to give "5 volts" than "4.9 volts", compared with using 10475 (derived from 1023)? ;)

Is there a Microchip AN on the A-D converter? The only information I have found is the following graph from the Microchip base data sheet. Note that the top (unlabled) dotted line (where the diagonal line terminates) is $400 (1024) and the last "transition" occurs 1.5*LSB before the reference level. Also, the text refers to "1024 steps" which implies 1025 voltage levels (i.e. zero to 1024). However, I will concede that Microchip appear to have got the lower end of the graph "wrong", probably because they have mis-scaled the "0.5*LSB" as 1*LSB wide, and then had to terminate the diagonal line incorrectly (not at the origin/negative reference as expected).

A-D_Converter.png

I think a parallel of this is the D-A converter which generates 32 levels from zero up to a maximum level of Reference*31/32. To get the full Reference voltage (i.e "Level 32") it's necessary to disconnect the lower end of the divider chain by enabling the "Low Power" flag.

Cheers, Alan.
 

hippy

Technical Support
Staff member
I don't know if there is a detailed Application Note on ADC and I will admit the datasheet intricacies are beyond me - or rather I never put full effort into fully understanding them !

You could well be right that there is a better number to use which will show "5V" when it is 5V. On top of all the other inaccuracies it's also quite likely that a 5V regulator won't be putting out exactly 5V anyway. There are likely going to be other inaccuracies which creep in when using any measured result in calculations so it all gets a bit fuzzy as to what a best answer would be.
 
Top