C Language Development Kit/Functions/BatteryVoltage

From OptiWiki

Jump to: navigation, search
Description Returns the output voltage level of the battery pack.
unsigned int batteryvoltage(void);
Arguments None
Returns The output voltage level of the battery pack as an unsigned integer value between 0 and MAX_AD. A value of zero corresponds to 0 Volt. A value of MAX_AD corresponds to the operating voltage of the handheld terminal. The conversion between the return value of batteryvoltage() and the battery voltage is: battery voltage = (return value) * (operating voltage) / MAX_AD. MAX_AD and the operating voltage are hardware dependant and are shown below:
Terminal MAX_AD Operating voltage
OPH100x 1023 3.3 volt
DWT7133 255 5 volt
ALL PHL terminals 255 3.3 volt
OPL97xx 1023 3.0 volt
DCL153x 1023 3.0 volt
Remarks The relation between battery pack output voltage level and remaining battery capacity depends on the type of batteries, and on the charging and discharging history. It is difficult if not impossible to determine the remaining battery capacity from the battery voltage.

The batteryvoltage() function is not available on some models of the PHL1700. On the models that do not support batteryvoltage(), the value 0 is returned.

#include <stdio.h>
#include <stdlib.h>
#include "lib.h"
#define MAXBATTVOLT  330L
#define MAX_AD       255L
void main( void )
    unsigned int voltage;
    cursor( NOWRAP );
    printf("\fBattery voltage:");
    while( 1 )
        voltage = ((long) batteryvoltage() * MAXBATTVOLT ) / MAX_AD;
        printf("%1d.%02d V", (voltage/100), (voltage-100*(voltage/100)));
        sound( TCLICK, VMEDIUM, SHIGH, 0);
        goodreadled( GREEN, TCLICK);

Personal tools