User Manual
Version 1.1
2011-07-15
deRFnode and deRFgateway
dresden elektronik
ingenieurtechnik gmbh
Enno-Heidebroek-Str. 12
12 7 Dr
n
rm  n
Tel.: +49 351 31 85 00
Fax: +49 351 3 18 50 10
wireless@dresden-elektronik.de
www. r
n- l k r nik.
Page 45 of 56
9.4.4. Measuring the battery voltage
The VBAT signal may be used to monitor the current battery voltage using the MCUs internal
A/D-converter. This requires a reference voltage. On ARM MCUs it must be provided exter-
nally on Pin3 which is available on the X8-Header at Pin 32. It is suggested to shortcut it to
VCC which is available on the same Header on Pins 2 and 33. Basically AVR MCUs can
handle external reference voltages too but we recommend using the internal reference volt-
age since it avoids additional external shortcut connections and enables a more precise
measurement. However in both cases during measurement, the GPIO-Pin 34 (e.g. on X8-
Header Pin 15) must not be used otherwise.
The measurement process includes:
(1) Initialization of the ADC,
(2) activation of the required ADC channel (0),
(3) perform the measurement,
(4) shut down the ADC.
For ARM MCUs, in peripherals/adc/adc.c the required library functions are to be
found and their invocation sequence may look like:
#define BOARD_ADC_FREQ 300000 // ADC Frequency
#define ADC_STARTUP_TIME_MAX 20 // returning from Idle mode (?/SPAN>s)
#define ADC_TRACK_HOLD_TIME_MIN 600 // Track&hold Acquisition Time (ns)
unsigned int adc_out, V_bat;
const Pin pin = {1<<27, AT91C_BASE_PIOB, AT91C_ID_PIOB, PIO_INPUT,
PIO_DEFAULT};
PIO_Configure(pin, 1);
ADC_Initialize( AT91C_BASE_ADC,
AT91C_ID_ADC,
AT91C_ADC_TRGEN_DIS,
0,
AT91C_ADC_SLEEP_NORMAL_MODE,
AT91C_ADC_LOWRES_10_BIT,
BOARD_MCK,
BOARD_ADC_FREQ,
ADC_STARTUP_TIME_MAX,
2*ADC_TRACK_HOLD_TIME_MIN);
ADC_EnableChannel(AT91C_BASE_ADC, ADC_CHANNEL_0);
ADC_StartConversion(AT91C_BASE_ADC);
// wait for conversion termination
while (!ADC_IsChannelInterruptStatusSet( ADC_GetStatus(AT91C_BASE_ADC),
ADC_CHANNEL_0)) ;
// perform measurement
adc_out = ADC_GetConvertedData(AT91C_BASE_ADC, ADC_CHANNEL_0);
// convert the measured value to real voltage (mV)
// voltage divider <-> V_bat = 4.73*V_meas
// max. resolution 10bit, V_ref=3.3V <-> V_ref/0x3FF = V_meas/adc_out
// <-> V_bat = 15.24*adc_out ~ (61*V_meas)/4
V_bat = (61*meas)/4;
// deactivate the ADC for power saving
ADC_DisableChannel(AT91C_BASE_ADC, ADC_CHANNEL_0);