Voltage monitor for car's battery and its charging system. Part 2. Software

Part 1. Schematic

Software

The firmware for this project was developed in mikroC Pro for PIC compiler. The equations to derive the input voltage from the 10-bit ADC output (Digital Number, DN) are described below.

VBattery = VADC, IN * (R1 + R2/R2 = 4.13 * VADC, IN

Resolution of ADC = 4.096/1024 = 4 mV/DN

VADC, IN = DN * 4 (mV)

=> VBattery = 4.13 * 4* DN (mV) = 0.0165*DN (V)

The use of internal reference voltage for A/D conversion requires configuration of FVRCON and ADCON1 registers. The mikroC Pro for PIC compiler provides a library for A/D conversion, but that uses the supply voltage, VDD , by default as the positive reference for the conversion. So the built-in ADC library of mikroC Pro for PIC is not useful for our case and we need to write our own ADC subroutine. The complete source code for this project can be downloaded from the link provided below.

Output

Plug in the device into the car’s cigarette lighter receptacle and turn in the car key to on position (don’t start the engine). This will display the car battery terminal voltage (about 12 V). Once the engine is turned on, the battery starts receiving the charging voltage from the alternator. This voltage should be higher (about 13.8 V) than the actual voltage produced by the battery itself.

Voltage monitor for car's battery and its charging system

Voltage monitor for car's battery and its charging system

Recommendation

An additional LED or a buzzer can also be added to the circuit to alarm under (say < 11.8) or over (say >14.0 V) voltage conditions.

Download the source code and HEX file

embedded-lab.com

You may have to register before you can post comments and get full access to forum.
EMS supplier