LTC6811

Committer:
roger5641
Date:
Sun Nov 12 01:21:48 2017 +0000
Revision:
0:910d40021983
ver1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
roger5641 0:910d40021983 1 /*!
roger5641 0:910d40021983 2 LTC6811-1: Multicell Battery Monitor
roger5641 0:910d40021983 3 @verbatim
roger5641 0:910d40021983 4 The LTC6811 is a 3rd generation multicell battery stack
roger5641 0:910d40021983 5 monitor that measures up to 12 series connected battery
roger5641 0:910d40021983 6 cells with a total measurement error of less than 1.2mV. The
roger5641 0:910d40021983 7 cell measurement range of 0V to 5V makes the LTC6811
roger5641 0:910d40021983 8 suitable for most battery chemistries. All 12 cell voltages
roger5641 0:910d40021983 9 can be captured in 290uS, and lower data acquisition rates
roger5641 0:910d40021983 10 can be selected for high noise reduction.
roger5641 0:910d40021983 11
roger5641 0:910d40021983 12 Using the LTC6811-1, multiple devices are connected in
roger5641 0:910d40021983 13 a daisy-chain with one host processor connection for all
roger5641 0:910d40021983 14 devices.
roger5641 0:910d40021983 15 @endverbatim
roger5641 0:910d40021983 16
roger5641 0:910d40021983 17 http://www.linear.com/product/LTC6811-1
roger5641 0:910d40021983 18
roger5641 0:910d40021983 19 http://www.linear.com/product/LTC6811-1#demoboards
roger5641 0:910d40021983 20
roger5641 0:910d40021983 21 REVISION HISTORY
roger5641 0:910d40021983 22 $Revision: 7139 $
roger5641 0:910d40021983 23 $Date: 2017-06-01 13:55:14 -0700 (Thu, 01 Jun 2017) $
roger5641 0:910d40021983 24
roger5641 0:910d40021983 25 Copyright (c) 2017, Linear Technology Corp.(LTC)
roger5641 0:910d40021983 26 All rights reserved.
roger5641 0:910d40021983 27
roger5641 0:910d40021983 28 Redistribution and use in source and binary forms, with or without
roger5641 0:910d40021983 29 modification, are permitted provided that the following conditions are met:
roger5641 0:910d40021983 30
roger5641 0:910d40021983 31 1. Redistributions of source code must retain the above copyright notice, this
roger5641 0:910d40021983 32 list of conditions and the following disclaimer.
roger5641 0:910d40021983 33 2. Redistributions in binary form must reproduce the above copyright notice,
roger5641 0:910d40021983 34 this list of conditions and the following disclaimer in the documentation
roger5641 0:910d40021983 35 and/or other materials provided with the distribution.
roger5641 0:910d40021983 36
roger5641 0:910d40021983 37 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
roger5641 0:910d40021983 38 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
roger5641 0:910d40021983 39 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
roger5641 0:910d40021983 40 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
roger5641 0:910d40021983 41 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
roger5641 0:910d40021983 42 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
roger5641 0:910d40021983 43 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
roger5641 0:910d40021983 44 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
roger5641 0:910d40021983 45 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
roger5641 0:910d40021983 46 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
roger5641 0:910d40021983 47
roger5641 0:910d40021983 48 The views and conclusions contained in the software and documentation are those
roger5641 0:910d40021983 49 of the authors and should not be interpreted as representing official policies,
roger5641 0:910d40021983 50 either expressed or implied, of Linear Technology Corp.
roger5641 0:910d40021983 51
roger5641 0:910d40021983 52 The Linear Technology Linduino is not affiliated with the official Arduino team.
roger5641 0:910d40021983 53 However, the Linduino is only possible because of the Arduino team's commitment
roger5641 0:910d40021983 54 to the open-source community. Please, visit http://www.arduino.cc and
roger5641 0:910d40021983 55 http://store.arduino.cc , and consider a purchase that will help fund their
roger5641 0:910d40021983 56 ongoing work.
roger5641 0:910d40021983 57
roger5641 0:910d40021983 58 Copyright 2017 Linear Technology Corp. (LTC)
roger5641 0:910d40021983 59 ***********************************************************/
roger5641 0:910d40021983 60
roger5641 0:910d40021983 61 //! @ingroup BMS
roger5641 0:910d40021983 62 //! @{
roger5641 0:910d40021983 63 //! @defgroup LTC6811-1 LTC6811-1: Multicell Battery Monitor
roger5641 0:910d40021983 64 //! @}
roger5641 0:910d40021983 65
roger5641 0:910d40021983 66 /*! @file
roger5641 0:910d40021983 67 @ingroup LTC6811-1
roger5641 0:910d40021983 68 Library for LTC6811-1 Multicell Battery Monitor
roger5641 0:910d40021983 69 */
roger5641 0:910d40021983 70
roger5641 0:910d40021983 71 #include "stdint.h"
roger5641 0:910d40021983 72 #include "LTC6811.h"
roger5641 0:910d40021983 73
roger5641 0:910d40021983 74
roger5641 0:910d40021983 75 void LTC6811_init_reg_limits(uint8_t total_ic, cell_asic ic[])
roger5641 0:910d40021983 76 {
roger5641 0:910d40021983 77 for (uint8_t cic=0; cic<total_ic; cic++)
roger5641 0:910d40021983 78 {
roger5641 0:910d40021983 79 ic[cic].ic_reg.cell_channels=12;
roger5641 0:910d40021983 80 ic[cic].ic_reg.stat_channels=4;
roger5641 0:910d40021983 81 ic[cic].ic_reg.aux_channels=6;
roger5641 0:910d40021983 82 ic[cic].ic_reg.num_cv_reg=4;
roger5641 0:910d40021983 83 ic[cic].ic_reg.num_gpio_reg=2;
roger5641 0:910d40021983 84 ic[cic].ic_reg.num_stat_reg=3;
roger5641 0:910d40021983 85 }
roger5641 0:910d40021983 86 }
roger5641 0:910d40021983 87
roger5641 0:910d40021983 88 /*
roger5641 0:910d40021983 89 Starts cell voltage conversion
roger5641 0:910d40021983 90 */
roger5641 0:910d40021983 91 void LTC6811_adcv(
roger5641 0:910d40021983 92 uint8_t MD, //ADC Mode
roger5641 0:910d40021983 93 uint8_t DCP, //Discharge Permit
roger5641 0:910d40021983 94 uint8_t CH //Cell Channels to be measured
roger5641 0:910d40021983 95 )
roger5641 0:910d40021983 96 {
roger5641 0:910d40021983 97 LTC681x_adcv(MD,DCP,CH);
roger5641 0:910d40021983 98 }
roger5641 0:910d40021983 99
roger5641 0:910d40021983 100 //Starts cell voltage and SOC conversion
roger5641 0:910d40021983 101 void LTC6811_adcvsc(
roger5641 0:910d40021983 102 uint8_t MD, //ADC Mode
roger5641 0:910d40021983 103 uint8_t DCP //Discharge Permit
roger5641 0:910d40021983 104 )
roger5641 0:910d40021983 105 {
roger5641 0:910d40021983 106 LTC681x_adcvsc(MD,DCP);
roger5641 0:910d40021983 107 }
roger5641 0:910d40021983 108
roger5641 0:910d40021983 109 // Starts cell voltage and GPIO 1&2 conversion
roger5641 0:910d40021983 110 void LTC6811_adcvax(
roger5641 0:910d40021983 111 uint8_t MD, //ADC Mode
roger5641 0:910d40021983 112 uint8_t DCP //Discharge Permit
roger5641 0:910d40021983 113 )
roger5641 0:910d40021983 114 {
roger5641 0:910d40021983 115 LTC681x_adcvax(MD,DCP);
roger5641 0:910d40021983 116 }
roger5641 0:910d40021983 117
roger5641 0:910d40021983 118 //Starts cell voltage overlap conversion
roger5641 0:910d40021983 119 void LTC6811_adol(
roger5641 0:910d40021983 120 uint8_t MD, //ADC Mode
roger5641 0:910d40021983 121 uint8_t DCP //Discharge Permit
roger5641 0:910d40021983 122 )
roger5641 0:910d40021983 123 {
roger5641 0:910d40021983 124 LTC681x_adol(MD,DCP);
roger5641 0:910d40021983 125 }
roger5641 0:910d40021983 126
roger5641 0:910d40021983 127 //Starts cell voltage self test conversion
roger5641 0:910d40021983 128 void LTC6811_cvst(
roger5641 0:910d40021983 129 uint8_t MD, //ADC Mode
roger5641 0:910d40021983 130 uint8_t ST //Self Test
roger5641 0:910d40021983 131 )
roger5641 0:910d40021983 132 {
roger5641 0:910d40021983 133 LTC681x_cvst(MD,ST);
roger5641 0:910d40021983 134 }
roger5641 0:910d40021983 135
roger5641 0:910d40021983 136 //Start an Auxiliary Register Self Test Conversion
roger5641 0:910d40021983 137 void LTC6811_axst(
roger5641 0:910d40021983 138 uint8_t MD, //ADC Mode
roger5641 0:910d40021983 139 uint8_t ST //Self Test
roger5641 0:910d40021983 140 )
roger5641 0:910d40021983 141 {
roger5641 0:910d40021983 142 LTC681x_axst(MD,ST);
roger5641 0:910d40021983 143 }
roger5641 0:910d40021983 144
roger5641 0:910d40021983 145 //Start a Status Register Self Test Conversion
roger5641 0:910d40021983 146 void LTC6811_statst(
roger5641 0:910d40021983 147 uint8_t MD, //ADC Mode
roger5641 0:910d40021983 148 uint8_t ST //Self Test
roger5641 0:910d40021983 149 )
roger5641 0:910d40021983 150 {
roger5641 0:910d40021983 151 LTC681x_statst(MD,ST);
roger5641 0:910d40021983 152 }
roger5641 0:910d40021983 153
roger5641 0:910d40021983 154 //Sends the poll adc command
roger5641 0:910d40021983 155 uint8_t LTC6811_pladc()
roger5641 0:910d40021983 156 {
roger5641 0:910d40021983 157 return(LTC681x_pladc());
roger5641 0:910d40021983 158 }
roger5641 0:910d40021983 159
roger5641 0:910d40021983 160 //This function will block operation until the ADC has finished it's conversion
roger5641 0:910d40021983 161 uint32_t LTC6811_pollAdc()
roger5641 0:910d40021983 162 {
roger5641 0:910d40021983 163 return(LTC681x_pollAdc());
roger5641 0:910d40021983 164 }
roger5641 0:910d40021983 165
roger5641 0:910d40021983 166 //Start a GPIO and Vref2 Conversion
roger5641 0:910d40021983 167 void LTC6811_adax(
roger5641 0:910d40021983 168 uint8_t MD, //ADC Mode
roger5641 0:910d40021983 169 uint8_t CHG //GPIO Channels to be measured)
roger5641 0:910d40021983 170 )
roger5641 0:910d40021983 171 {
roger5641 0:910d40021983 172 LTC681x_adax(MD,CHG);
roger5641 0:910d40021983 173 }
roger5641 0:910d40021983 174
roger5641 0:910d40021983 175 //Start an GPIO Redundancy test
roger5641 0:910d40021983 176 void LTC6811_adaxd(
roger5641 0:910d40021983 177 uint8_t MD, //ADC Mode
roger5641 0:910d40021983 178 uint8_t CHG //GPIO Channels to be measured)
roger5641 0:910d40021983 179 )
roger5641 0:910d40021983 180 {
roger5641 0:910d40021983 181 LTC681x_adaxd(MD,CHG);
roger5641 0:910d40021983 182 }
roger5641 0:910d40021983 183
roger5641 0:910d40021983 184 //Start a Status ADC Conversion
roger5641 0:910d40021983 185 void LTC6811_adstat(
roger5641 0:910d40021983 186 uint8_t MD, //ADC Mode
roger5641 0:910d40021983 187 uint8_t CHST //GPIO Channels to be measured
roger5641 0:910d40021983 188 )
roger5641 0:910d40021983 189 {
roger5641 0:910d40021983 190 LTC681x_adstat(MD,CHST);
roger5641 0:910d40021983 191 }
roger5641 0:910d40021983 192
roger5641 0:910d40021983 193 // Start a Status register redundancy test Conversion
roger5641 0:910d40021983 194 void LTC6811_adstatd(
roger5641 0:910d40021983 195 uint8_t MD, //ADC Mode
roger5641 0:910d40021983 196 uint8_t CHST //GPIO Channels to be measured
roger5641 0:910d40021983 197 )
roger5641 0:910d40021983 198 {
roger5641 0:910d40021983 199 LTC681x_adstatd(MD,CHST);
roger5641 0:910d40021983 200 }
roger5641 0:910d40021983 201
roger5641 0:910d40021983 202
roger5641 0:910d40021983 203 // Start an open wire Conversion
roger5641 0:910d40021983 204 void LTC6811_adow(
roger5641 0:910d40021983 205 uint8_t MD, //ADC Mode
roger5641 0:910d40021983 206 uint8_t PUP //Discharge Permit
roger5641 0:910d40021983 207 )
roger5641 0:910d40021983 208 {
roger5641 0:910d40021983 209 LTC681x_adow(MD,PUP);
roger5641 0:910d40021983 210 }
roger5641 0:910d40021983 211
roger5641 0:910d40021983 212 // Reads and parses the LTC6811 cell voltage registers.
roger5641 0:910d40021983 213 uint8_t LTC6811_rdcv(uint8_t reg, // Controls which cell voltage register is read back.
roger5641 0:910d40021983 214 uint8_t total_ic, // the number of ICs in the system
roger5641 0:910d40021983 215 cell_asic ic[] // Array of the parsed cell codes
roger5641 0:910d40021983 216 )
roger5641 0:910d40021983 217 {
roger5641 0:910d40021983 218
roger5641 0:910d40021983 219 int8_t pec_error = 0;
roger5641 0:910d40021983 220 pec_error = LTC681x_rdcv(reg,total_ic,ic);
roger5641 0:910d40021983 221 return(pec_error);
roger5641 0:910d40021983 222 }
roger5641 0:910d40021983 223
roger5641 0:910d40021983 224 /*
roger5641 0:910d40021983 225 The function is used
roger5641 0:910d40021983 226 to read the parsed GPIO codes of the LTC6811. This function will send the requested
roger5641 0:910d40021983 227 read commands parse the data and store the gpio voltages in aux_codes variable
roger5641 0:910d40021983 228 */
roger5641 0:910d40021983 229 int8_t LTC6811_rdaux(uint8_t reg, //Determines which GPIO voltage register is read back.
roger5641 0:910d40021983 230 uint8_t total_ic,//the number of ICs in the system
roger5641 0:910d40021983 231 cell_asic ic[]//A two dimensional array of the gpio voltage codes.
roger5641 0:910d40021983 232 )
roger5641 0:910d40021983 233 {
roger5641 0:910d40021983 234 int8_t pec_error = 0;
roger5641 0:910d40021983 235 LTC681x_rdaux(reg,total_ic,ic);
roger5641 0:910d40021983 236 return (pec_error);
roger5641 0:910d40021983 237 }
roger5641 0:910d40021983 238
roger5641 0:910d40021983 239 /*
roger5641 0:910d40021983 240 Reads and parses the LTC6811 stat registers.
roger5641 0:910d40021983 241 The function is used
roger5641 0:910d40021983 242 to read the parsed stat codes of the LTC6811. This function will send the requested
roger5641 0:910d40021983 243 read commands parse the data and store the stat voltages in stat_codes variable
roger5641 0:910d40021983 244 */
roger5641 0:910d40021983 245 int8_t LTC6811_rdstat(uint8_t reg, //Determines which Stat register is read back.
roger5641 0:910d40021983 246 uint8_t total_ic,//the number of ICs in the system
roger5641 0:910d40021983 247 cell_asic ic[]
roger5641 0:910d40021983 248 )
roger5641 0:910d40021983 249 {
roger5641 0:910d40021983 250 int8_t pec_error = 0;
roger5641 0:910d40021983 251 pec_error = LTC681x_rdstat(reg,total_ic,ic);
roger5641 0:910d40021983 252 return (pec_error);
roger5641 0:910d40021983 253 }
roger5641 0:910d40021983 254
roger5641 0:910d40021983 255 /*
roger5641 0:910d40021983 256 The command clears the cell voltage registers and intiallizes
roger5641 0:910d40021983 257 all values to 1. The register will read back hexadecimal 0xFF
roger5641 0:910d40021983 258 after the command is sent.
roger5641 0:910d40021983 259 */
roger5641 0:910d40021983 260 void LTC6811_clrcell()
roger5641 0:910d40021983 261 {
roger5641 0:910d40021983 262 LTC681x_clrcell();
roger5641 0:910d40021983 263 }
roger5641 0:910d40021983 264
roger5641 0:910d40021983 265 /*
roger5641 0:910d40021983 266 The command clears the Auxiliary registers and initializes
roger5641 0:910d40021983 267 all values to 1. The register will read back hexadecimal 0xFF
roger5641 0:910d40021983 268 after the command is sent.
roger5641 0:910d40021983 269 */
roger5641 0:910d40021983 270 void LTC6811_clraux()
roger5641 0:910d40021983 271 {
roger5641 0:910d40021983 272 LTC681x_clraux();
roger5641 0:910d40021983 273 }
roger5641 0:910d40021983 274
roger5641 0:910d40021983 275 /*
roger5641 0:910d40021983 276 The command clears the Stat registers and intiallizes
roger5641 0:910d40021983 277 all values to 1. The register will read back hexadecimal 0xFF
roger5641 0:910d40021983 278 after the command is sent.
roger5641 0:910d40021983 279
roger5641 0:910d40021983 280 */
roger5641 0:910d40021983 281 void LTC6811_clrstat()
roger5641 0:910d40021983 282 {
roger5641 0:910d40021983 283 LTC681x_clrstat();
roger5641 0:910d40021983 284 }
roger5641 0:910d40021983 285
roger5641 0:910d40021983 286 /*
roger5641 0:910d40021983 287 The command clears the Sctrl registers and initializes
roger5641 0:910d40021983 288 all values to 0. The register will read back hexadecimal 0x00
roger5641 0:910d40021983 289 after the command is sent.
roger5641 0:910d40021983 290 */
roger5641 0:910d40021983 291 void LTC6811_clrsctrl()
roger5641 0:910d40021983 292 {
roger5641 0:910d40021983 293 LTC681x_clrsctrl();
roger5641 0:910d40021983 294 }
roger5641 0:910d40021983 295
roger5641 0:910d40021983 296 //Starts the Mux Decoder diagnostic self test
roger5641 0:910d40021983 297 void LTC6811_diagn()
roger5641 0:910d40021983 298 {
roger5641 0:910d40021983 299 LTC681x_diagn();
roger5641 0:910d40021983 300 }
roger5641 0:910d40021983 301
roger5641 0:910d40021983 302 /*
roger5641 0:910d40021983 303 This command will write the configuration registers of the LTC6811-1s
roger5641 0:910d40021983 304 connected in a daisy chain stack. The configuration is written in descending
roger5641 0:910d40021983 305 order so the last device's configuration is written first.
roger5641 0:910d40021983 306 */
roger5641 0:910d40021983 307 void LTC6811_wrcfg(uint8_t total_ic, //The number of ICs being written to
roger5641 0:910d40021983 308 cell_asic ic[] //A two dimensional array of the configuration data that will be written
roger5641 0:910d40021983 309 )
roger5641 0:910d40021983 310 {
roger5641 0:910d40021983 311 LTC681x_wrcfg(total_ic,ic);
roger5641 0:910d40021983 312 }
roger5641 0:910d40021983 313
roger5641 0:910d40021983 314
roger5641 0:910d40021983 315 /*
roger5641 0:910d40021983 316 Reads configuration registers of a LTC6811 daisy chain
roger5641 0:910d40021983 317 */
roger5641 0:910d40021983 318 int8_t LTC6811_rdcfg(uint8_t total_ic, //Number of ICs in the system
roger5641 0:910d40021983 319 cell_asic ic[] //A two dimensional array that the function stores the read configuration data.
roger5641 0:910d40021983 320 )
roger5641 0:910d40021983 321 {
roger5641 0:910d40021983 322 int8_t pec_error = 0;
roger5641 0:910d40021983 323 pec_error = LTC681x_rdcfg(total_ic,ic);
roger5641 0:910d40021983 324 return(pec_error);
roger5641 0:910d40021983 325 }
roger5641 0:910d40021983 326
roger5641 0:910d40021983 327 /*
roger5641 0:910d40021983 328 Writes the pwm registers of a LTC6811 daisy chain
roger5641 0:910d40021983 329 */
roger5641 0:910d40021983 330 void LTC6811_wrpwm(uint8_t total_ic,
roger5641 0:910d40021983 331 uint8_t pwmReg, //The number of ICs being written to
roger5641 0:910d40021983 332 cell_asic ic[] //A two dimensional array of the configuration data that will be written
roger5641 0:910d40021983 333 )
roger5641 0:910d40021983 334 {
roger5641 0:910d40021983 335 LTC681x_wrpwm(total_ic,pwmReg,ic);
roger5641 0:910d40021983 336 }
roger5641 0:910d40021983 337
roger5641 0:910d40021983 338
roger5641 0:910d40021983 339 /*
roger5641 0:910d40021983 340 Reads pwm registers of a LTC6811 daisy chain
roger5641 0:910d40021983 341 */
roger5641 0:910d40021983 342 int8_t LTC6811_rdpwm(uint8_t total_ic, //Number of ICs in the system
roger5641 0:910d40021983 343 uint8_t pwmReg,
roger5641 0:910d40021983 344 cell_asic ic[] //A two dimensional array that the function stores the read configuration data.
roger5641 0:910d40021983 345 )
roger5641 0:910d40021983 346 {
roger5641 0:910d40021983 347 int8_t pec_error =0;
roger5641 0:910d40021983 348 pec_error = LTC681x_rdpwm(total_ic,pwmReg,ic);
roger5641 0:910d40021983 349 return(pec_error);
roger5641 0:910d40021983 350 }
roger5641 0:910d40021983 351
roger5641 0:910d40021983 352 /*
roger5641 0:910d40021983 353 Writes the COMM registers of a LTC6811 daisy chain
roger5641 0:910d40021983 354 */
roger5641 0:910d40021983 355 void LTC6811_wrcomm(uint8_t total_ic, //The number of ICs being written to
roger5641 0:910d40021983 356 cell_asic ic[] //A two dimensional array of the comm data that will be written
roger5641 0:910d40021983 357 )
roger5641 0:910d40021983 358 {
roger5641 0:910d40021983 359 LTC681x_wrcomm(total_ic,ic);
roger5641 0:910d40021983 360 }
roger5641 0:910d40021983 361
roger5641 0:910d40021983 362 /*
roger5641 0:910d40021983 363 Reads COMM registers of a LTC6811 daisy chain
roger5641 0:910d40021983 364 */
roger5641 0:910d40021983 365 int8_t LTC6811_rdcomm(uint8_t total_ic, //Number of ICs in the system
roger5641 0:910d40021983 366 cell_asic ic[] //A two dimensional array that the function stores the read configuration data.
roger5641 0:910d40021983 367 )
roger5641 0:910d40021983 368 {
roger5641 0:910d40021983 369 int8_t pec_error = 0;
roger5641 0:910d40021983 370 LTC681x_rdcomm(total_ic, ic);
roger5641 0:910d40021983 371 return(pec_error);
roger5641 0:910d40021983 372 }
roger5641 0:910d40021983 373
roger5641 0:910d40021983 374 /*
roger5641 0:910d40021983 375 Shifts data in COMM register out over LTC6811 SPI/I2C port
roger5641 0:910d40021983 376 */
roger5641 0:910d40021983 377 void LTC6811_stcomm()
roger5641 0:910d40021983 378 {
roger5641 0:910d40021983 379 LTC681x_stcomm();
roger5641 0:910d40021983 380 }
roger5641 0:910d40021983 381
roger5641 0:910d40021983 382 //Helper function to set discharge bit in CFG register
roger5641 0:910d40021983 383 void LTC6811_set_discharge(int Cell, uint8_t total_ic, cell_asic ic[])
roger5641 0:910d40021983 384 {
roger5641 0:910d40021983 385 for (int i=0; i<total_ic; i++)
roger5641 0:910d40021983 386 {
roger5641 0:910d40021983 387 if (Cell<9)
roger5641 0:910d40021983 388 {
roger5641 0:910d40021983 389 ic[i].config.tx_data[4] = ic[i].config.tx_data[4] | (1<<(Cell-1));
roger5641 0:910d40021983 390 }
roger5641 0:910d40021983 391 else if (Cell < 13)
roger5641 0:910d40021983 392 {
roger5641 0:910d40021983 393 ic[i].config.tx_data[5] = ic[i].config.tx_data[5] | (1<<(Cell-9));
roger5641 0:910d40021983 394 }
roger5641 0:910d40021983 395 }
roger5641 0:910d40021983 396 }
roger5641 0:910d40021983 397
roger5641 0:910d40021983 398 // Runs the Digital Filter Self Test
roger5641 0:910d40021983 399 int16_t LTC6811_run_cell_adc_st(uint8_t adc_reg,uint8_t total_ic, cell_asic ic[])
roger5641 0:910d40021983 400 {
roger5641 0:910d40021983 401 int16_t error = 0;
roger5641 0:910d40021983 402 error = LTC681x_run_cell_adc_st(adc_reg,total_ic,ic);
roger5641 0:910d40021983 403 return(error);
roger5641 0:910d40021983 404 }
roger5641 0:910d40021983 405
roger5641 0:910d40021983 406 //runs the redundancy self test
roger5641 0:910d40021983 407 int16_t LTC6811_run_adc_redundancy_st(uint8_t adc_mode, uint8_t adc_reg, uint8_t total_ic, cell_asic ic[])
roger5641 0:910d40021983 408 {
roger5641 0:910d40021983 409 int16_t error = 0;
roger5641 0:910d40021983 410 LTC681x_run_adc_redundancy_st(adc_mode,adc_reg,total_ic,ic);
roger5641 0:910d40021983 411 return(error);
roger5641 0:910d40021983 412 }
roger5641 0:910d40021983 413 //Runs the datasheet algorithm for open wire
roger5641 0:910d40021983 414 void LTC6811_run_openwire(uint8_t total_ic, cell_asic ic[])
roger5641 0:910d40021983 415 {
roger5641 0:910d40021983 416 LTC681x_run_openwire(total_ic,ic);
roger5641 0:910d40021983 417 }
roger5641 0:910d40021983 418 // Runs the ADC overlap test for the IC
roger5641 0:910d40021983 419 uint16_t LTC6811_run_adc_overlap(uint8_t total_ic, cell_asic ic[])
roger5641 0:910d40021983 420 {
roger5641 0:910d40021983 421 uint16_t error = 0;
roger5641 0:910d40021983 422 LTC681x_run_adc_overlap(total_ic, ic);
roger5641 0:910d40021983 423 return(error);
roger5641 0:910d40021983 424 }
roger5641 0:910d40021983 425
roger5641 0:910d40021983 426 void LTC6811_max_min(uint8_t total_ic, cell_asic ic_cells[],
roger5641 0:910d40021983 427 cell_asic ic_min[],
roger5641 0:910d40021983 428 cell_asic ic_max[],
roger5641 0:910d40021983 429 cell_asic ic_delta[])
roger5641 0:910d40021983 430 {
roger5641 0:910d40021983 431 for (int j=0; j < total_ic; j++)
roger5641 0:910d40021983 432 {
roger5641 0:910d40021983 433 for (int i = 0; i< 12; i++)
roger5641 0:910d40021983 434 {
roger5641 0:910d40021983 435 if (ic_cells[j].cells.c_codes[i]>ic_max[j].cells.c_codes[i])ic_max[j].cells.c_codes[i]=ic_cells[j].cells.c_codes[i];
roger5641 0:910d40021983 436 else if (ic_cells[j].cells.c_codes[i]<ic_min[j].cells.c_codes[i])ic_min[j].cells.c_codes[i]=ic_cells[j].cells.c_codes[i];
roger5641 0:910d40021983 437 ic_delta[j].cells.c_codes[i] = ic_max[j].cells.c_codes[i] - ic_min[j].cells.c_codes[i];
roger5641 0:910d40021983 438 }
roger5641 0:910d40021983 439 }
roger5641 0:910d40021983 440
roger5641 0:910d40021983 441
roger5641 0:910d40021983 442
roger5641 0:910d40021983 443
roger5641 0:910d40021983 444 }
roger5641 0:910d40021983 445
roger5641 0:910d40021983 446 void LTC6811_init_max_min(uint8_t total_ic, cell_asic ic[],cell_asic ic_max[],cell_asic ic_min[])
roger5641 0:910d40021983 447 {
roger5641 0:910d40021983 448 for (int j=0; j < total_ic; j++)
roger5641 0:910d40021983 449 {
roger5641 0:910d40021983 450 for (int i = 0; i< ic[j].ic_reg.cell_channels; i++)
roger5641 0:910d40021983 451 {
roger5641 0:910d40021983 452 ic_max[j].cells.c_codes[i]=0;
roger5641 0:910d40021983 453 ic_min[j].cells.c_codes[i]=0xFFFF;
roger5641 0:910d40021983 454 }
roger5641 0:910d40021983 455 }
roger5641 0:910d40021983 456
roger5641 0:910d40021983 457 }
roger5641 0:910d40021983 458
roger5641 0:910d40021983 459 //Helper function that increments PEC counters
roger5641 0:910d40021983 460 void LTC6811_check_pec(uint8_t total_ic,uint8_t reg, cell_asic ic[])
roger5641 0:910d40021983 461 {
roger5641 0:910d40021983 462 LTC681x_check_pec(total_ic,reg,ic);
roger5641 0:910d40021983 463 }
roger5641 0:910d40021983 464
roger5641 0:910d40021983 465 //Helper Function to reset PEC counters
roger5641 0:910d40021983 466 void LTC6811_reset_crc_count(uint8_t total_ic, cell_asic ic[])
roger5641 0:910d40021983 467 {
roger5641 0:910d40021983 468 LTC681x_reset_crc_count(total_ic,ic);
roger5641 0:910d40021983 469 }
roger5641 0:910d40021983 470
roger5641 0:910d40021983 471 //Helper function to intialize CFG variables.
roger5641 0:910d40021983 472 void LTC6811_init_cfg(uint8_t total_ic, cell_asic ic[])
roger5641 0:910d40021983 473 {
roger5641 0:910d40021983 474 LTC681x_init_cfg(total_ic,ic);
roger5641 0:910d40021983 475 }
roger5641 0:910d40021983 476 //Helper function to set CFGR variable
roger5641 0:910d40021983 477 void LTC6811_set_cfgr(uint8_t nIC, cell_asic ic[], bool refon, bool adcopt, bool gpio[5],bool dcc[12])
roger5641 0:910d40021983 478 {
roger5641 0:910d40021983 479 LTC681x_set_cfgr_refon(nIC,ic,refon);
roger5641 0:910d40021983 480 LTC681x_set_cfgr_adcopt(nIC,ic,adcopt);
roger5641 0:910d40021983 481 LTC681x_set_cfgr_gpio(nIC,ic,gpio);
roger5641 0:910d40021983 482 LTC681x_set_cfgr_dis(nIC,ic,dcc);
roger5641 0:910d40021983 483 }
roger5641 0:910d40021983 484 //Helper function to set the REFON bit
roger5641 0:910d40021983 485 void LTC6811_set_cfgr_refon(uint8_t nIC, cell_asic ic[], bool refon)
roger5641 0:910d40021983 486 {
roger5641 0:910d40021983 487 LTC681x_set_cfgr_refon(nIC,ic,refon);
roger5641 0:910d40021983 488 }
roger5641 0:910d40021983 489 //Helper function to set the adcopt bit
roger5641 0:910d40021983 490 void LTC6811_set_cfgr_adcopt(uint8_t nIC, cell_asic ic[], bool adcopt)
roger5641 0:910d40021983 491 {
roger5641 0:910d40021983 492 LTC681x_set_cfgr_adcopt(nIC,ic,adcopt);
roger5641 0:910d40021983 493 }
roger5641 0:910d40021983 494 //Helper function to set GPIO bits
roger5641 0:910d40021983 495 void LTC6811_set_cfgr_gpio(uint8_t nIC, cell_asic ic[],bool gpio[5])
roger5641 0:910d40021983 496 {
roger5641 0:910d40021983 497 LTC681x_set_cfgr_gpio(nIC,ic,gpio);
roger5641 0:910d40021983 498 }
roger5641 0:910d40021983 499 //Helper function to control discharge
roger5641 0:910d40021983 500 void LTC6811_set_cfgr_dis(uint8_t nIC, cell_asic ic[],bool dcc[12])
roger5641 0:910d40021983 501 {
roger5641 0:910d40021983 502 LTC681x_set_cfgr_dis(nIC,ic,dcc);
roger5641 0:910d40021983 503 }
roger5641 0:910d40021983 504 //Helper Function to set uv value in CFG register
roger5641 0:910d40021983 505 void LTC6811_set_cfgr_uv(uint8_t nIC, cell_asic ic[],uint16_t uv)
roger5641 0:910d40021983 506 {
roger5641 0:910d40021983 507 LTC681x_set_cfgr_uv(nIC, ic, uv);
roger5641 0:910d40021983 508 }
roger5641 0:910d40021983 509 //helper function to set OV value in CFG register
roger5641 0:910d40021983 510 void LTC6811_set_cfgr_ov(uint8_t nIC, cell_asic ic[],uint16_t ov)
roger5641 0:910d40021983 511 {
roger5641 0:910d40021983 512 LTC681x_set_cfgr_ov( nIC, ic, ov);
roger5641 0:910d40021983 513 }