| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LTC2944.h
Go to the documentation of this file.
1 /*!
2 LTC2944: Multicell Battery Gas Gauge with Temperature, Voltage and Current Measurement
3
4 @verbatim
5
6 The LTC®2944 measures battery charge state, battery voltage,
7 battery current and its own temperature in portable
8 product applications. The wide input voltage range allows
9 use with multicell batteries up to 60V. A precision coulomb
10 counter integrates current through a sense resistor between
11 the battery’s positive terminal and the load or charger.
12 Voltage, current and temperature are measured with an
13 internal 14-bit No Latency ΔΣ™ ADC. The measurements
14 are stored in internal registers accessible via the onboard
15 I2C/SMBus Interface.
16
17 I2C DATA FORMAT (MSB FIRST):
18
19 Data Out:
20 Byte #1 Byte #2 Byte #3
21
22 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
23
24 Data In:
25 Byte #1 Byte #2 Byte #3
26
27 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
28
29 Byte #4 Byte #5
30 MSB LSB
31 D15 D14 D13 D12 D11 D10 D9 D8 MACK D7 D6 D5 D4 D3 D2 D1 D0 MNACK STOP
32
33 START : I2C Start
34 Repeat Start: I2c Repeat Start
35 STOP : I2C Stop
36 SAx : I2C Address
37 SACK : I2C Slave Generated Acknowledge (Active Low)
38 MACK : I2C Master Generated Acknowledge (Active Low)
39 MNACK : I2c Master Generated Not Acknowledge
40 W : I2C Write (0)
41 R : I2C Read (1)
42 Cx : Command Code
43 Dx : Data Bits
44 X : Don't care
45
46
47
48 Example Code:
49
50 Read charge, current, and voltage.
51
52 adc_command = LTC2944_SENSE_MONITOR | LTC2944_AUTOMATIC_MODE; // Builds commands to set LTC2944 to automatic mode
53 ack |= LTC2944_write(LTC2944_I2C_ADDRESS, LTC2944_CONTROL_REG, adc_command); // Sets the LTC2944 to automatic mode
54
55 resistor = .1; // Resistor Value On Demo Board
56
57 ack |= LTC2944_read_16_bits(LTC2944_I2C_ADDRESS, LTC2944_CHARGE_MSB_REG, &charge_code); // Reads the ADC registers that contains charge value
58 charge = LTC2944_code_to_coulombs(charge_code, resistor, prescalarValue); // Calculates charge from charge code, resistor and prescalar
59
60 ack |= LTC2944_read_16_bits(LTC2944_I2C_ADDRESS, LTC2944_CURRENT_MSB_REG, &current_code); // Reads the voltage code across sense resistor
61 current = LTC2944_code_to_current(current_code, resistor); // Calculates current from current code, resistor value.
62
63 ack |= LTC2944_read_16_bits(LTC2944_I2C_ADDRESS, LTC2944_VOLTAGE_MSB_REG, &voltage_code); // Reads voltage voltage code
64 VIN = LTC2944_VIN_code_to_voltage(voltage_code); // Calculates VIN voltage from VIN code and lsb
65
66
67 @endverbatim
68 */
69
70 /*! @file
71 @ingroup LTC2944
72 Header for LTC2944: Multicell Battery Gas Gauge with Temperature, Voltage and Current Measurement
73 */
74
75
76 #ifndef LTC2944_H
77 #define LTC2944_H
78
79 #include <Wire.h>
80
81
82 /*!
83 | LTC2944 I2C Address Assignment | Value |
84 | :-------------------------------- | :---: |
85 | LTC2944_I2C_ADDRESS | 0xC8 |
86 */
87
88 /*! @name LTC2944 I2C Address
89 @{ */
90
91 #define LTC2944_I2C_ADDRESS 0x64
92 #define LTC2944_I2C_ALERT_RESPONSE 0x0C
93 //! @}
94
95
96 /*!
97 | Name | Value |
98 | :------------------------------------------------ | :---: |
99 | LTC2944_STATUS_REG | 0x00 |
100 | LTC2944_CONTROL_REG | 0x01 |
101 | LTC2944_ACCUM_CHARGE_MSB_REG | 0x02 |
102 | LTC2944_ACCUM_CHARGE_LSB_REG | 0x03 |
103 | LTC2944_CHARGE_THRESH_HIGH_MSB_REG | 0x04 |
104 | LTC2944_CHARGE_THRESH_HIGH_LSB_REG | 0x05 |
105 | LTC2944_CHARGE_THRESH_LOW_MSB_REG | 0x06 |
106 | LTC2944_CHARGE_THRESH_LOW_LSB_REG | 0x07 |
107 | LTC2944_VOLTAGE_MSB_REG | 0x08 |
108 | LTC2944_VOLTAGE_LSB_REG | 0x09 |
109 | LTC2944_VOLTAGE_THRESH_HIGH_MSB_REG | 0x0A |
110 | LTC2944_VOLTAGE_THRESH_HIGH_LSB_REG | 0x0B |
111 | LTC2944_VOLTAGE_THRESH_LOW_MSB_REG | 0x0C |
112 | LTC2944_VOLTAGE_THRESH_LOW_LSB_REG | 0x0D |
113 | LTC2944_CURRENT_MSB_REG | 0x0E |
114 | LTC2944_CURRENT_LSB_REG | 0x0F |
115 | LTC2944_CURRENT_THRESH_HIGH_MSB_REG | 0x10 |
116 | LTC2944_CURRENT_THRESH_HIGH_LSB_REG | 0x11 |
117 | LTC2944_CURRENT_THRESH_LOW_MSB_REG | 0x12 |
118 | LTC2944_CURRENT_THRESH_LOW_LSB_REG | 0x13 |
119 | LTC2944_TEMPERATURE_MSB_REG | 0x14 |
120 | LTC2944_TEMPERATURE_LSB_REG | 0x15 |
121 | LTC2944_TEMPERATURE_THRESH_HIGH_REG | 0x16 |
122 | LTC2944_TEMPERATURE_THRESH_LOW_REG | 0x17 |
123 */
124
125 /*! @name Registers
126 @{ */
127 // Registers
128 #define LTC2944_STATUS_REG 0x00
129 #define LTC2944_CONTROL_REG 0x01
130 #define LTC2944_ACCUM_CHARGE_MSB_REG 0x02
131 #define LTC2944_ACCUM_CHARGE_LSB_REG 0x03
132 #define LTC2944_CHARGE_THRESH_HIGH_MSB_REG 0x04
133 #define LTC2944_CHARGE_THRESH_HIGH_LSB_REG 0x05
134 #define LTC2944_CHARGE_THRESH_LOW_MSB_REG 0x06
135 #define LTC2944_CHARGE_THRESH_LOW_LSB_REG 0x07
136 #define LTC2944_VOLTAGE_MSB_REG 0x08
137 #define LTC2944_VOLTAGE_LSB_REG 0x09
138 #define LTC2944_VOLTAGE_THRESH_HIGH_MSB_REG 0x0A
139 #define LTC2944_VOLTAGE_THRESH_HIGH_LSB_REG 0x0B
140 #define LTC2944_VOLTAGE_THRESH_LOW_MSB_REG 0x0C
141 #define LTC2944_VOLTAGE_THRESH_LOW_LSB_REG 0x0D
142 #define LTC2944_CURRENT_MSB_REG 0x0E
143 #define LTC2944_CURRENT_LSB_REG 0x0F
144 #define LTC2944_CURRENT_THRESH_HIGH_MSB_REG 0x10
145 #define LTC2944_CURRENT_THRESH_HIGH_LSB_REG 0x11
146 #define LTC2944_CURRENT_THRESH_LOW_MSB_REG 0x12
147 #define LTC2944_CURRENT_THRESH_LOW_LSB_REG 0x13
148 #define LTC2944_TEMPERATURE_MSB_REG 0x14
149 #define LTC2944_TEMPERATURE_LSB_REG 0x15
150 #define LTC2944_TEMPERATURE_THRESH_HIGH_REG 0x16
151 #define LTC2944_TEMPERATURE_THRESH_LOW_REG 0x17
152 //! @}
153
154 /*!
155 | Command Codes | Value |
156 | :-------------------------------------------- | :-------: |
157 | LTC2944_AUTOMATIC_MODE | 0xC0 |
158 | LTC2944_SCAN_MODE | 0x80 |
159 | LTC2944_MANUAL_MODE | 0x40 |
160 | LTC2944_SLEEP_MODE | 0x00 |
161 | LTC2944_PRESCALAR_M_1 | 0x00 |
162 | LTC2944_PRESCALAR_M_4 | 0x08 |
163 | LTC2944_PRESCALAR_M_16 | 0x10 |
164 | LTC2944_PRESCALAR_M_64 | 0x18 |
165 | LTC2944_PRESCALAR_M_256 | 0x20 |
166 | LTC2944_PRESCALAR_M_1024 | 0x28 |
167 | LTC2944_PRESCALAR_M_4096 | 0x30 |
168 | LTC2944_PRESCALAR_M_4096_2 | 0x31 |
169 | LTC2944_ALERT_MODE | 0x04 |
170 | LTC2944_CHARGE_COMPLETE_MODE | 0x02 |
171 | LTC2944_DISABLE_ALCC_PIN | 0x00 |
172 | LTC2944_SHUTDOWN_MODE | 0x01 |
173 */
174
175 /*! @name Command Codes
176 @{ */
177 // Command Codes
178 #define LTC2944_AUTOMATIC_MODE 0xC0
179 #define LTC2944_SCAN_MODE 0x80
180 #define LTC2944_MANUAL_MODE 0x40
181 #define LTC2944_SLEEP_MODE 0x00
182
183 #define LTC2944_PRESCALAR_M_1 0x00
184 #define LTC2944_PRESCALAR_M_4 0x08
185 #define LTC2944_PRESCALAR_M_16 0x10
186 #define LTC2944_PRESCALAR_M_64 0x18
187 #define LTC2944_PRESCALAR_M_256 0x20
188 #define LTC2944_PRESCALAR_M_1024 0x28
189 #define LTC2944_PRESCALAR_M_4096 0x30
190 #define LTC2944_PRESCALAR_M_4096_2 0x31
191
192 #define LTC2944_ALERT_MODE 0x04
193 #define LTC2944_CHARGE_COMPLETE_MODE 0x02
194
195 #define LTC2944_DISABLE_ALCC_PIN 0x00
196 #define LTC2944_SHUTDOWN_MODE 0x01
197
198 //! @}
199
200 /*! @name Conversion Constants
201 @{ */
202 const float LTC2944_CHARGE_lsb = 0.34E-3;
203 const float LTC2944_VOLTAGE_lsb = 4.32E-3;
204 const float LTC2944_CURRENT_lsb = 31.25E-6;
205 const float LTC2944_TEMPERATURE_lsb = 0.25;
206 const float LTC2944_FULLSCALE_VOLTAGE = 70.8;
207 const float LTC2944_FULLSCALE_CURRENT = 64E-3; // Note: 2**11*31.25e-6 = 0.064
208 const float LTC2944_FULLSCALE_TEMPERATURE = 510;
209 //! @}
210
211 //! Write an 8-bit code to the LTC2944.
212 //! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
213 int8_t LTC2944_write(uint8_t i2c_address, //!< Register address for the LTC2944
214 uint8_t adc_command, //!< The "command byte" for the LTC2944
215 uint8_t code //!< Value that will be written to the register.
216 );
217
218 //! Write a 16-bit code to the LTC2944.
219 //! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
220 int8_t LTC2944_write_16_bits(uint8_t i2c_address, //!< Register address for the LTC2944
221 uint8_t adc_command, //!< The "command byte" for the LTC2944
222 uint16_t code //!< Value that will be written to the register.
223 );
224
225
226 //! Reads an 8-bit adc_code from LTC2944
227 //! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
228 int8_t LTC2944_read(uint8_t i2c_address, //!< Register address for the LTC2944
229 uint8_t adc_command, //!< The "command byte" for the LTC2944
230 uint8_t *adc_code //!< Value that will be read from the register.
231 );
232
233 //! Reads a 16-bit adc_code from LTC2944
234 //! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
235 int8_t LTC2944_read_16_bits(uint8_t i2c_address, //!< Register address for the LTC2944
236 uint8_t adc_command, //!< The "command byte" for the LTC2944
237 uint16_t *adc_code //!< Value that will be read from the register.
238 );
239
240
241 //! Calculate the LTC2944 charge in Coulombs
242 //! @return Returns the Coulombs of charge in the ACR register.
243 float LTC2944_code_to_coulombs(uint16_t adc_code, //!< The RAW ADC value
244 float resistor, //!< The sense resistor value
245 uint16_t prescalar //!< The prescalar value
246 );
247
248 //! Calculate the LTC2944 charge in mAh
249 //! @return Returns the Coulombs of charge in the ACR register.
250 float LTC2944_code_to_mAh(uint16_t adc_code, //!< The RAW ADC value
251 float resistor, //!< The sense resistor value
252 uint16_t prescalar //!< The prescalar value
253 );
254
255 //! Calculate the LTC2944 SENSE+ voltage
256 //! @return Returns the SENSE+ Voltage in Volts
257 float LTC2944_code_to_voltage(uint16_t adc_code //!< The RAW ADC value
258 );
259
260 //! Calculate the LTC2944 current with a sense resistor
261 //! @return Returns the current through the sense resisor
262 float LTC2944_code_to_current(uint16_t adc_code, //!< The RAW ADC value
263 float resistor //!< The sense resistor value
264 );
265
266 //! Calculate the LTC2944 temperature
267 //! @return Returns the temperature in Kelvin
268 float LTC2944_code_to_kelvin_temperature(uint16_t adc_code //!< The RAW ADC value
269 );
270
271 //! Calculate the LTC2944 temperature
272 //! @return Returns the temperature in Celcius
273 float LTC2944_code_to_celcius_temperature(uint16_t adc_code //!< The RAW ADC value
274 );
275
276 #endif // LTC2944_H
i2c_address
uint8_t i2c_address
adc_command
static uint8_t adc_command
Definition: DC2071AA.ino:111
resistor
const float resistor
resistor value on demo board
Definition: DC1496BB.ino:116
LTC2944_code_to_current
float LTC2944_code_to_current(uint16_t adc_code, float resistor)
Calculate the LTC2944 current with a sense resistor.
Definition: LTC2944.cpp:145
LTC2944_FULLSCALE_CURRENT
const float LTC2944_FULLSCALE_CURRENT
Definition: LTC2944.h:207
LTC2944_VOLTAGE_lsb
const float LTC2944_VOLTAGE_lsb
Definition: LTC2944.h:203
LTC2944_FULLSCALE_VOLTAGE
const float LTC2944_FULLSCALE_VOLTAGE
Definition: LTC2944.h:206
LTC2944_read_16_bits
int8_t LTC2944_read_16_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t *adc_code)
Reads a 16-bit adc_code from LTC2944.
Definition: LTC2944.cpp:109
LTC2944_code_to_celcius_temperature
float LTC2944_code_to_celcius_temperature(uint16_t adc_code)
Calculate the LTC2944 temperature.
Definition: LTC2944.cpp:161
LTC2944_code_to_coulombs
float LTC2944_code_to_coulombs(uint16_t adc_code, float resistor, uint16_t prescalar)
Calculate the LTC2944 charge in Coulombs.
Definition: LTC2944.cpp:120
LTC2944_FULLSCALE_TEMPERATURE
const float LTC2944_FULLSCALE_TEMPERATURE
Definition: LTC2944.h:208
LTC2944_code_to_kelvin_temperature
float LTC2944_code_to_kelvin_temperature(uint16_t adc_code)
Calculate the LTC2944 temperature.
Definition: LTC2944.cpp:153
LTC2944_read
int8_t LTC2944_read(uint8_t i2c_address, uint8_t adc_command, uint8_t *adc_code)
Reads an 8-bit adc_code from LTC2944.
Definition: LTC2944.cpp:98
LTC2944_CHARGE_lsb
const float LTC2944_CHARGE_lsb
Definition: LTC2944.h:202
LTC2944_write
int8_t LTC2944_write(uint8_t i2c_address, uint8_t adc_command, uint8_t code)
Write an 8-bit code to the LTC2944.
Definition: LTC2944.cpp:77
E
const int16_t E
Definition: LTC2492_Thermocouple_Meter.ino:101
LTC2944_TEMPERATURE_lsb
const float LTC2944_TEMPERATURE_lsb
Definition: LTC2944.h:205
LTC2944_code_to_mAh
float LTC2944_code_to_mAh(uint16_t adc_code, float resistor, uint16_t prescalar)
Calculate the LTC2944 charge in mAh.
Definition: LTC2944.cpp:129
LTC2944_write_16_bits
int8_t LTC2944_write_16_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t code)
Write a 16-bit code to the LTC2944.
Definition: LTC2944.cpp:88
adc_code
static uint32_t adc_code
Definition: DC2071AA.ino:113
LTC2944_CURRENT_lsb
const float LTC2944_CURRENT_lsb
Definition: LTC2944.h:204
LTC2944_code_to_voltage
float LTC2944_code_to_voltage(uint16_t adc_code)
Calculate the LTC2944 SENSE+ voltage.
Definition: LTC2944.cpp:137