LTC2943-1 - 1A Multicell Battery Gas Gauge with Temperature, Voltage and Current Measurement
Features
- Measures Accumulated Battery Charge and Discharge
- 3.6V to 20V Operating Range for Multiple Cells
- Integrated 50mΩ High Side Sense Resistor
- ±1A Current Sense Range
- 14-Bit ADC Measures Voltage, Current and Temperature
- 1% Voltage, Current and Charge Accuracy
- High Side Sense
- General Purpose Measurements for Any Battery Chemistry and Capacity
- I2C/SMBus Interface
- Configurable Alert Output/Charge Complete Input
- Quiescent Current Less Than 120μA
- Small 8-Lead 3mm × 3mm DFN Package
Typical Application
Description
The LTC®2943-1 measures battery charge state, battery voltage, battery current and its own temperature in portable product applications. The wide input voltage range allows use with multicell batteries up to 20V. A precision coulomb counter integrates current through a sense resistor between the battery’s positive terminal and the load or charger. Voltage, current and temperature are measured with an internal 14-bit No Latency ΔΣ™ ADC. The measurements are stored in internal registers accessible via the onboard I2C/SMBus Interface.
The LTC2943-1 features programmable high and low thresholds for all four measured quantities. If a programmed threshold is exceeded, the device communicates an alert using either the SMBus alert protocol or by setting a flag in the internal status register.
Packaging
For complete and up to date package information and drawings, please refer to our packaging page
| Part Number | Package | Code | Temp | Package Drawing |
RoHS |
|---|---|---|---|---|---|
| LTC2943CDD-1#PBF | 3x3 DFN-8 | DD | C | 05-08-1698 | Yes |
| LTC2943CDD-1#TRPBF | 3x3 DFN-8 | DD | C | 05-08-1698 | Yes |
| LTC2943IDD-1#PBF | 3x3 DFN-8 | DD | I | 05-08-1698 | Yes |
| LTC2943IDD-1#TRPBF | 3x3 DFN-8 | DD | I | 05-08-1698 | Yes |
Order Info
- Part numbers ending in PBF are lead free. Solder plated terminal finish (SnPb) versions are non-standard and special terms and conditions and pricing applies if available. Please contact LTC marketing for information.
- Part numbers containing TR or TRM are shipped in tape and reel or 500 unit mini tape and reel, respectively
- Please refer to our general ordering information or the product datasheet for more details
Package Variations and Pricing
| Part Number | Package | Temp | Price (1-99) |
Price (1k)* |
RoHS | |
|---|---|---|---|---|---|---|
| LTC2943CDD-1#PBF | 3x3 DFN-8 | C | $3.86 | $2.70 | Yes | |
| LTC2943CDD-1#TRPBF | 3x3 DFN-8 | C | $3.92 | $2.76 | Yes | |
| LTC2943IDD-1#PBF | 3x3 DFN-8 | I | $4.63 | $3.24 | Yes | |
| LTC2943IDD-1#TRPBF | 3x3 DFN-8 | I | $4.69 | $3.30 | Yes | |
| Buy Now • Request Samples | ||||||
Demo Boards
Linear Technology offers many demo boards free of charge to qualified customers. Contact your local sales office or distributor to inquire about a demo board. Certain demo boards are also available for sale via credit card on this website. Demo boards are for evaluation purposes only. It remains the customer’s responsibility to verify proper and reliable operation in the actual end application.| Part Number | Description | Price | Documentation |
|---|---|---|---|
| DC1812A-C | LTC2943-1 Demo Board | 20VIN, 1A Battery Gas Gauge w/ Internal RSENSE (req. DC2026) | $50.00 | |
| Buy Now | |||
Companion Boards
| Part Number | Description | Price | Documentation |
|---|---|---|---|
| DC2026C | Linduino One Isolated USB Demo Board: An Arduino- and QuikEval-Compatible Code Development Platform | $75.00 | |
| Buy Now | |||
Applications
- Power Tools
- Portable Medical Equipment
- Video Cameras
People Who Viewed This Product Also Viewed
- LTC2943 - Multicell Battery Gas Gauge with Temperature, Voltage and Current Measurement
- LTC4015 - Multichemistry Buck Battery Charger Controller with Digital Telemetry System
- LTC4020 - 55V Buck-Boost Multi-Chemistry Battery Charger
- LTC2942 - Battery Gas Gauge with Temperature, Voltage Measurement
- LTC4150 - Coulomb Counter/Battery Gas Gauge
- LTC4000 - High Voltage High Current Controller for Battery Charging and Power Management
- LTC3335 - Nanopower Buck-Boost DC/DC with Integrated Coulomb Counter
- LT3652 - Power Tracking 2A Battery Charger for Solar Power
- LTC4364 - Surge Stopper with Ideal Diode
- LT8490 - High Voltage, High Current Buck-Boost Battery Charge Controller with Maximum Power Point Tracking (MPPT)
Product Notifications
Please login to your MyLinear account for notifications of datasheet updates, new document releases and LTspice model announcements for your favorite products. If you do not have a MyLinear account you may Sign Up Now.
Forgot your password? Click here.
Need help? Email mylinear@linear.com with questions and comments.
Design Tools
LTspice
LTspice® software is a powerful, fast and free simulation tool, schematic capture and waveform viewer with enhancements and models for improving the simulation of switching regulators. Click here to download LTspice
Models for the following parts are available in LTspice:
LTC2943
Linduino
Linduino is an Arduino compatible platform for developing and distributing firmware libraries and code for SPI and I²C-compatible integrated circuits. The Linduino One board interfaces to more than 300 QuikEval demonstration cards, supporting a variety of product types including analog-to-digital converters (ADCs), digital-to-analog converters (DACs), power monitors, and more. Firmware libraries for individual devices are written in C and designed to be portable to a wide variety of processors and microcontrollers. Each library has a demonstration program that can be uploaded to the Linduino One platform to allow the circuit and software to be quickly and easily verified.
Code
Linduino is Linear Technology's Arduino compatible system for developing and distributing firmware libraries and example code for Linear Technology’s integrated circuits. The code below can be downloaded or copied and pasted into your project. Please visit the Linduino Home Page for demo board, manual and setup information.
This part is Code Supported: There is example code available for this part. The code below may rely on other drivers available in the full library.
Download LTC2943 - DC1812A Linduino.INO File
/*!
DC1812A-A
LTC2943: Multicell Battery Gas Gauge with Temperature, Voltage and Current Measurement
DC1812A-C
LTC2943-1: Multicell Battery Gas Gauge with Temperature, Voltage and Current Measurement
@verbatim
Setup:
Apply a voltage source to the V_BATT terminal and a load at the V_CHRG/LD terminal.
Refer to the Demo Manual Guide for a detailed setup description. Ensure that JP1 is
set to AL# position.
Explanation of Commands:
1 - Automatic Mode - Scans Voltage, Current, Temperature and charge every 60ms.
Scanning interval has been increased to 1s for ease of reading on the Serial Prompt.
Displays an alert if it is set in the status register at the time of scan.
2 - Scan Mode - Scans Voltage, Current, Temperature and charge every 10s.
Displays an alert if it is set in the status register at the time of scan.
3 - Manual Mode - Provides a SnapShot of the Voltage, Current, Temperature and Accumulated Charge.
After the initial SnapShot, the part goes into sleep mode where it only counts charge.
Displays an alert if it is set in the status register at the time of scan.
4 - Sleep Mode - The ADC portion of the LTC2943 is shutdown. In this mode only charge is accumulated.
5 - Shutdown Mode - The LTC2943 goes into low power mode.
6 - Settings - Allows user to set alert thresholds, set prescalar, set AL#/CC# pin mode and change the temperature and charge units.
NOTES
Setup:
Set the terminal baud rate to 115200 and select the newline terminator.
Requires a power supply.
Refer to demo manual DC1812A-A.
USER INPUT DATA FORMAT:
decimal : 1024
hex : 0x400
octal : 02000 (leading 0 "zero")
binary : B10000000000
float : 1024.0
@endverbatim
http://www.linear.com/product/LTC2943
http://www.linear.com/product/LTC2943-1
http://www.linear.com/product/LTC2943#demoboards
http://www.linear.com/product/LTC2943-1#demoboards
REVISION HISTORY
$Revision: 5179 $
$Date: 2016-05-31 16:28:15 -0700 (Tue, 31 May 2016) $
Copyright (c) 2013, Linear Technology Corp.(LTC)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of Linear Technology Corp.
The Linear Technology Linduino is not affiliated with the official Arduino team.
However, the Linduino is only possible because of the Arduino team's commitment
to the open-source community. Please, visit http://www.arduino.cc and
http://store.arduino.cc , and consider a purchase that will help fund their
ongoing work.
*/
/*! @file
@ingroup LTC2943
*/
#include <Arduino.h>
#include <stdint.h>
#include "Linduino.h"
#include "LT_I2C.h"
#include "UserInterface.h"
#include "QuikEval_EEPROM.h"
#include "LTC2943.h"
#include <Wire.h>
// Function Declaration
void print_title(); // Print the title block
void print_prompt(); // Print the Prompt
void store_alert_settings(); // Store the alert settings to the EEPROM
int8_t restore_alert_settings(); // Read the alert settings from EEPROM
#define AUTOMATIC_MODE_DISPLAY_DELAY 1000 //!< The delay between readings in automatic mode
#define SCAN_MODE_DISPLAY_DELAY 10000 //!< The delay between readings in scan mode
// Change resistor value to 50 mOhm (0.05) for DC1812AC (LTC2943-1)
const float resistor = .100; //!< resistor value on demo board
// Error string
const char ack_error[] = "Error: No Acknowledge. Check I2C Address."; //!< Error message
// Global variables
static int8_t demo_board_connected; //!< Set to 1 if the board is connected
static uint8_t alert_code = 0; //!< Value stored or read from ALERT register. Shared between loop() and restore_alert_settings()
//! Initialize Linduino
void setup()
{
char demo_name[] = "DC1812"; //! Demo Board Name stored in QuikEval EEPROM
quikeval_I2C_init(); //! Configure the EEPROM I2C port for 100kHz
quikeval_I2C_connect(); //! Connects to main I2C port
Serial.begin(115200); //! Initialize the serial port to the PC
print_title();
demo_board_connected = discover_demo_board(demo_name);
if (demo_board_connected)
{
print_prompt();
}
else
{
demo_board_connected = true;
Serial.println("Did not read ID String, attempting to proceed anyway...\nPlease ensure I2C lines of Linduino are connected to the LTC device");
print_prompt();
}
}
//! Repeats Linduino loop
void loop()
{
int8_t ack = 0; //! I2C acknowledge indicator
static uint8_t user_command; //! The user input command
static uint8_t mAh_or_Coulombs = 0;
static uint8_t celcius_or_kelvin = 0;
static uint16_t prescalar_mode = LTC2943_PRESCALAR_M_4096;
static uint16_t prescalarValue = 4096;
static uint16_t alcc_mode = LTC2943_ALERT_MODE;
if (demo_board_connected) //! Do nothing if the demo board is not connected
{
if (Serial.available()) //! Do nothing if serial is not available
{
user_command = read_int(); //! Read user input command
if (user_command != 'm')
Serial.println(user_command);
Serial.println();
ack = 0;
switch (user_command) //! Prints the appropriate submenu
{
case 1:
ack |= menu_1_automatic_mode(mAh_or_Coulombs, celcius_or_kelvin, prescalar_mode, prescalarValue, alcc_mode); //! Automatic Mode
break;
case 2:
ack |= menu_2_scan_mode(mAh_or_Coulombs, celcius_or_kelvin, prescalar_mode, prescalarValue, alcc_mode); //! Scan Mode
break;
case 3:
ack |= menu_3_manual_mode(mAh_or_Coulombs, celcius_or_kelvin, prescalar_mode, prescalarValue, alcc_mode); //! Manual Mode
break;
case 4:
ack |= menu_4_sleep_mode(mAh_or_Coulombs, prescalar_mode, prescalarValue, alcc_mode); //! Sleep Mode
break;
case 5:
ack |= menu_5_shutdown_mode(); //! Shutdown Mode
break;
case 6:
ack |= menu_6_settings(&mAh_or_Coulombs, &celcius_or_kelvin, &prescalar_mode, &prescalarValue, &alcc_mode); //! Settings Mode
break;
}
if (ack != 0) //! If ack is not recieved print an error.
Serial.println(ack_error);
Serial.print(F("*************************"));
print_prompt();
}
}
}
// Function Definitions
//! Print the title block
void print_title()
{
Serial.println(F("\n*****************************************************************"));
Serial.print(F("* DC1812A Demonstration Program *\n"));
Serial.print(F("* *\n"));
Serial.print(F("* This program communicates with the LTC2943 Multicell Coulomb *\n"));
Serial.print(F("* Counter found on the DC1812A demo board. *\n"));
Serial.print(F("* Set the baud rate to 115200 and select the newline terminator.*\n"));
Serial.print(F("* *\n"));
Serial.print(F("*****************************************************************\n"));
}
//! Print the Prompt
void print_prompt()
{
Serial.print(F("\n1-Automatic Mode\n"));
Serial.print(F("2-Scan Mode\n"));
Serial.print(F("3-Manual Mode\n"));
Serial.print(F("4-Sleep Mode\n"));
Serial.print(F("5-Shutdown Mode\n"));
Serial.print(F("6-Settings\n"));
Serial.print(F("Enter a command: "));
}
//! Automatic Mode.
int8_t menu_1_automatic_mode(int8_t mAh_or_Coulombs, int8_t celcius_or_kelvin ,uint16_t prescalar_mode, uint16_t prescalarValue, uint16_t alcc_mode)
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
{
int8_t LTC2943_mode;
int8_t ack = 0;
LTC2943_mode = LTC2943_AUTOMATIC_MODE|prescalar_mode|alcc_mode ; //! Set the control register of the LTC2943 to automatic mode as well as set prescalar and AL#/CC# pin values.
Serial.println();
ack |= LTC2943_write(LTC2943_I2C_ADDRESS, LTC2943_CONTROL_REG, LTC2943_mode); //! Writes the set mode to the LTC2943 control register
do
{
Serial.print(F("*************************\n\n"));
uint8_t status_code, hightemp_code, lowtemp_code;
uint16_t charge_code, current_code, voltage_code, temperature_code;
ack |= LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_ACCUM_CHARGE_MSB_REG, &charge_code); //! Read MSB and LSB Accumulated Charge Registers for 16 bit charge code
ack |= LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_VOLTAGE_MSB_REG, &voltage_code); //! Read MSB and LSB Voltage Registers for 16 bit voltage code
ack |= LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_CURRENT_MSB_REG, ¤t_code); //! Read MSB and LSB Current Registers for 16 bit current code
ack |= LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_TEMPERATURE_MSB_REG, &temperature_code); //! Read MSB and LSB Temperature Registers for 16 bit temperature code
ack |= LTC2943_read(LTC2943_I2C_ADDRESS, LTC2943_STATUS_REG, &status_code); //! Read Status Register for 8 bit status code
float charge, current, voltage, temperature;
if (mAh_or_Coulombs)
{
charge = LTC2943_code_to_coulombs(charge_code, resistor, prescalarValue); //! Convert charge code to Coulombs if Coulomb units are desired.
Serial.print("Coulombs: ");
Serial.print(charge, 4);
Serial.print(F(" C\n"));
}
else
{
charge = LTC2943_code_to_mAh(charge_code, resistor, prescalarValue); //! Convert charge code to mAh if mAh units are desired.
Serial.print("mAh: ");
Serial.print(charge, 4);
Serial.print(F(" mAh\n"));
}
current = LTC2943_code_to_current(current_code, resistor); //! Convert current code to Amperes
voltage = LTC2943_code_to_voltage(voltage_code); //! Convert voltage code to Volts
Serial.print(F("Current "));
Serial.print(current, 4);
Serial.print(F(" A\n"));
Serial.print(F("Voltage "));
Serial.print(voltage, 4);
Serial.print(F(" V\n"));
if (celcius_or_kelvin)
{
temperature = LTC2943_code_to_kelvin_temperature(temperature_code); //! Convert temperature code to kelvin
Serial.print(F("Temperature "));
Serial.print(temperature, 4);
Serial.print(F(" K\n"));
}
else
{
temperature = LTC2943_code_to_celcius_temperature(temperature_code); //! Convert temperature code to celcius
Serial.print(F("Temperature "));
Serial.print(temperature, 4);
Serial.print(F(" C\n"));
}
checkAlerts(status_code); //! Check status code for Alerts. If an Alert has been set, print out appropriate message in the Serial Prompt.
Serial.print(F("m-Main Menu\n\n"));
Serial.flush();
delay(AUTOMATIC_MODE_DISPLAY_DELAY); //! Delay for 1s before next polling
}
while (Serial.available() == false && !(ack)); //! if Serial is not available and an NACK has not been recieved, keep polling the registers.
read_int(); // clears the Serial.available
return(ack);
}
//! Scan Mode
int8_t menu_2_scan_mode(int8_t mAh_or_Coulombs , int8_t celcius_or_kelvin ,uint16_t prescalar_mode,uint16_t prescalarValue, uint16_t alcc_mode)
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
{
int8_t LTC2943_mode;
int8_t ack = 0;
LTC2943_mode = LTC2943_SCAN_MODE|prescalar_mode|alcc_mode ; //! Set the control mode of the LTC2943 to scan mode as well as set prescalar and AL#/CC# pin values.
Serial.println();
ack |= LTC2943_write(LTC2943_I2C_ADDRESS, LTC2943_CONTROL_REG, LTC2943_mode); //! Writes the set mode to the LTC2943 control register
do
{
Serial.print(F("*************************\n\n"));
uint8_t status_code;
uint16_t charge_code, current_code, voltage_code, temperature_code;
ack |= LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_ACCUM_CHARGE_MSB_REG, &charge_code); //! Read MSB and LSB Accumulated Charge Registers for 16 bit charge code
ack |= LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_VOLTAGE_MSB_REG, &voltage_code); //! Read MSB and LSB Voltage Registers for 16 bit voltage code
ack |= LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_CURRENT_MSB_REG, ¤t_code); //! Read MSB and LSB Current Registers for 16 bit current code
ack |= LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_TEMPERATURE_MSB_REG, &temperature_code); //! Read MSB and LSB Temperature Registers for 16 bit temperature code
ack |= LTC2943_read(LTC2943_I2C_ADDRESS, LTC2943_STATUS_REG, &status_code); //! Read Status Registers for 8 bit status code
float charge, current, voltage, temperature;
if (mAh_or_Coulombs)
{
charge = LTC2943_code_to_coulombs(charge_code, resistor, prescalarValue); //! Convert charge code to Coulombs if Coulomb units are desired.
Serial.print("Coulombs: ");
Serial.print(charge, 4);
Serial.print(F(" C\n"));
}
else
{
charge = LTC2943_code_to_mAh(charge_code, resistor, prescalarValue); //! Convert charge code to mAh if mAh units are desired.
Serial.print("mAh: ");
Serial.print(charge, 4);
Serial.print(F(" mAh\n"));
}
current = LTC2943_code_to_current(current_code, resistor); //! Convert current code to Amperes
voltage = LTC2943_code_to_voltage(voltage_code); //! Convert voltage code to Volts
Serial.print(F("Current "));
Serial.print(current, 4);
Serial.print(F(" A\n"));
Serial.print(F("Voltage "));
Serial.print(voltage, 4);
Serial.print(F(" V\n"));
if (celcius_or_kelvin)
{
temperature = LTC2943_code_to_kelvin_temperature(temperature_code); //! Convert temperature code to Kelvin if Kelvin units are desired.
Serial.print(F("Temperature "));
Serial.print(temperature, 4);
Serial.print(F(" K\n"));
}
else
{
temperature = LTC2943_code_to_celcius_temperature(temperature_code); //! Convert temperature code to Celcius if Celcius units are desired.
Serial.print(F("Temperature "));
Serial.print(temperature, 4);
Serial.print(F(" C\n"));
}
checkAlerts(status_code); //! Check status code for Alerts. If an Alert has been set, print out appropriate message in the Serial Prompt
Serial.print(F("m-Main Menu\n\n"));
Serial.flush();
delay(SCAN_MODE_DISPLAY_DELAY);
}
while (Serial.available() == false && !(ack));
read_int(); // clears the Serial.available
return(ack);
}
//! Manual Mode
int8_t menu_3_manual_mode(int8_t mAh_or_Coulombs ,int8_t celcius_or_kelvin ,uint16_t prescalar_mode, uint16_t prescalarValue, uint16_t alcc_mode)
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
{
int8_t LTC2943_mode;
int8_t ack = 0;
LTC2943_mode = LTC2943_MANUAL_MODE|prescalar_mode|alcc_mode ; //! Set the control mode of the LTC2943 to manual mode as well as set prescalar and AL#/CC# pin values.
Serial.println();
ack |= LTC2943_write(LTC2943_I2C_ADDRESS, LTC2943_CONTROL_REG, LTC2943_mode); //! Writes the set mode to the LTC2943 control register
int staleData = 0; //! Stale Data Check variable. When set to 1 it indicates that stale data is being read from the voltage, current and temperature registers.
do
{
Serial.print(F("*************************\n\n"));
uint8_t status_code;
uint16_t charge_code, current_code, voltage_code, temperature_code;
ack |= LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_ACCUM_CHARGE_MSB_REG, &charge_code); //! Read MSB and LSB Accumulated Charge Registers for 16 bit charge code
ack |= LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_VOLTAGE_MSB_REG, &voltage_code); //! Read MSB and LSB Voltage Registers for 16 bit voltage code
ack |= LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_CURRENT_MSB_REG, ¤t_code); //! Read MSB and LSB Current Registers for 16 bit current code
ack |= LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_TEMPERATURE_MSB_REG, &temperature_code); //! Read MSB and LSB Temperature Registers for 16 bit temperature code
ack |= LTC2943_read(LTC2943_I2C_ADDRESS, LTC2943_STATUS_REG, &status_code); //! Read Status Registers for 8 bit status code
float charge, current, voltage, temperature;
if (mAh_or_Coulombs)
{
charge = LTC2943_code_to_coulombs(charge_code, resistor, prescalarValue); //! Convert charge code to Coulombs if Coulomb units are desired.
Serial.print("Coulombs: ");
Serial.print(charge, 4);
Serial.print(F(" C\n"));
}
else
{
charge = LTC2943_code_to_mAh(charge_code, resistor, prescalarValue); //! Convert charge code to mAh if mAh units are desired.
Serial.print("mAh: ");
Serial.print(charge, 4);
Serial.print(F(" mAh\n"));
}
current = LTC2943_code_to_current(current_code, resistor); //! Convert current code to Amperes
voltage = LTC2943_code_to_voltage(voltage_code); //! Convert voltage code to Volts
Serial.print(F("Current "));
Serial.print(current, 4);
Serial.print(F(" A"));
if (staleData) Serial.print(F(" ***** Stale Data ******\n")); //! If Stale data is inside the register after initial snapshot, Print Stale Data message.
else Serial.println("");
Serial.print(F("Voltage "));
Serial.print(voltage, 4);
Serial.print(F(" V"));
if (staleData) Serial.print(F(" ***** Stale Data ******\n")); //! If Stale data is inside the register after initial snapshot, Print Stale Data message.
else Serial.println("");
if (celcius_or_kelvin)
{
temperature = LTC2943_code_to_kelvin_temperature(temperature_code); //! Convert temperature code to Kelvin if Kelvin units are desired.
Serial.print(F("Temperature "));
Serial.print(temperature, 4);
Serial.print(F(" K"));
}
else
{
temperature = LTC2943_code_to_celcius_temperature(temperature_code); //! Convert temperature code to Celcius if Celcius units are desired.
Serial.print(F("Temperature "));
Serial.print(temperature, 4);
Serial.print(F(" C"));
}
if (staleData) Serial.print(F(" ***** Stale Data ******\n"));
else Serial.println("");
checkAlerts(status_code); //! Check status code for Alerts. If an Alert has been set, print out appropriate message in the Serial Prompt
Serial.print(F("m-Main Menu\n\n"));
staleData = 1;
Serial.flush();
delay(AUTOMATIC_MODE_DISPLAY_DELAY);
}
while (Serial.available() == false && !(ack));
read_int(); // clears the Serial.available
return(ack);
}
//! Sleep Mode
int8_t menu_4_sleep_mode(int8_t mAh_or_Coulombs ,uint16_t prescalar_mode, uint16_t prescalarValue, uint16_t alcc_mode)
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
{
int8_t LTC2943_mode;
int8_t ack = 0;
LTC2943_mode = LTC2943_SLEEP_MODE|prescalar_mode|alcc_mode ; //! Set the control mode of the LTC2943 to sleep mode as well as set prescalar and AL#/CC# pin values.
Serial.println();
ack |= LTC2943_write(LTC2943_I2C_ADDRESS, LTC2943_CONTROL_REG, LTC2943_mode); //! Writes the set mode to the LTC2943 control register
do
{
Serial.print(F("*************************\n\n"));
delay(100);
uint8_t status_code;
uint16_t charge_code;
ack |= LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_ACCUM_CHARGE_MSB_REG, &charge_code); //! Read MSB and LSB Accumulated Charge Registers for 16 bit charge code
ack |= LTC2943_read(LTC2943_I2C_ADDRESS, LTC2943_STATUS_REG, &status_code); //! Read Status Registers for 8 bit status code
float charge;
if (mAh_or_Coulombs)
{
charge = LTC2943_code_to_coulombs(charge_code, resistor, prescalarValue); //! Convert charge code to Coulombs if Coulomb units are desired.
Serial.print("Coulombs: ");
Serial.print(charge, 4);
Serial.print(F(" C\n"));
}
else
{
charge = LTC2943_code_to_mAh(charge_code, resistor, prescalarValue); //! Convert charge code to mAh if mAh units are desired.
Serial.print("mAh: ");
Serial.print(charge, 4);
Serial.print(F(" mAh\n"));
}
Serial.print(F("Current "));
Serial.print(F(" ADC Sleep...\n"));
Serial.print(F("Voltage "));
Serial.print(F(" ADC Sleep...\n"));
Serial.print(F("Temperature "));
Serial.print(F(" ADC Sleep...\n"));
Serial.print(F("m-Main Menu\n\n"));
checkAlerts(status_code);
Serial.flush();
delay(AUTOMATIC_MODE_DISPLAY_DELAY);
}
while (Serial.available() == false || (ack));
read_int(); // clears the Serial.available
return(ack);
}
//! Shutdown Mode
int8_t menu_5_shutdown_mode()
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
{
int8_t ack = 0;
ack |= LTC2943_write(LTC2943_I2C_ADDRESS, LTC2943_CONTROL_REG, LTC2943_SHUTDOWN_MODE); //! Sets the LTC2943 into shutdown mode
Serial.print("LTC2943 Has Been ShutDown\n");
return(ack);
}
//! Settings Menu
int8_t menu_6_settings(uint8_t *mAh_or_Coulombs, uint8_t *celcius_or_kelvin, uint16_t *prescalar_mode, uint16_t *prescalarValue, uint16_t *alcc_mode)
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
{
int8_t ack = 0;
int8_t user_command;
do
{
Serial.print(F("*************************\n\n"));
Serial.print(F("1-Set Alert Thresholds\n"));
Serial.print(F("2-Set Prescalar Value\n"));
Serial.print(F("3-Set AL#/CC# Pin State\n"));
Serial.print(F("4-Set Units\n"));
Serial.print(F("m-Main Menu\n\n"));
Serial.print(F("Enter a command: "));
user_command = read_int();
if (user_command == 'm')
Serial.println("m");
else
Serial.println(user_command);
Serial.println();
switch (user_command)
{
case 1:
ack |= menu_6_settings_menu_1_set_alert_thresholds(); //! Settings Menu to set Alert Thresholds
break;
case 2:
ack |= menu_6_settings_menu_2_set_prescalar_values(prescalar_mode, prescalarValue); //! Settings Menu to set Prescalar Values
break;
case 3:
ack |= menu_6_alert_menu_3_set_allcc_state(alcc_mode); //! Settings Menu to set AL#/CC# mode
break;
case 4:
ack |= menu_6_alert_menu_4_set_units(mAh_or_Coulombs, celcius_or_kelvin); //! Settings Menu to set Temperature and Charge Units
break;
default:
if (user_command != 'm')
Serial.println("Incorrect Option");
break;
}
}
while (!((user_command == 'm') || (ack)));
return(ack);
}
//! Alert Threshold Menu
int8_t menu_6_settings_menu_1_set_alert_thresholds()
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
{
int8_t ack = 0;
int8_t user_command;
do
{
Serial.print(F("*************************\n\n"));
Serial.print(F("1-Set Charge Thresholds\n"));
Serial.print(F("2-Set Voltage Thresholds\n"));
Serial.print(F("3-Set Current Thresholds\n"));
Serial.print(F("4-Set Temperature Thresholds\n"));
Serial.print(F("m-Main Menu\n\n"));
Serial.print(F("Enter a command: "));
user_command = read_int();
if (user_command == 'm')
Serial.println("m");
else
Serial.println(user_command);
Serial.println();
switch (user_command)
{
case 1:
ack |= menu_6_alert_menu_1_set_charge_thresholds(); //! Set Max and Min Charge Thresholds. The ACR charge lsb size changes with respect to the prescalar and sense resistor value. Due to this variability, for the purpose of this demo enter values in hexadecimal.
break;
case 2:
ack |= menu_6_alert_menu_2_set_voltage_thresholds(); //! Set Max and Min Voltage Thresholds. Enter Values in Volts
break;
case 3:
ack |= menu_6_alert_menu_3_set_current_thresholds(); //! Set Max and Min Current Thresholds. Enter Values in Amperes.
break;
case 4:
ack |= menu_6_alert_menu_4_set_temperature_thresholds(); //! Set Max and Min Temperature Thresholds. Enter Values in Celcius.
break;
default:
if (user_command != 'm')
Serial.println("Incorrect Option");
break;
}
}
while (!((user_command == 'm') || (ack)));
return(ack);
}
//! Set Charge Threshold Function
int8_t menu_6_alert_menu_1_set_charge_thresholds()
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
{
int8_t ack = 0;
Serial.print(F("Enter RAW Max Charge Threshold:"));
uint16_t max_charge_threshold;
max_charge_threshold = read_int(); //! Read user entered value
Serial.println(max_charge_threshold);
ack |= LTC2943_write_16_bits(LTC2943_I2C_ADDRESS, LTC2943_CHARGE_THRESH_HIGH_MSB_REG, max_charge_threshold); //! write user entered value to HIGH threshold register
Serial.print(F("Enter RAW Min Charge Threshold:"));
float min_charge_threshold;
min_charge_threshold = read_int(); //! Read user entered value
Serial.println(min_charge_threshold);
ack |= LTC2943_write_16_bits(LTC2943_I2C_ADDRESS, LTC2943_CHARGE_THRESH_LOW_MSB_REG, min_charge_threshold); //! write user entered value to HIGH threshold register
return(ack);
}
//! Set Voltage Thresholds
int8_t menu_6_alert_menu_2_set_voltage_thresholds()
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
{
int8_t ack = 0;
Serial.print(F("Enter Max Voltage Threshold:"));
float max_voltage_threshold;
max_voltage_threshold = read_float(); //! Read user entered value
Serial.print(max_voltage_threshold, 3);
Serial.println("V");
uint16_t max_voltage_threshold_code = max_voltage_threshold*(0xFFFF)/(LTC2943_FULLSCALE_VOLTAGE); //! Convert user entered voltage into adc code.
ack |= LTC2943_write_16_bits(LTC2943_I2C_ADDRESS, LTC2943_VOLTAGE_THRESH_HIGH_MSB_REG, max_voltage_threshold_code); //! Write adc code to HIGH threshold register
Serial.print(F("Enter Min Voltage Threshold:"));
float min_voltage_threshold;
min_voltage_threshold = read_float(); //! Read user entered value
Serial.println(min_voltage_threshold, 3);
Serial.println("V");
uint16_t min_voltage_threshold_code = min_voltage_threshold*(0xFFFF)/(LTC2943_FULLSCALE_VOLTAGE); //! Convert user entered voltage into adc code.
ack |= LTC2943_write_16_bits(LTC2943_I2C_ADDRESS, LTC2943_VOLTAGE_THRESH_LOW_MSB_REG, min_voltage_threshold_code); //! Write adc code to LOW threshold register
return(ack);
}
//! Set Current Thresholds
int8_t menu_6_alert_menu_3_set_current_thresholds()
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
{
int8_t ack = 0;
Serial.print(F("Enter Max Current Threshold:"));
float max_current_threshold;
max_current_threshold = read_float(); //! Read user entered value
Serial.print(max_current_threshold, 3);
Serial.println("A");
uint16_t max_current_threshold_code = resistor*max_current_threshold*(0x7FFF)/(LTC2943_FULLSCALE_CURRENT) + 0x7FFF; //! Convert user entered current into adc code.
ack |= LTC2943_write_16_bits(LTC2943_I2C_ADDRESS, LTC2943_CURRENT_THRESH_HIGH_MSB_REG, max_current_threshold_code); //! Write adc code to HIGH threshold register
Serial.print(F("Enter Min Current Threshold:"));
float min_current_threshold;
min_current_threshold = read_float(); //! Read user entered value
Serial.print(min_current_threshold, 3);
Serial.println("A");
uint16_t min_current_threshold_code = resistor*min_current_threshold*(0x7FFF)/(LTC2943_FULLSCALE_CURRENT) + 0x7FFF; //! Convert user entered current into adc code.
ack |= LTC2943_write_16_bits(LTC2943_I2C_ADDRESS, LTC2943_CURRENT_THRESH_LOW_MSB_REG, min_current_threshold_code); //! Write adc code to LOW threshold register
return(ack);
}
//! Set Temperature Thresholds
int8_t menu_6_alert_menu_4_set_temperature_thresholds()
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
{
int8_t ack = 0;
Serial.print(F("Enter Max Temperature Threshold in Celcius:"));
float max_temperature_threshold;
max_temperature_threshold = read_float(); //! Read user entered value
Serial.print(max_temperature_threshold, 2);
Serial.println("C");
uint16_t max_temperature_threshold_code = (max_temperature_threshold + 273.15)*(0xFFFF)/(LTC2943_FULLSCALE_TEMPERATURE); //! Convert user entered temperature into adc code.
ack |= LTC2943_write_16_bits(LTC2943_I2C_ADDRESS, LTC2943_TEMPERATURE_THRESH_HIGH_REG, max_temperature_threshold_code); //! Write adc code to HIGH threshold register
Serial.print(F("Enter Min Temperature Threshold in Celcius:"));
float min_temperature_threshold;
min_temperature_threshold = read_float(); //! Read user entered value
Serial.print(min_temperature_threshold, 2);
Serial.println("C");
uint16_t min_temperature_threshold_code = (min_temperature_threshold + 273.15)*(0xFFFF)/(LTC2943_FULLSCALE_TEMPERATURE); //! Convert user entered temperature into adc code.
ack |= LTC2943_write_16_bits(LTC2943_I2C_ADDRESS, LTC2943_TEMPERATURE_THRESH_LOW_REG, min_temperature_threshold_code); //! Write adc code to LOW threshold register
return(ack);
}
//! Prescalar Menu
int8_t menu_6_settings_menu_2_set_prescalar_values(uint16_t *prescalar_mode, uint16_t *prescalarValue)
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
{
int8_t ack = 0;
int8_t user_command;
do
{
Serial.print(F("*************************\n\n"));
Serial.print(F("1-Set Prescalar M = 1\n"));
Serial.print(F("2-Set Prescalar M = 4\n"));
Serial.print(F("3-Set Prescalar M = 16\n"));
Serial.print(F("4-Set Prescalar M = 64\n"));
Serial.print(F("5-Set Prescalar M = 256\n"));
Serial.print(F("6-Set Prescalar M = 1024\n"));
Serial.print(F("7-Set Prescalar M = 4096\n"));
Serial.print(F("m-Main Menu\n\n"));
Serial.print(F("Enter a command: "));
user_command = read_int();
if (user_command == 'm')
Serial.println("m");
else
Serial.println(user_command);
Serial.println();
switch (user_command)
{
case 1:
*prescalar_mode = LTC2943_PRESCALAR_M_1; //! Set Prescalar Value M = 1
*prescalarValue = 1;
Serial.println(F("\nPrescalar Set to 1\n"));
break;
case 2:
*prescalar_mode = LTC2943_PRESCALAR_M_4; //! Set Prescalar Value M = 4
*prescalarValue = 4;
Serial.println(F("\nPrescalar Set to 4\n"));
break;
case 3:
*prescalar_mode = LTC2943_PRESCALAR_M_16; //! Set Prescalar Value M = 16
*prescalarValue = 16;
Serial.println(F("\nPrescalar Set to 16\n"));
break;
case 4:
*prescalar_mode = LTC2943_PRESCALAR_M_64; //! Set Prescalar Value M = 64
*prescalarValue = 64;
Serial.println(F("\nPrescalar Set to 64\n"));
break;
case 5:
*prescalar_mode = LTC2943_PRESCALAR_M_256; //! Set Prescalar Value M = 256
*prescalarValue = 256;
Serial.println(F("\nPrescalar Set to 256\n"));
break;
case 6:
*prescalar_mode = LTC2943_PRESCALAR_M_1024; //! Set Prescalar Value M = 1024
*prescalarValue = 1024;
\
Serial.println(F("\nPrescalar Set to 1024\n"));
break;
case 7:
*prescalar_mode = LTC2943_PRESCALAR_M_4096; //! Set Prescalar Value M = 4096
*prescalarValue = 4096;
Serial.println(F("\nPrescalar Set to 4096\n"));
break;
default:
if (user_command != 'm')
Serial.println("Incorrect Option");
break;
}
}
while (!((user_command == 'm') || (ack)));
return(ack);
}
//! AL#/CC# Pin Mode Menu
uint8_t menu_6_alert_menu_3_set_allcc_state(uint16_t *alcc_mode)
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
{
int8_t ack = 0;
int8_t user_command;
do
{
Serial.print(F("*************************\n\n"));
Serial.print(F("1-Enable Alert Mode\n"));
Serial.print(F("2-Enable Charge Complete Mode\n"));
Serial.print(F("3-Disable AL#/CC# Pin\n"));
Serial.print(F("m-Main Menu\n\n"));
Serial.print(F("Enter a command: "));
user_command = read_int();
if (user_command == 'm')
Serial.println("m");
else
Serial.println(user_command);
Serial.println();
switch (user_command)
{
case 1:
*alcc_mode = LTC2943_ALERT_MODE; //! Set AL#/CC# mode to Alert Mode
Serial.println(F("\nAlert Mode Enabled\n"));
break;
case 2:
*alcc_mode = LTC2943_CHARGE_COMPLETE_MODE; //! Set AL#/CC# mode to Charge Complete Mode
Serial.println(F("\nCharge Mode Enabled\n"));
break;
case 3:
*alcc_mode = LTC2943_DISABLE_ALCC_PIN; //! Disable AL#/CC# pin.
Serial.println(F("\nAL#/CC# Pin Disabled\n"));
break;
default:
if (user_command != 'm')
Serial.println("Incorrect Option");
break;
}
}
while (!((user_command == 'm') || (ack)));
return(ack);
}
//! Set Charge and Temperature Units Menu
uint8_t menu_6_alert_menu_4_set_units(uint8_t *mAh_or_Coulombs, uint8_t *celcius_or_kelvin)
//! @return Returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge
{
int8_t ack = 0;
int8_t user_command;
do
{
Serial.print(F("*************************\n\n"));
Serial.print(F("1-Set Charge Units to mAh\n"));
Serial.print(F("2-Set Charge Units to Coulombs\n"));
Serial.print(F("3-Set Temperature Units to Celsius\n"));
Serial.print(F("4-Set Temperature Units to Kelvin\n"));
Serial.print(F("m-Main Menu\n\n"));
Serial.print(F("Enter a command: "));
user_command = read_int();
if (user_command == 'm')
Serial.println("m");
else
Serial.println(user_command);
Serial.println();
switch (user_command)
{
case 1:
*mAh_or_Coulombs = 0;
Serial.println(F("\nCharge Units Set to mAh\n"));
break;
case 2:
*mAh_or_Coulombs = 1;
Serial.println(F("\nCharge Units Set to Coulombs\n"));
break;
case 3:
*celcius_or_kelvin = 0;
Serial.println(F("\nTemperature Units Set to Celcius\n"));
break;
case 4:
*celcius_or_kelvin = 1;
Serial.println(F("\nTemperature Units Set to Kelvin\n"));
break;
default:
if (user_command != 'm')
Serial.println("Incorrect Option");
break;
}
}
while (!((user_command == 'm') || (ack)));
return(ack);
}
//! Checks to see if a bit in a certain position is set.
bool isBitSet(uint8_t value, uint8_t position)
//! @return Returns the state of a bit at "position" in a byte. 1 = Set, 0 = Not Set
{
return((1<<position)&value);
}
//! Check Alerts Function - Checks to see if an alert has been set in the status register. If an alert has been set, it prints out the appropriate message.
void checkAlerts(uint8_t status_code)
//! @return
{
if (isBitSet(status_code,6))
{
Serial.print(F("\n***********************\n"));
Serial.print(F("Alert: "));
Serial.print(F("Current Alert\n"));
Serial.print(F("***********************\n"));
}
if (isBitSet(status_code,5))
{
Serial.print(F("\n***********************\n"));
Serial.print(F("Alert: "));
Serial.print(F("Charge Over/Under Flow Alert\n"));
Serial.print(F("***********************\n"));
}
if (isBitSet(status_code,4))
{
Serial.print(F("\n***********************\n"));
Serial.print(F("Alert: "));
Serial.print(F("Temperature Alert\n"));
Serial.print(F("***********************\n"));
}
if (isBitSet(status_code,3))
{
Serial.print(F("\n***********************\n"));
Serial.print(F("Alert: "));
Serial.print(F("Charge High Alert\n"));
Serial.print(F("***********************\n"));
}
if (isBitSet(status_code,2))
{
Serial.print(F("\n***********************\n"));
Serial.print(F("Alert: "));
Serial.print(F("Charge Low Alert\n"));
Serial.print(F("***********************\n"));
}
if (isBitSet(status_code,1))
{
Serial.print(F("\n***********************\n"));
Serial.print(F("Alert: "));
Serial.print(F("Voltage Alert\n"));
Serial.print(F("***********************\n"));
}
if (isBitSet(status_code,0))
{
Serial.print(F("\n***********************\n"));
Serial.print(F("Alert: "));
Serial.print(F("UVLO Alert\n"));
Serial.print(F("***********************\n"));
}
}
Download LTC2943 Linduino Header File
/*!
LTC2943: Multicell Battery Gas Gauge with Temperature, Voltage and Current Measurement.
LTC2943-1: Multicell Battery Gas Gauge with Temperature, Voltage and Current Measurement.
@verbatim
The LTC2943 measures battery charge state, battery voltage,
battery current and its own temperature in portable
product applications. The wide input voltage range allows
use with multicell batteries up to 20V. A precision coulomb
counter integrates current through a sense resistor between
the battery’s positive terminal and the load or charger.
Voltage, current and temperature are measured with an
internal 14-bit No Latency ΔΣ™ ADC. The measurements
are stored in internal registers accessible via the onboard
I2C/SMBus Interface.
I2C DATA FORMAT (MSB FIRST):
Data Out:
Byte #1 Byte #2 Byte #3
START SA6 SA5 SA4 SA3 SA2 SA1 SA0 W SACK C7 C6 C5 C4 C3 C2 C1 C0 SACK D7 D6 D5 D4 D3 D2 D1 D0 SACK STOP
Data In:
Byte #1 Byte #2 Byte #3
START SA6 SA5 SA4 SA3 SA2 SA1 SA0 W SACK C7 C6 C5 C4 C3 C2 C1 C0 SACK Repeat Start SA6 SA5 SA4 SA3 SA2 SA1 SA0 R SACK
Byte #4 Byte #5
MSB LSB
D15 D14 D13 D12 D11 D10 D9 D8 MACK D7 D6 D5 D4 D3 D2 D1 D0 MNACK STOP
START : I2C Start
Repeat Start: I2c Repeat Start
STOP : I2C Stop
SAx : I2C Address
SACK : I2C Slave Generated Acknowledge (Active Low)
MACK : I2C Master Generated Acknowledge (Active Low)
MNACK : I2c Master Generated Not Acknowledge
W : I2C Write (0)
R : I2C Read (1)
Cx : Command Code
Dx : Data Bits
X : Don't care
Example Code:
Read charge, current, and voltage.
adc_command = LTC2943_SENSE_MONITOR | LTC2943_AUTOMATIC_MODE; // Builds commands to set LTC2943 to automatic mode
ack |= LTC2943_write(LTC2943_I2C_ADDRESS, LTC2943_CONTROL_REG, adc_command); // Sets the LTC2943 to automatic mode
resistor = .1; // Resistor Value On Demo Board
ack |= LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_CHARGE_MSB_REG, &charge_code); // Reads the ADC registers that contains charge value
charge = LTC2943_code_to_coulombs(charge_code, resistor, prescalarValue); // Calculates charge from charge code, resistor and prescalar
ack |= LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_CURRENT_MSB_REG, ¤t_code); // Reads the voltage code across sense resistor
current = LTC2943_code_to_current(current_code, resistor); // Calculates current from current code, resistor value.
ack |= LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_VOLTAGE_MSB_REG, &voltage_code); // Reads voltage voltage code
VIN = LTC2943_VIN_code_to_voltage(voltage_code); // Calculates VIN voltage from VIN code and lsb
@endverbatim
http://www.linear.com/product/LTC2943
http://www.linear.com/product/LTC2943-1
http://www.linear.com/product/LTC2943#demoboards
http://www.linear.com/product/LTC2943-1#demoboards
*/
/*! @file
@ingroup LTC2943
Header for LTC2943: Multicell Battery Gas Gauge with Temperature, Voltage and Current Measurement
*/
#ifndef LTC2943_H
#define LTC2943_H
#include <Wire.h>
/*!
| LTC2943 I2C Address Assignment | Value |
| :-------------------------------- | :---: |
| LTC2943_I2C_ADDRESS | 0xC8 |
*/
/*! @name LTC2943 I2C Address
@{ */
#define LTC2943_I2C_ADDRESS 0x64
#define LTC2943_I2C_ALERT_RESPONSE 0x0C
//! @}
/*!
| Name | Value |
| :------------------------------------------------ | :---: |
| LTC2943_STATUS_REG | 0x00 |
| LTC2943_CONTROL_REG | 0x01 |
| LTC2943_ACCUM_CHARGE_MSB_REG | 0x02 |
| LTC2943_ACCUM_CHARGE_LSB_REG | 0x03 |
| LTC2943_CHARGE_THRESH_HIGH_MSB_REG | 0x04 |
| LTC2943_CHARGE_THRESH_HIGH_LSB_REG | 0x05 |
| LTC2943_CHARGE_THRESH_LOW_MSB_REG | 0x06 |
| LTC2943_CHARGE_THRESH_LOW_LSB_REG | 0x07 |
| LTC2943_VOLTAGE_MSB_REG | 0x08 |
| LTC2943_VOLTAGE_LSB_REG | 0x09 |
| LTC2943_VOLTAGE_THRESH_HIGH_MSB_REG | 0x0A |
| LTC2943_VOLTAGE_THRESH_HIGH_LSB_REG | 0x0B |
| LTC2943_VOLTAGE_THRESH_LOW_MSB_REG | 0x0C |
| LTC2943_VOLTAGE_THRESH_LOW_LSB_REG | 0x0D |
| LTC2943_CURRENT_MSB_REG | 0x0E |
| LTC2943_CURRENT_LSB_REG | 0x0F |
| LTC2943_CURRENT_THRESH_HIGH_MSB_REG | 0x10 |
| LTC2943_CURRENT_THRESH_HIGH_LSB_REG | 0x11 |
| LTC2943_CURRENT_THRESH_LOW_MSB_REG | 0x12 |
| LTC2943_CURRENT_THRESH_LOW_LSB_REG | 0x13 |
| LTC2943_TEMPERATURE_MSB_REG | 0x14 |
| LTC2943_TEMPERATURE_LSB_REG | 0x15 |
| LTC2943_TEMPERATURE_THRESH_HIGH_REG | 0x16 |
| LTC2943_TEMPERATURE_THRESH_LOW_REG | 0x17 |
*/
/*! @name Registers
@{ */
// Registers
#define LTC2943_STATUS_REG 0x00
#define LTC2943_CONTROL_REG 0x01
#define LTC2943_ACCUM_CHARGE_MSB_REG 0x02
#define LTC2943_ACCUM_CHARGE_LSB_REG 0x03
#define LTC2943_CHARGE_THRESH_HIGH_MSB_REG 0x04
#define LTC2943_CHARGE_THRESH_HIGH_LSB_REG 0x05
#define LTC2943_CHARGE_THRESH_LOW_MSB_REG 0x06
#define LTC2943_CHARGE_THRESH_LOW_LSB_REG 0x07
#define LTC2943_VOLTAGE_MSB_REG 0x08
#define LTC2943_VOLTAGE_LSB_REG 0x09
#define LTC2943_VOLTAGE_THRESH_HIGH_MSB_REG 0x0A
#define LTC2943_VOLTAGE_THRESH_HIGH_LSB_REG 0x0B
#define LTC2943_VOLTAGE_THRESH_LOW_MSB_REG 0x0C
#define LTC2943_VOLTAGE_THRESH_LOW_LSB_REG 0x0D
#define LTC2943_CURRENT_MSB_REG 0x0E
#define LTC2943_CURRENT_LSB_REG 0x0F
#define LTC2943_CURRENT_THRESH_HIGH_MSB_REG 0x10
#define LTC2943_CURRENT_THRESH_HIGH_LSB_REG 0x11
#define LTC2943_CURRENT_THRESH_LOW_MSB_REG 0x12
#define LTC2943_CURRENT_THRESH_LOW_LSB_REG 0x13
#define LTC2943_TEMPERATURE_MSB_REG 0x14
#define LTC2943_TEMPERATURE_LSB_REG 0x15
#define LTC2943_TEMPERATURE_THRESH_HIGH_REG 0x16
#define LTC2943_TEMPERATURE_THRESH_LOW_REG 0x17
//! @}
/*!
| Command Codes | Value |
| :-------------------------------------------- | :-------: |
| LTC2943_AUTOMATIC_MODE | 0xC0 |
| LTC2943_SCAN_MODE | 0x80 |
| LTC2943_MANUAL_MODE | 0x40 |
| LTC2943_SLEEP_MODE | 0x00 |
| LTC2943_PRESCALAR_M_1 | 0x00 |
| LTC2943_PRESCALAR_M_4 | 0x08 |
| LTC2943_PRESCALAR_M_16 | 0x10 |
| LTC2943_PRESCALAR_M_64 | 0x18 |
| LTC2943_PRESCALAR_M_256 | 0x20 |
| LTC2943_PRESCALAR_M_1024 | 0x28 |
| LTC2943_PRESCALAR_M_4096 | 0x30 |
| LTC2943_PRESCALAR_M_4096_2 | 0x31 |
| LTC2943_ALERT_MODE | 0x04 |
| LTC2943_CHARGE_COMPLETE_MODE | 0x02 |
| LTC2943_DISABLE_ALCC_PIN | 0x00 |
| LTC2943_SHUTDOWN_MODE | 0x01 |
*/
/*! @name Command Codes
@{ */
// Command Codes
#define LTC2943_AUTOMATIC_MODE 0xC0
#define LTC2943_SCAN_MODE 0x80
#define LTC2943_MANUAL_MODE 0x40
#define LTC2943_SLEEP_MODE 0x00
#define LTC2943_PRESCALAR_M_1 0x00
#define LTC2943_PRESCALAR_M_4 0x08
#define LTC2943_PRESCALAR_M_16 0x10
#define LTC2943_PRESCALAR_M_64 0x18
#define LTC2943_PRESCALAR_M_256 0x20
#define LTC2943_PRESCALAR_M_1024 0x28
#define LTC2943_PRESCALAR_M_4096 0x30
#define LTC2943_PRESCALAR_M_4096_2 0x31
#define LTC2943_ALERT_MODE 0x04
#define LTC2943_CHARGE_COMPLETE_MODE 0x02
#define LTC2943_DISABLE_ALCC_PIN 0x00
#define LTC2943_SHUTDOWN_MODE 0x01
//! @}
/*!
| Conversion Constants | Value |
| :------------------------------------------------ | :------: |
| LTC2943_CHARGE_lsb | 0.34 mAh|
| LTC2943_VOLTAGE_lsb | 1.44 mV|
| LTC2943_CURRENT_lsb | 29.3 uV|
| LTC2943_TEMPERATURE_lsb | 0.25 C|
| LTC2943_FULLSCALE_VOLTAGE | 23.6 V|
| LTC2943_FULLSCALE_CURRENT | 60 mV|
| LTC2943_FULLSCALE_TEMPERATURE | 510 K|
*/
/*! @name Conversion Constants
@{ */
const float LTC2943_CHARGE_lsb = 0.34E-3;
const float LTC2943_VOLTAGE_lsb = 1.44E-3;
const float LTC2943_CURRENT_lsb = 29.3E-6;
const float LTC2943_TEMPERATURE_lsb = 0.25;
const float LTC2943_FULLSCALE_VOLTAGE = 23.6;
const float LTC2943_FULLSCALE_CURRENT = 60E-3;
const float LTC2943_FULLSCALE_TEMPERATURE = 510;
//! @}
//! @}
//! Write an 8-bit code to the LTC2943.
//! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t LTC2943_write(uint8_t i2c_address, //!< Register address for the LTC2943
uint8_t adc_command, //!< The "command byte" for the LTC2943
uint8_t code //!< Value that will be written to the register.
);
//! Write a 16-bit code to the LTC2943.
//! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t LTC2943_write_16_bits(uint8_t i2c_address, //!< Register address for the LTC2943
uint8_t adc_command, //!< The "command byte" for the LTC2943
uint16_t code //!< Value that will be written to the register.
);
//! Reads an 8-bit adc_code from LTC2943
//! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t LTC2943_read(uint8_t i2c_address, //!< Register address for the LTC2943
uint8_t adc_command, //!< The "command byte" for the LTC2943
uint8_t *adc_code //!< Value that will be read from the register.
);
//! Reads a 16-bit adc_code from LTC2943
//! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
int8_t LTC2943_read_16_bits(uint8_t i2c_address, //!< Register address for the LTC2943
uint8_t adc_command, //!< The "command byte" for the LTC2943
uint16_t *adc_code //!< Value that will be read from the register.
);
//! Calculate the LTC2943 charge in Coulombs
//! @return Returns the Coulombs of charge in the ACR register.
float LTC2943_code_to_coulombs(uint16_t adc_code, //!< The RAW ADC value
float resistor, //!< The sense resistor value
uint16_t prescalar //!< The prescalar value
);
//! Calculate the LTC2943 charge in mAh
//! @return Returns the Coulombs of charge in the ACR register.
float LTC2943_code_to_mAh(uint16_t adc_code, //!< The RAW ADC value
float resistor, //!< The sense resistor value
uint16_t prescalar //!< The prescalar value
);
//! Calculate the LTC2943 SENSE+ voltage
//! @return Returns the SENSE+ Voltage in Volts
float LTC2943_code_to_voltage(uint16_t adc_code //!< The RAW ADC value
);
//! Calculate the LTC2943 current with a sense resistor
//! @return Returns the current through the sense resisor
float LTC2943_code_to_current(uint16_t adc_code, //!< The RAW ADC value
float resistor //!< The sense resistor value
);
//! Calculate the LTC2943 temperature
//! @return Returns the temperature in Kelvin
float LTC2943_code_to_kelvin_temperature(uint16_t adc_code //!< The RAW ADC value
);
//! Calculate the LTC2943 temperature
//! @return Returns the temperature in Celcius
float LTC2943_code_to_celcius_temperature(uint16_t adc_code //!< The RAW ADC value
);
#endif // LTC2943_H
/*!
LTC2943: Multicell Battery Gas Gauge with Temperature, Voltage and Current Measurement.
LTC2943-1: Multicell Battery Gas Gauge with Temperature, Voltage and Current Measurement.
@verbatim
The LTC2943 measures battery charge state, battery voltage,
battery current and its own temperature in portable
product applications. The wide input voltage range allows
use with multicell batteries up to 20V. A precision coulomb
counter integrates current through a sense resistor between
the battery’s positive terminal and the load or charger.
Voltage, current and temperature are measured with an
internal 14-bit No Latency ΔΣ™ ADC. The measurements
are stored in internal registers accessible via the onboard
I2C/SMBus Interface
@endverbatim
http://www.linear.com/product/LTC2943
http://www.linear.com/product/LTC2943-1
http://www.linear.com/product/LTC2943#demoboards
http://www.linear.com/product/LTC2943-1#demoboards
REVISION HISTORY
$Revision: 5672 $
$Date: 2016-09-02 11:42:55 -0700 (Fri, 02 Sep 2016) $
Copyright (c) 2013, Linear Technology Corp.(LTC)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of Linear Technology Corp.
The Linear Technology Linduino is not affiliated with the official Arduino team.
However, the Linduino is only possible because of the Arduino team's commitment
to the open-source community. Please, visit http://www.arduino.cc and
http://store.arduino.cc , and consider a purchase that will help fund their
ongoing work.
*/
//! @defgroup LTC2943 LTC2943: Multicell Battery Gas Gauge with Temperature, Voltage and Current Measurement
/*! @file
@ingroup LTC2943
Library for LTC2943 Multicell Battery Gas Gauge with Temperature, Voltage and Current Measurement
*/
#include <Arduino.h>
#include <stdint.h>
#include "Linduino.h"
#include "LT_I2C.h"
#include "LTC2943.h"
#include <Wire.h>
// Write an 8-bit code to the LTC2943.
int8_t LTC2943_write(uint8_t i2c_address, uint8_t adc_command, uint8_t code)
// The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
{
int32_t ack;
ack = i2c_write_byte_data(i2c_address, adc_command, code);
return(ack);
}
// Write a 16-bit code to the LTC2943.
int8_t LTC2943_write_16_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t code)
// The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
{
int8_t ack;
ack = i2c_write_word_data(i2c_address, adc_command, code);
return(ack);
}
// Reads an 8-bit adc_code from LTC2943
int8_t LTC2943_read(uint8_t i2c_address, uint8_t adc_command, uint8_t *adc_code)
// The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
{
int32_t ack;
ack = i2c_read_byte_data(i2c_address, adc_command, adc_code);
return(ack);
}
// Reads a 16-bit adc_code from LTC2943
int8_t LTC2943_read_16_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t *adc_code)
// The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
{
int32_t ack;
ack = i2c_read_word_data(i2c_address, adc_command, adc_code);
return(ack);
}
float LTC2943_code_to_coulombs(uint16_t adc_code, float resistor, uint16_t prescalar)
// The function converts the 16-bit RAW adc_code to Coulombs
{
float coulomb_charge;
coulomb_charge = 1000*(float)(adc_code*LTC2943_CHARGE_lsb*prescalar*50E-3)/(resistor*4096);
coulomb_charge = coulomb_charge*3.6f;
return(coulomb_charge);
}
float LTC2943_code_to_mAh(uint16_t adc_code, float resistor, uint16_t prescalar )
// The function converts the 16-bit RAW adc_code to mAh
{
float mAh_charge;
mAh_charge = 1000*(float)(adc_code*LTC2943_CHARGE_lsb*prescalar*50E-3)/(resistor*4096);
return(mAh_charge);
}
float LTC2943_code_to_voltage(uint16_t adc_code)
// The function converts the 16-bit RAW adc_code to Volts
{
float voltage;
voltage = ((float)adc_code/(65535))*LTC2943_FULLSCALE_VOLTAGE;
return(voltage);
}
float LTC2943_code_to_current(uint16_t adc_code, float resistor)
// The function converts the 16-bit RAW adc_code to Amperes
{
float current;
current = (((float)adc_code-32767)/(32767))*((float)(LTC2943_FULLSCALE_CURRENT)/resistor);
return(current);
}
float LTC2943_code_to_kelvin_temperature(uint16_t adc_code)
// The function converts the 16-bit RAW adc_code to Kelvin
{
float temperature;
temperature = adc_code*((float)(LTC2943_FULLSCALE_TEMPERATURE)/65535);
return(temperature);
}
float LTC2943_code_to_celcius_temperature(uint16_t adc_code)
// The function converts the 16-bit RAW adc_code to Celcius
{
float temperature;
temperature = adc_code*((float)(LTC2943_FULLSCALE_TEMPERATURE)/65535) - 273.15;
return(temperature);
}
// Used to set and clear bits in a control register. bits_to_set will be bitwise OR'd with the register.
// bits_to_clear will be inverted and bitwise AND'd with the register so that every location with a 1 will result in a 0 in the register.
int8_t LTC2943_register_set_clear_bits(uint8_t i2c_address, uint8_t register_address, uint8_t bits_to_set, uint8_t bits_to_clear)
{
uint8_t register_data;
int8_t ack = 0;
ack |= LTC2943_read(i2c_address, register_address, ®ister_data);
register_data = register_data & (~bits_to_clear);
register_data = register_data | bits_to_set;
ack |= LTC2943_write(i2c_address, register_address, register_data);
return(ack);
}
Technical Support
- For immediate technical assistance, contact your local sales office or distributor or call 1-800-4-LINEAR (US customers only) or 408-432-1900.
- For less urgent requests, please complete our Technical Support Request Form. Please allow 2-3 business days for reply.