CALIBADC10 wordvariable CALIBADC variable
Variable - receives the adc reading.
Calibrate the microcontrollers internal ADC by measuring a fixed internal fixed voltage reference.
||20M, 28X1, 40X1
||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 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 voltage (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
This will give the voltage in 1V units.
To obtain a voltage in millivolts (mV) -
Vpsu = 1.024 * 1023 * 1000
Vpsu = 1047552 / Nref
Which, accounting for PICAXE numerical constraints -
Vpsu = 52378 / Nref * 20