CALIBADC variable

CALIBADC10 wordvariable

Variable - receives the adc reading


Calibrate the microcontrollers internal ADC by measuring a fixed internal fixed voltage reference.

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.

The reference voltage used by the PICAXE microcontrollers ADC reading (readadc/ readadc10) commands is the supply voltage. In the case of a battery powered system, this supply voltage can change over time (as the battery runs down), resulting in a varying ADC reading for the same voltage input.

The calibadc/calibadc10 commands can help overcome this issue by providing the ADC reading of a nominal internal reference. Therefore by periodically using the calibadc command you can mathematically calibrate/compensate the readadc command for changes in supply voltage.

calibadc can be considered as 'carry out a readadc on a fixed reference'.

Note that the reference voltage specified is a nominal voltage only and will vary with each part. Microchip datasheet AN1072 provides further details on how to software calibrate and use this advanced feature.

Theory of operation

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 * 255 / Vpsu

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

     Vpsu = Vref * 255 / Nref

If the Vref were 1.024 volts then this will be -

     Vpsu = 1.024 * 255 / Nref

     Vpsu = 261.12 / Nref

Rounded to the nearest whole number -

     Vpsu = 261 / Nref

Applies To:
All (except 08, 08M, 14M, 18, 18A, 18M, 18X, 28, 28A, 28X, 40X)
See Also:
Related Create:

Using 'calibadc'

This program reads the 8-bit 'calibadc' value into the byte variable 'b1' and then reports what that reading is.

Code Example:
main:	calibadc b1	; read the adc reading
	debug		; display current value
	pause 500	; wait a while
	goto main	; loop back to start
Copy Code Submit an Example

Submit Your Own Code!

You must be logged in to submit code examples. Login now.


  • Login to leave a comment.