BMS_T2

Dependencies:   INA226

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LTC6811.h Source File

LTC6811.h

00001 /*
00002     LTC6811-1: Multicell Battery Monitor
00003     LTC6811.h
00004 */
00005 
00006 #ifndef LTC6811_H
00007 #define LTC6811_H
00008 
00009 #include "mbed.h"
00010 //#include <stdint.h>
00011 #include "LTC681x.h"
00012 
00013 #define CELL 1
00014 #define AUX 2
00015 #define STAT 3
00016 
00017 
00018 
00019 void LTC6811_init_reg_limits(uint8_t total_ic, cell_asic ic[]);
00020 
00021 
00022 /*! Starts the Mux Decoder diagnostic self test
00023 
00024  Running this command will start the Mux Decoder Diagnostic Self Test
00025  This test takes roughly 1mS to complete. The MUXFAIL bit will be updated,
00026  the bit will be set to 1 for a failure and 0 if the test has been passed.
00027 
00028 */
00029 void LTC6811_diagn();
00030 
00031 
00032 //! Sends the poll adc command
00033 //! @returns 1 byte read back after a pladc command. If the byte is not 0xFF ADC conversion has completed
00034 uint8_t LTC6811_pladc();
00035 
00036 
00037 //! This function will block operation until the ADC has finished it's conversion
00038 //! @returns the approximate time it took for the ADC function to complete.
00039 uint32_t LTC6811_pollAdc();
00040 
00041 /*! Starts cell voltage conversion
00042 */
00043 void LTC6811_adcv(uint8_t MD, //!< ADC Conversion Mode
00044                   uint8_t DCP, //!< Controls if Discharge is permitted during conversion
00045                   uint8_t CH //!< Sets which Cell channels are converted
00046                  );
00047 
00048 /*!  Starts cell voltage  and GPIO 1&2 conversion
00049 */
00050 void LTC6811_adcvax(
00051   uint8_t MD, //!< ADC Conversion Mode
00052   uint8_t DCP //!< Controls if Discharge is permitted during conversion
00053 );
00054 
00055 
00056 /*!  Starts cell voltage self test conversion
00057 */
00058 void LTC6811_cvst(
00059   uint8_t MD, //!< ADC Conversion Mode
00060   uint8_t ST //!< Self Test Mode
00061 );
00062 
00063 /*!  Starts cell voltage and SOC conversion
00064 */
00065 void LTC6811_adcvsc(
00066   uint8_t MD, //!< ADC Conversion Mode
00067   uint8_t DCP //!< Controls if Discharge is permitted during conversion
00068 );
00069 /*!  Starts cell voltage overlap conversion
00070 */
00071 void LTC6811_adol(
00072   uint8_t MD, //!< ADC Conversion Mode
00073   uint8_t DCP //!< Discharge permitted during conversion
00074 );
00075 
00076 /*!  Start an open wire Conversion
00077 */
00078 void LTC6811_adow(
00079   uint8_t MD, //!< ADC Conversion Mode
00080   uint8_t PUP //!< Controls if Discharge is permitted during conversion
00081 );
00082 
00083 
00084 /*!  Start a GPIO and Vref2 Conversion
00085 */
00086 void LTC6811_adax(
00087   uint8_t MD, //!< ADC Conversion Mode
00088   uint8_t CHG //!< Sets which GPIO channels are converted
00089 );
00090 
00091 /*!  Start an GPIO Redundancy test
00092 */
00093 void LTC6811_adaxd(
00094   uint8_t MD, //!< ADC Conversion Mode
00095   uint8_t CHG //!< Sets which GPIO channels are converted
00096 );
00097 
00098 /*!  Start an Auxiliary Register Self Test Conversion
00099 */
00100 void LTC6811_axst(
00101   uint8_t MD, //!< ADC Conversion Mode
00102   uint8_t ST //!< Sets if self test 1 or 2 is run
00103 );
00104 
00105 /*!  Start a Status ADC Conversion
00106 */
00107 void LTC6811_adstat(
00108   uint8_t MD, //!< ADC Conversion Mode
00109   uint8_t CHST //!< Sets which Stat channels are converted
00110 );
00111 
00112 /*!   Start a Status register redundancy test Conversion
00113 */
00114 void LTC6811_adstatd(
00115   uint8_t MD, //!< ADC Mode
00116   uint8_t CHST //!< Sets which Status channels are converted
00117 );
00118 
00119 
00120 /*!  Start a Status Register Self Test Conversion
00121 */
00122 void LTC6811_statst(
00123   uint8_t MD, //!< ADC Conversion Mode
00124   uint8_t ST //!< Sets if self test 1 or 2 is run
00125 );
00126 
00127 /*!  Reads and parses the LTC6811 cell voltage registers.
00128 
00129   @return int8_t, PEC Status.
00130     0: No PEC error detected
00131     -1: PEC error detected, retry read
00132 */
00133 uint8_t LTC6811_rdcv(uint8_t reg, //!< controls which cell voltage register is read back.
00134                      uint8_t total_ic, //!< the number of ICs in the daisy chain(-1 only)
00135                      cell_asic ic[] //!< array of the parsed cell codes from lowest to highest.
00136                     );
00137 
00138 
00139 
00140 /*!  Reads and parses the LTC6811 auxiliary registers.
00141 @return  int8_t, PEC Status
00142   0: No PEC error detected
00143  -1: PEC error detected, retry read
00144 */
00145 int8_t LTC6811_rdaux(uint8_t reg,        //!< controls which GPIO voltage register is read back
00146                      uint8_t nIC,        //!< the number of ICs in the daisy chain
00147                      cell_asic ic[] //!< A two dimensional array of the parsed gpio voltage codes
00148                     );
00149 
00150 /*!  Reads and parses the LTC6811 stat registers.
00151 
00152 @return  int8_t, PEC Status
00153   0: No PEC error detected
00154  -1: PEC error detected, retry read
00155 */
00156 int8_t LTC6811_rdstat(uint8_t reg, //Determines which Stat  register is read back.
00157                       uint8_t total_ic,//the number of ICs in the system
00158                       cell_asic ic[]
00159                      );
00160 
00161 /*!  Clears the LTC6811 cell voltage registers
00162 */
00163 void LTC6811_clrcell();
00164 
00165 /*! Clears the LTC6811 Auxiliary registers
00166 */
00167 void LTC6811_clraux();
00168 
00169 /*!  Clears the LTC6811 Stat registers
00170 */
00171 void LTC6811_clrstat();
00172 
00173 /*!  Clears the LTC6811 Sctrl registers
00174 */
00175 void LTC6811_clrsctrl();
00176 
00177 /*!  Write the LTC6811 configuration register
00178 */
00179 void LTC6811_wrcfg(uint8_t nIC, //!< The number of ICs being written
00180                    cell_asic ic[] //!< a two dimensional array of the configuration data that will be written
00181                   );
00182 
00183 void LTC6811_wrcfgb(uint8_t nIC, //!< The number of ICs being written
00184                     cell_asic ic[] //!< a two dimensional array of the configuration data that will be written
00185                    );
00186 /*!  Reads configuration registers of a LTC6811 daisy chain
00187 @return int8_t, PEC Status.
00188   0: Data read back has matching PEC
00189    -1: Data read back has incorrect PEC
00190 */
00191 int8_t LTC6811_rdcfg(uint8_t nIC, //!< number of ICs in the daisy chain
00192                      cell_asic ic[] //!< a two dimensional array that the function stores the read configuration data
00193                     );
00194 
00195 int8_t LTC6811_rdcfgb(uint8_t nIC, //!< number of ICs in the daisy chain
00196                       cell_asic ic[] //!< a two dimensional array that the function stores the read configuration data
00197                      );
00198 /*!  Write the LTC6811 PWM register
00199 */
00200 void LTC6811_wrpwm(uint8_t nIC, //!< number of ICs in the daisy chain
00201                    uint8_t pwmReg,
00202                    cell_asic ic[]
00203                   );
00204 
00205 /*!  Reads pwm registers of a LTC6811 daisy chain
00206 
00207 */
00208 int8_t LTC6811_rdpwm(uint8_t nIC, //!< number of ICs in the daisy chain
00209                      uint8_t pwmReg,
00210                      cell_asic ic[] //!< a two dimensional array that the function stores the read pwm data
00211                     );
00212 
00213 /*!  Write the LTC6811 Sctrl register
00214 */
00215 void LTC6811_wrsctrl(uint8_t nIC, //!< number of ICs in the daisy chain
00216                      uint8_t sctrl_reg,
00217                      cell_asic ic[]
00218                     );
00219 
00220 
00221 /*!  Reads sctrl registers of a LTC6811 daisy chain
00222 @return int8_t, PEC Status.
00223   0: Data read back has matching PEC
00224   -1: Data read back has incorrect PEC
00225 */
00226 int8_t LTC6811_rdsctrl(uint8_t nIC, //!< number of ICs in the daisy chain
00227                        uint8_t sctrl_reg,
00228                        cell_asic ic[] //!< a two dimensional array that the function stores the read pwm data
00229                       );
00230 
00231 
00232 /*!  Start Sctrl data communication
00233 This command will start the sctrl pulse communication over the spins
00234 */
00235 void LTC6811_stsctrl();
00236 
00237 
00238 /*!  Write the LTC6811 COMM register
00239 */
00240 void LTC6811_wrcomm(uint8_t total_ic, //!< Number of ICs in the daisy chain
00241                     cell_asic ic[] //!< A two dimensional array of the comm data that will be written
00242                    );
00243 
00244 /*!  Reads comm registers of a LTC6811 daisy chain
00245 @return int8_t, PEC Status.
00246 
00247   0: Data read back has matching PEC
00248 
00249   -1: Data read back has incorrect PEC
00250 
00251 */
00252 int8_t LTC6811_rdcomm(uint8_t total_ic, //!< number of ICs in the daisy chain
00253                       cell_asic ic[] //!< Two dimensional array that the function stores the read comm data.
00254                      );
00255 
00256 /*!  issues a stcomm command and clocks data out of the COMM register */
00257 void LTC6811_stcomm();
00258 
00259 
00260 /*! @returns returns the register data pattern for a given ADC MD and Self test */
00261 uint16_t LTC6811_st_lookup(
00262   uint8_t MD, //!< ADC Conversion Mode
00263   uint8_t ST //!< Self test number
00264 );
00265 
00266 void LTC6811_set_discharge(int Cell,
00267                            uint8_t total_ic,
00268                            cell_asic ic[]);
00269 
00270 /*! Helper function that runs the ADC Self Tests*/
00271 int16_t LTC6811_run_cell_adc_st(uint8_t adc_reg,
00272                                 uint8_t total_ic,
00273                                 cell_asic ic[]);
00274 
00275 /*! Helper function that runs the ADC Digital Redudancy commands and checks output for errors*/
00276 int16_t LTC6811_run_adc_redundancy_st(uint8_t adc_mode,
00277                                       uint8_t adc_reg,
00278                                       uint8_t total_ic,
00279                                       cell_asic ic[]);
00280 
00281 /*! Helper function that runs the datasheet open wire algorithm*/
00282 void LTC6811_run_openwire(uint8_t total_ic,
00283                           cell_asic ic[]);
00284 
00285 void LTC6811_set_discharge(int Cell,
00286                            uint8_t total_ic,
00287                            cell_asic ic[]);
00288 
00289 /*! Helper Function that runs the ADC Overlap test*/
00290 uint16_t LTC6811_run_adc_overlap(uint8_t total_ic,
00291                                  cell_asic ic[]);
00292 
00293 /*! Helper Function that counts overall PEC errors and register/IC PEC errors*/
00294 void LTC6811_check_pec(uint8_t total_ic,
00295                        uint8_t reg,
00296                        cell_asic ic[]);
00297 
00298 /*! Helper Function that resets the PEC error counters */
00299 void LTC6811_reset_crc_count(uint8_t total_ic,
00300                              cell_asic ic[]);
00301 
00302 /*! Helper Function to initialize the CFGR data structures*/
00303 void LTC6811_init_cfg(uint8_t total_ic,
00304                       cell_asic ic[]);
00305 
00306 /*! Helper function to set appropriate bits in CFGR register based on bit function*/
00307 void LTC6811_set_cfgr(uint8_t nIC,
00308                       cell_asic ic[],
00309                       bool refon,
00310                       bool adcopt,
00311                       bool gpio[5],
00312                       bool dcc[12]);
00313 
00314 /*! Helper function to turn the refon bit HIGH or LOW*/
00315 void LTC6811_set_cfgr_refon(uint8_t nIC,
00316                             cell_asic ic[],
00317                             bool refon);
00318 
00319 /*! Helper function to turn the ADCOPT bit HIGH or LOW*/
00320 void LTC6811_set_cfgr_adcopt(uint8_t nIC,
00321                              cell_asic ic[],
00322                              bool adcopt);
00323 
00324 /*! Helper function to turn the GPIO bits HIGH or LOW*/
00325 void LTC6811_set_cfgr_gpio(uint8_t nIC,
00326                            cell_asic ic[],
00327                            bool gpio[]);
00328 
00329 /*! Helper function to turn the DCC bits HIGH or LOW*/
00330 void LTC6811_set_cfgr_dis(uint8_t nIC,
00331                           cell_asic ic[],
00332                           bool dcc[]);
00333 /*!  Helper function to set uv field in CFGRA register*/
00334 void LTC6811_set_cfgr_uv(uint8_t nIC,
00335                          cell_asic ic[],
00336                          uint16_t uv);
00337 
00338 /*!  Helper function to set ov field in CFGRA register*/
00339 void LTC6811_set_cfgr_ov(uint8_t nIC,
00340                          cell_asic ic[],
00341                          uint16_t ov);
00342 
00343 void LTC6811_init_max_min(uint8_t total_ic,
00344                           cell_asic ic[],
00345                           cell_asic ic_max[],
00346                           cell_asic ic_min[]);
00347 
00348 void LTC6811_max_min(uint8_t total_ic, cell_asic ic_cells[],
00349                      cell_asic ic_min[],
00350                      cell_asic ic_max[],
00351                      cell_asic ic_delta[]);
00352 #endif