| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

LTC2943.h
Go to the documentation of this file.
1 /*!
2 LTC2943: Multicell Battery Gas Gauge with Temperature, Voltage and Current Measurement.
3 LTC2943-1: Multicell Battery Gas Gauge with Temperature, Voltage and Current Measurement.
4
5 @verbatim
6
7 The LTC2943 measures battery charge state, battery voltage,
8 battery current and its own temperature in portable
9 product applications. The wide input voltage range allows
10 use with multicell batteries up to 20V. A precision coulomb
11 counter integrates current through a sense resistor between
12 the battery’s positive terminal and the load or charger.
13 Voltage, current and temperature are measured with an
14 internal 14-bit No Latency ΔΣ™ ADC. The measurements
15 are stored in internal registers accessible via the onboard
16 I2C/SMBus Interface.
17
18 I2C DATA FORMAT (MSB FIRST):
19
20 Data Out:
21 Byte #1 Byte #2 Byte #3
22
23 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
24
25 Data In:
26 Byte #1 Byte #2 Byte #3
27
28 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
29
30 Byte #4 Byte #5
31 MSB LSB
32 D15 D14 D13 D12 D11 D10 D9 D8 MACK D7 D6 D5 D4 D3 D2 D1 D0 MNACK STOP
33
34 START : I2C Start
35 Repeat Start: I2c Repeat Start
36 STOP : I2C Stop
37 SAx : I2C Address
38 SACK : I2C Slave Generated Acknowledge (Active Low)
39 MACK : I2C Master Generated Acknowledge (Active Low)
40 MNACK : I2c Master Generated Not Acknowledge
41 W : I2C Write (0)
42 R : I2C Read (1)
43 Cx : Command Code
44 Dx : Data Bits
45 X : Don't care
46
47
48
49 Example Code:
50
51 Read charge, current, and voltage.
52
53 adc_command = LTC2943_SENSE_MONITOR | LTC2943_AUTOMATIC_MODE; // Builds commands to set LTC2943 to automatic mode
54 ack |= LTC2943_write(LTC2943_I2C_ADDRESS, LTC2943_CONTROL_REG, adc_command); // Sets the LTC2943 to automatic mode
55
56 resistor = .1; // Resistor Value On Demo Board
57
58 ack |= LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_CHARGE_MSB_REG, &charge_code); // Reads the ADC registers that contains charge value
59 charge = LTC2943_code_to_coulombs(charge_code, resistor, prescalarValue); // Calculates charge from charge code, resistor and prescalar
60
61 ack |= LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_CURRENT_MSB_REG, &current_code); // Reads the voltage code across sense resistor
62 current = LTC2943_code_to_current(current_code, resistor); // Calculates current from current code, resistor value.
63
64 ack |= LTC2943_read_16_bits(LTC2943_I2C_ADDRESS, LTC2943_VOLTAGE_MSB_REG, &voltage_code); // Reads voltage voltage code
65 VIN = LTC2943_VIN_code_to_voltage(voltage_code); // Calculates VIN voltage from VIN code and lsb
66
67
68 @endverbatim
69
70 http://www.linear.com/product/LTC2943
71 http://www.linear.com/product/LTC2943-1
72
73 http://www.linear.com/product/LTC2943#demoboards
74 http://www.linear.com/product/LTC2943-1#demoboards
75
76 */
77
78 /*! @file
79 @ingroup LTC2943
80 Header for LTC2943: Multicell Battery Gas Gauge with Temperature, Voltage and Current Measurement
81 */
82
83
84 #ifndef LTC2943_H
85 #define LTC2943_H
86
87 #include <Wire.h>
88
89
90 /*!
91 | LTC2943 I2C Address Assignment | Value |
92 | :-------------------------------- | :---: |
93 | LTC2943_I2C_ADDRESS | 0xC8 |
94 */
95
96 /*! @name LTC2943 I2C Address
97 @{ */
98
99 #define LTC2943_I2C_ADDRESS 0x64
100 #define LTC2943_I2C_ALERT_RESPONSE 0x0C
101 //! @}
102
103
104 /*!
105 | Name | Value |
106 | :------------------------------------------------ | :---: |
107 | LTC2943_STATUS_REG | 0x00 |
108 | LTC2943_CONTROL_REG | 0x01 |
109 | LTC2943_ACCUM_CHARGE_MSB_REG | 0x02 |
110 | LTC2943_ACCUM_CHARGE_LSB_REG | 0x03 |
111 | LTC2943_CHARGE_THRESH_HIGH_MSB_REG | 0x04 |
112 | LTC2943_CHARGE_THRESH_HIGH_LSB_REG | 0x05 |
113 | LTC2943_CHARGE_THRESH_LOW_MSB_REG | 0x06 |
114 | LTC2943_CHARGE_THRESH_LOW_LSB_REG | 0x07 |
115 | LTC2943_VOLTAGE_MSB_REG | 0x08 |
116 | LTC2943_VOLTAGE_LSB_REG | 0x09 |
117 | LTC2943_VOLTAGE_THRESH_HIGH_MSB_REG | 0x0A |
118 | LTC2943_VOLTAGE_THRESH_HIGH_LSB_REG | 0x0B |
119 | LTC2943_VOLTAGE_THRESH_LOW_MSB_REG | 0x0C |
120 | LTC2943_VOLTAGE_THRESH_LOW_LSB_REG | 0x0D |
121 | LTC2943_CURRENT_MSB_REG | 0x0E |
122 | LTC2943_CURRENT_LSB_REG | 0x0F |
123 | LTC2943_CURRENT_THRESH_HIGH_MSB_REG | 0x10 |
124 | LTC2943_CURRENT_THRESH_HIGH_LSB_REG | 0x11 |
125 | LTC2943_CURRENT_THRESH_LOW_MSB_REG | 0x12 |
126 | LTC2943_CURRENT_THRESH_LOW_LSB_REG | 0x13 |
127 | LTC2943_TEMPERATURE_MSB_REG | 0x14 |
128 | LTC2943_TEMPERATURE_LSB_REG | 0x15 |
129 | LTC2943_TEMPERATURE_THRESH_HIGH_REG | 0x16 |
130 | LTC2943_TEMPERATURE_THRESH_LOW_REG | 0x17 |
131 */
132
133 /*! @name Registers
134 @{ */
135 // Registers
136 #define LTC2943_STATUS_REG 0x00
137 #define LTC2943_CONTROL_REG 0x01
138 #define LTC2943_ACCUM_CHARGE_MSB_REG 0x02
139 #define LTC2943_ACCUM_CHARGE_LSB_REG 0x03
140 #define LTC2943_CHARGE_THRESH_HIGH_MSB_REG 0x04
141 #define LTC2943_CHARGE_THRESH_HIGH_LSB_REG 0x05
142 #define LTC2943_CHARGE_THRESH_LOW_MSB_REG 0x06
143 #define LTC2943_CHARGE_THRESH_LOW_LSB_REG 0x07
144 #define LTC2943_VOLTAGE_MSB_REG 0x08
145 #define LTC2943_VOLTAGE_LSB_REG 0x09
146 #define LTC2943_VOLTAGE_THRESH_HIGH_MSB_REG 0x0A
147 #define LTC2943_VOLTAGE_THRESH_HIGH_LSB_REG 0x0B
148 #define LTC2943_VOLTAGE_THRESH_LOW_MSB_REG 0x0C
149 #define LTC2943_VOLTAGE_THRESH_LOW_LSB_REG 0x0D
150 #define LTC2943_CURRENT_MSB_REG 0x0E
151 #define LTC2943_CURRENT_LSB_REG 0x0F
152 #define LTC2943_CURRENT_THRESH_HIGH_MSB_REG 0x10
153 #define LTC2943_CURRENT_THRESH_HIGH_LSB_REG 0x11
154 #define LTC2943_CURRENT_THRESH_LOW_MSB_REG 0x12
155 #define LTC2943_CURRENT_THRESH_LOW_LSB_REG 0x13
156 #define LTC2943_TEMPERATURE_MSB_REG 0x14
157 #define LTC2943_TEMPERATURE_LSB_REG 0x15
158 #define LTC2943_TEMPERATURE_THRESH_HIGH_REG 0x16
159 #define LTC2943_TEMPERATURE_THRESH_LOW_REG 0x17
160 //! @}
161
162 /*!
163 | Command Codes | Value |
164 | :-------------------------------------------- | :-------: |
165 | LTC2943_AUTOMATIC_MODE | 0xC0 |
166 | LTC2943_SCAN_MODE | 0x80 |
167 | LTC2943_MANUAL_MODE | 0x40 |
168 | LTC2943_SLEEP_MODE | 0x00 |
169 | LTC2943_PRESCALAR_M_1 | 0x00 |
170 | LTC2943_PRESCALAR_M_4 | 0x08 |
171 | LTC2943_PRESCALAR_M_16 | 0x10 |
172 | LTC2943_PRESCALAR_M_64 | 0x18 |
173 | LTC2943_PRESCALAR_M_256 | 0x20 |
174 | LTC2943_PRESCALAR_M_1024 | 0x28 |
175 | LTC2943_PRESCALAR_M_4096 | 0x30 |
176 | LTC2943_PRESCALAR_M_4096_2 | 0x31 |
177 | LTC2943_ALERT_MODE | 0x04 |
178 | LTC2943_CHARGE_COMPLETE_MODE | 0x02 |
179 | LTC2943_DISABLE_ALCC_PIN | 0x00 |
180 | LTC2943_SHUTDOWN_MODE | 0x01 |
181 */
182
183 /*! @name Command Codes
184 @{ */
185 // Command Codes
186 #define LTC2943_AUTOMATIC_MODE 0xC0
187 #define LTC2943_SCAN_MODE 0x80
188 #define LTC2943_MANUAL_MODE 0x40
189 #define LTC2943_SLEEP_MODE 0x00
190
191 #define LTC2943_PRESCALAR_M_1 0x00
192 #define LTC2943_PRESCALAR_M_4 0x08
193 #define LTC2943_PRESCALAR_M_16 0x10
194 #define LTC2943_PRESCALAR_M_64 0x18
195 #define LTC2943_PRESCALAR_M_256 0x20
196 #define LTC2943_PRESCALAR_M_1024 0x28
197 #define LTC2943_PRESCALAR_M_4096 0x30
198 #define LTC2943_PRESCALAR_M_4096_2 0x31
199
200 #define LTC2943_ALERT_MODE 0x04
201 #define LTC2943_CHARGE_COMPLETE_MODE 0x02
202
203 #define LTC2943_DISABLE_ALCC_PIN 0x00
204 #define LTC2943_SHUTDOWN_MODE 0x01
205
206 //! @}
207
208 /*!
209 | Conversion Constants | Value |
210 | :------------------------------------------------ | :------: |
211 | LTC2943_CHARGE_lsb | 0.34 mAh|
212 | LTC2943_VOLTAGE_lsb | 1.44 mV|
213 | LTC2943_CURRENT_lsb | 29.3 uV|
214 | LTC2943_TEMPERATURE_lsb | 0.25 C|
215 | LTC2943_FULLSCALE_VOLTAGE | 23.6 V|
216 | LTC2943_FULLSCALE_CURRENT | 60 mV|
217 | LTC2943_FULLSCALE_TEMPERATURE | 510 K|
218
219 */
220 /*! @name Conversion Constants
221 @{ */
222 const float LTC2943_CHARGE_lsb = 0.34E-3;
223 const float LTC2943_VOLTAGE_lsb = 1.44E-3;
224 const float LTC2943_CURRENT_lsb = 29.3E-6;
225 const float LTC2943_TEMPERATURE_lsb = 0.25;
226 const float LTC2943_FULLSCALE_VOLTAGE = 23.6;
227 const float LTC2943_FULLSCALE_CURRENT = 60E-3;
228 const float LTC2943_FULLSCALE_TEMPERATURE = 510;
229 //! @}
230
231 //! @}
232
233
234 //! Write an 8-bit code to the LTC2943.
235 //! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
236 int8_t LTC2943_write(uint8_t i2c_address, //!< Register address for the LTC2943
237 uint8_t adc_command, //!< The "command byte" for the LTC2943
238 uint8_t code //!< Value that will be written to the register.
239 );
240
241 //! Write a 16-bit code to the LTC2943.
242 //! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
243 int8_t LTC2943_write_16_bits(uint8_t i2c_address, //!< Register address for the LTC2943
244 uint8_t adc_command, //!< The "command byte" for the LTC2943
245 uint16_t code //!< Value that will be written to the register.
246 );
247
248
249 //! Reads an 8-bit adc_code from LTC2943
250 //! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
251 int8_t LTC2943_read(uint8_t i2c_address, //!< Register address for the LTC2943
252 uint8_t adc_command, //!< The "command byte" for the LTC2943
253 uint8_t *adc_code //!< Value that will be read from the register.
254 );
255
256 //! Reads a 16-bit adc_code from LTC2943
257 //! @return The function returns the state of the acknowledge bit after the I2C address write. 0=acknowledge, 1=no acknowledge.
258 int8_t LTC2943_read_16_bits(uint8_t i2c_address, //!< Register address for the LTC2943
259 uint8_t adc_command, //!< The "command byte" for the LTC2943
260 uint16_t *adc_code //!< Value that will be read from the register.
261 );
262
263
264 //! Calculate the LTC2943 charge in Coulombs
265 //! @return Returns the Coulombs of charge in the ACR register.
266 float LTC2943_code_to_coulombs(uint16_t adc_code, //!< The RAW ADC value
267 float resistor, //!< The sense resistor value
268 uint16_t prescalar //!< The prescalar value
269 );
270
271 //! Calculate the LTC2943 charge in mAh
272 //! @return Returns the Coulombs of charge in the ACR register.
273 float LTC2943_code_to_mAh(uint16_t adc_code, //!< The RAW ADC value
274 float resistor, //!< The sense resistor value
275 uint16_t prescalar //!< The prescalar value
276 );
277
278 //! Calculate the LTC2943 SENSE+ voltage
279 //! @return Returns the SENSE+ Voltage in Volts
280 float LTC2943_code_to_voltage(uint16_t adc_code //!< The RAW ADC value
281 );
282
283 //! Calculate the LTC2943 current with a sense resistor
284 //! @return Returns the current through the sense resisor
285 float LTC2943_code_to_current(uint16_t adc_code, //!< The RAW ADC value
286 float resistor //!< The sense resistor value
287 );
288
289 //! Calculate the LTC2943 temperature
290 //! @return Returns the temperature in Kelvin
291 float LTC2943_code_to_kelvin_temperature(uint16_t adc_code //!< The RAW ADC value
292 );
293
294 //! Calculate the LTC2943 temperature
295 //! @return Returns the temperature in Celcius
296 float LTC2943_code_to_celcius_temperature(uint16_t adc_code //!< The RAW ADC value
297 );
298
299 #endif // LTC2943_H
LTC2943_VOLTAGE_lsb
const float LTC2943_VOLTAGE_lsb
Definition: LTC2943.h:223
i2c_address
uint8_t i2c_address
adc_command
static uint8_t adc_command
Definition: DC2071AA.ino:111
LTC2943_read
int8_t LTC2943_read(uint8_t i2c_address, uint8_t adc_command, uint8_t *adc_code)
Reads an 8-bit adc_code from LTC2943.
Definition: LTC2943.cpp:101
resistor
const float resistor
resistor value on demo board
Definition: DC1496BB.ino:116
LTC2943_code_to_kelvin_temperature
float LTC2943_code_to_kelvin_temperature(uint16_t adc_code)
Calculate the LTC2943 temperature.
Definition: LTC2943.cpp:156
LTC2943_write
int8_t LTC2943_write(uint8_t i2c_address, uint8_t adc_command, uint8_t code)
Write an 8-bit code to the LTC2943.
Definition: LTC2943.cpp:80
LTC2943_write_16_bits
int8_t LTC2943_write_16_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t code)
Write a 16-bit code to the LTC2943.
Definition: LTC2943.cpp:91
LTC2943_code_to_current
float LTC2943_code_to_current(uint16_t adc_code, float resistor)
Calculate the LTC2943 current with a sense resistor.
Definition: LTC2943.cpp:148
LTC2943_FULLSCALE_CURRENT
const float LTC2943_FULLSCALE_CURRENT
Definition: LTC2943.h:227
LTC2943_code_to_celcius_temperature
float LTC2943_code_to_celcius_temperature(uint16_t adc_code)
Calculate the LTC2943 temperature.
Definition: LTC2943.cpp:164
LTC2943_code_to_coulombs
float LTC2943_code_to_coulombs(uint16_t adc_code, float resistor, uint16_t prescalar)
Calculate the LTC2943 charge in Coulombs.
Definition: LTC2943.cpp:123
LTC2943_TEMPERATURE_lsb
const float LTC2943_TEMPERATURE_lsb
Definition: LTC2943.h:225
LTC2943_code_to_mAh
float LTC2943_code_to_mAh(uint16_t adc_code, float resistor, uint16_t prescalar)
Calculate the LTC2943 charge in mAh.
Definition: LTC2943.cpp:132
LTC2943_code_to_voltage
float LTC2943_code_to_voltage(uint16_t adc_code)
Calculate the LTC2943 SENSE+ voltage.
Definition: LTC2943.cpp:140
LTC2943_CHARGE_lsb
const float LTC2943_CHARGE_lsb
Definition: LTC2943.h:222
LTC2943_FULLSCALE_TEMPERATURE
const float LTC2943_FULLSCALE_TEMPERATURE
Definition: LTC2943.h:228
E
const int16_t E
Definition: LTC2492_Thermocouple_Meter.ino:101
LTC2943_FULLSCALE_VOLTAGE
const float LTC2943_FULLSCALE_VOLTAGE
Definition: LTC2943.h:226
LTC2943_CURRENT_lsb
const float LTC2943_CURRENT_lsb
Definition: LTC2943.h:224
adc_code
static uint32_t adc_code
Definition: DC2071AA.ino:113
LTC2943_read_16_bits
int8_t LTC2943_read_16_bits(uint8_t i2c_address, uint8_t adc_command, uint16_t *adc_code)
Reads a 16-bit adc_code from LTC2943.
Definition: LTC2943.cpp:112