BMS_T1
Dependencies: INA226
LTC6811.cpp@3:61174d4de67d, 2020-10-13 (annotated)
- Committer:
- takuma1
- Date:
- Tue Oct 13 07:20:11 2020 +0000
- Revision:
- 3:61174d4de67d
- Parent:
- 0:f06ed53310a3
BMS_T2;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
APS_Lab | 0:f06ed53310a3 | 1 | /* |
APS_Lab | 0:f06ed53310a3 | 2 | LTC6811-1: Multicell Battery Monitor |
APS_Lab | 0:f06ed53310a3 | 3 | LTC6811.cpp |
APS_Lab | 0:f06ed53310a3 | 4 | */ |
APS_Lab | 0:f06ed53310a3 | 5 | |
APS_Lab | 0:f06ed53310a3 | 6 | #include "mbed.h" |
APS_Lab | 0:f06ed53310a3 | 7 | #include "LTC681x.h" |
APS_Lab | 0:f06ed53310a3 | 8 | #include "LTC6811.h" |
APS_Lab | 0:f06ed53310a3 | 9 | |
APS_Lab | 0:f06ed53310a3 | 10 | |
APS_Lab | 0:f06ed53310a3 | 11 | void LTC6811_init_reg_limits(uint8_t total_ic, cell_asic ic[]) |
APS_Lab | 0:f06ed53310a3 | 12 | { |
APS_Lab | 0:f06ed53310a3 | 13 | for (uint8_t cic=0; cic<total_ic; cic++) |
APS_Lab | 0:f06ed53310a3 | 14 | { |
APS_Lab | 0:f06ed53310a3 | 15 | ic[cic].ic_reg.cell_channels=12; |
APS_Lab | 0:f06ed53310a3 | 16 | ic[cic].ic_reg.stat_channels=4; |
APS_Lab | 0:f06ed53310a3 | 17 | ic[cic].ic_reg.aux_channels=6; |
APS_Lab | 0:f06ed53310a3 | 18 | ic[cic].ic_reg.num_cv_reg=4; |
APS_Lab | 0:f06ed53310a3 | 19 | ic[cic].ic_reg.num_gpio_reg=2; |
APS_Lab | 0:f06ed53310a3 | 20 | ic[cic].ic_reg.num_stat_reg=3; |
APS_Lab | 0:f06ed53310a3 | 21 | } |
APS_Lab | 0:f06ed53310a3 | 22 | } |
APS_Lab | 0:f06ed53310a3 | 23 | |
APS_Lab | 0:f06ed53310a3 | 24 | /* |
APS_Lab | 0:f06ed53310a3 | 25 | Starts cell voltage conversion |
APS_Lab | 0:f06ed53310a3 | 26 | */ |
APS_Lab | 0:f06ed53310a3 | 27 | void LTC6811_adcv( |
APS_Lab | 0:f06ed53310a3 | 28 | uint8_t MD, //ADC Mode |
APS_Lab | 0:f06ed53310a3 | 29 | uint8_t DCP, //Discharge Permit |
APS_Lab | 0:f06ed53310a3 | 30 | uint8_t CH //Cell Channels to be measured |
APS_Lab | 0:f06ed53310a3 | 31 | ) |
APS_Lab | 0:f06ed53310a3 | 32 | { |
APS_Lab | 0:f06ed53310a3 | 33 | LTC681x_adcv(MD,DCP,CH); |
APS_Lab | 0:f06ed53310a3 | 34 | } |
APS_Lab | 0:f06ed53310a3 | 35 | |
APS_Lab | 0:f06ed53310a3 | 36 | //Starts cell voltage and SOC conversion |
APS_Lab | 0:f06ed53310a3 | 37 | void LTC6811_adcvsc( |
APS_Lab | 0:f06ed53310a3 | 38 | uint8_t MD, //ADC Mode |
APS_Lab | 0:f06ed53310a3 | 39 | uint8_t DCP //Discharge Permit |
APS_Lab | 0:f06ed53310a3 | 40 | ) |
APS_Lab | 0:f06ed53310a3 | 41 | { |
APS_Lab | 0:f06ed53310a3 | 42 | LTC681x_adcvsc(MD,DCP); |
APS_Lab | 0:f06ed53310a3 | 43 | } |
APS_Lab | 0:f06ed53310a3 | 44 | |
APS_Lab | 0:f06ed53310a3 | 45 | // Starts cell voltage and GPIO 1&2 conversion |
APS_Lab | 0:f06ed53310a3 | 46 | void LTC6811_adcvax( |
APS_Lab | 0:f06ed53310a3 | 47 | uint8_t MD, //ADC Mode |
APS_Lab | 0:f06ed53310a3 | 48 | uint8_t DCP //Discharge Permit |
APS_Lab | 0:f06ed53310a3 | 49 | ) |
APS_Lab | 0:f06ed53310a3 | 50 | { |
APS_Lab | 0:f06ed53310a3 | 51 | LTC681x_adcvax(MD,DCP); |
APS_Lab | 0:f06ed53310a3 | 52 | } |
APS_Lab | 0:f06ed53310a3 | 53 | |
APS_Lab | 0:f06ed53310a3 | 54 | //Starts cell voltage overlap conversion |
APS_Lab | 0:f06ed53310a3 | 55 | void LTC6811_adol( |
APS_Lab | 0:f06ed53310a3 | 56 | uint8_t MD, //ADC Mode |
APS_Lab | 0:f06ed53310a3 | 57 | uint8_t DCP //Discharge Permit |
APS_Lab | 0:f06ed53310a3 | 58 | ) |
APS_Lab | 0:f06ed53310a3 | 59 | { |
APS_Lab | 0:f06ed53310a3 | 60 | LTC681x_adol(MD,DCP); |
APS_Lab | 0:f06ed53310a3 | 61 | } |
APS_Lab | 0:f06ed53310a3 | 62 | |
APS_Lab | 0:f06ed53310a3 | 63 | //Starts cell voltage self test conversion |
APS_Lab | 0:f06ed53310a3 | 64 | void LTC6811_cvst( |
APS_Lab | 0:f06ed53310a3 | 65 | uint8_t MD, //ADC Mode |
APS_Lab | 0:f06ed53310a3 | 66 | uint8_t ST //Self Test |
APS_Lab | 0:f06ed53310a3 | 67 | ) |
APS_Lab | 0:f06ed53310a3 | 68 | { |
APS_Lab | 0:f06ed53310a3 | 69 | LTC681x_cvst(MD,ST); |
APS_Lab | 0:f06ed53310a3 | 70 | } |
APS_Lab | 0:f06ed53310a3 | 71 | |
APS_Lab | 0:f06ed53310a3 | 72 | //Start an Auxiliary Register Self Test Conversion |
APS_Lab | 0:f06ed53310a3 | 73 | void LTC6811_axst( |
APS_Lab | 0:f06ed53310a3 | 74 | uint8_t MD, //ADC Mode |
APS_Lab | 0:f06ed53310a3 | 75 | uint8_t ST //Self Test |
APS_Lab | 0:f06ed53310a3 | 76 | ) |
APS_Lab | 0:f06ed53310a3 | 77 | { |
APS_Lab | 0:f06ed53310a3 | 78 | LTC681x_axst(MD,ST); |
APS_Lab | 0:f06ed53310a3 | 79 | } |
APS_Lab | 0:f06ed53310a3 | 80 | |
APS_Lab | 0:f06ed53310a3 | 81 | //Start a Status Register Self Test Conversion |
APS_Lab | 0:f06ed53310a3 | 82 | void LTC6811_statst( |
APS_Lab | 0:f06ed53310a3 | 83 | uint8_t MD, //ADC Mode |
APS_Lab | 0:f06ed53310a3 | 84 | uint8_t ST //Self Test |
APS_Lab | 0:f06ed53310a3 | 85 | ) |
APS_Lab | 0:f06ed53310a3 | 86 | { |
APS_Lab | 0:f06ed53310a3 | 87 | LTC681x_statst(MD,ST); |
APS_Lab | 0:f06ed53310a3 | 88 | } |
APS_Lab | 0:f06ed53310a3 | 89 | |
APS_Lab | 0:f06ed53310a3 | 90 | //Sends the poll adc command |
APS_Lab | 0:f06ed53310a3 | 91 | uint8_t LTC6811_pladc() |
APS_Lab | 0:f06ed53310a3 | 92 | { |
APS_Lab | 0:f06ed53310a3 | 93 | return(LTC681x_pladc()); |
APS_Lab | 0:f06ed53310a3 | 94 | } |
APS_Lab | 0:f06ed53310a3 | 95 | |
APS_Lab | 0:f06ed53310a3 | 96 | //This function will block operation until the ADC has finished it's conversion |
APS_Lab | 0:f06ed53310a3 | 97 | uint32_t LTC6811_pollAdc() |
APS_Lab | 0:f06ed53310a3 | 98 | { |
APS_Lab | 0:f06ed53310a3 | 99 | return(LTC681x_pollAdc()); |
APS_Lab | 0:f06ed53310a3 | 100 | } |
APS_Lab | 0:f06ed53310a3 | 101 | |
APS_Lab | 0:f06ed53310a3 | 102 | //Start a GPIO and Vref2 Conversion |
APS_Lab | 0:f06ed53310a3 | 103 | void LTC6811_adax( |
APS_Lab | 0:f06ed53310a3 | 104 | uint8_t MD, //ADC Mode |
APS_Lab | 0:f06ed53310a3 | 105 | uint8_t CHG //GPIO Channels to be measured) |
APS_Lab | 0:f06ed53310a3 | 106 | ) |
APS_Lab | 0:f06ed53310a3 | 107 | { |
APS_Lab | 0:f06ed53310a3 | 108 | LTC681x_adax(MD,CHG); |
APS_Lab | 0:f06ed53310a3 | 109 | } |
APS_Lab | 0:f06ed53310a3 | 110 | |
APS_Lab | 0:f06ed53310a3 | 111 | //Start an GPIO Redundancy test |
APS_Lab | 0:f06ed53310a3 | 112 | void LTC6811_adaxd( |
APS_Lab | 0:f06ed53310a3 | 113 | uint8_t MD, //ADC Mode |
APS_Lab | 0:f06ed53310a3 | 114 | uint8_t CHG //GPIO Channels to be measured) |
APS_Lab | 0:f06ed53310a3 | 115 | ) |
APS_Lab | 0:f06ed53310a3 | 116 | { |
APS_Lab | 0:f06ed53310a3 | 117 | LTC681x_adaxd(MD,CHG); |
APS_Lab | 0:f06ed53310a3 | 118 | } |
APS_Lab | 0:f06ed53310a3 | 119 | |
APS_Lab | 0:f06ed53310a3 | 120 | //Start a Status ADC Conversion |
APS_Lab | 0:f06ed53310a3 | 121 | void LTC6811_adstat( |
APS_Lab | 0:f06ed53310a3 | 122 | uint8_t MD, //ADC Mode |
APS_Lab | 0:f06ed53310a3 | 123 | uint8_t CHST //GPIO Channels to be measured |
APS_Lab | 0:f06ed53310a3 | 124 | ) |
APS_Lab | 0:f06ed53310a3 | 125 | { |
APS_Lab | 0:f06ed53310a3 | 126 | LTC681x_adstat(MD,CHST); |
APS_Lab | 0:f06ed53310a3 | 127 | } |
APS_Lab | 0:f06ed53310a3 | 128 | |
APS_Lab | 0:f06ed53310a3 | 129 | // Start a Status register redundancy test Conversion |
APS_Lab | 0:f06ed53310a3 | 130 | void LTC6811_adstatd( |
APS_Lab | 0:f06ed53310a3 | 131 | uint8_t MD, //ADC Mode |
APS_Lab | 0:f06ed53310a3 | 132 | uint8_t CHST //GPIO Channels to be measured |
APS_Lab | 0:f06ed53310a3 | 133 | ) |
APS_Lab | 0:f06ed53310a3 | 134 | { |
APS_Lab | 0:f06ed53310a3 | 135 | LTC681x_adstatd(MD,CHST); |
APS_Lab | 0:f06ed53310a3 | 136 | } |
APS_Lab | 0:f06ed53310a3 | 137 | |
APS_Lab | 0:f06ed53310a3 | 138 | |
APS_Lab | 0:f06ed53310a3 | 139 | // Start an open wire Conversion |
APS_Lab | 0:f06ed53310a3 | 140 | void LTC6811_adow( |
APS_Lab | 0:f06ed53310a3 | 141 | uint8_t MD, //ADC Mode |
APS_Lab | 0:f06ed53310a3 | 142 | uint8_t PUP //Discharge Permit |
APS_Lab | 0:f06ed53310a3 | 143 | ) |
APS_Lab | 0:f06ed53310a3 | 144 | { |
APS_Lab | 0:f06ed53310a3 | 145 | LTC681x_adow(MD,PUP); |
APS_Lab | 0:f06ed53310a3 | 146 | } |
APS_Lab | 0:f06ed53310a3 | 147 | |
APS_Lab | 0:f06ed53310a3 | 148 | // Reads and parses the LTC6811 cell voltage registers. |
APS_Lab | 0:f06ed53310a3 | 149 | uint8_t LTC6811_rdcv(uint8_t reg, // Controls which cell voltage register is read back. |
APS_Lab | 0:f06ed53310a3 | 150 | uint8_t total_ic, // the number of ICs in the system |
APS_Lab | 0:f06ed53310a3 | 151 | cell_asic ic[] // Array of the parsed cell codes |
APS_Lab | 0:f06ed53310a3 | 152 | ) |
APS_Lab | 0:f06ed53310a3 | 153 | { |
APS_Lab | 0:f06ed53310a3 | 154 | |
APS_Lab | 0:f06ed53310a3 | 155 | int8_t pec_error = 0; |
APS_Lab | 0:f06ed53310a3 | 156 | pec_error = LTC681x_rdcv(reg,total_ic,ic); |
APS_Lab | 0:f06ed53310a3 | 157 | return(pec_error); |
APS_Lab | 0:f06ed53310a3 | 158 | } |
APS_Lab | 0:f06ed53310a3 | 159 | |
APS_Lab | 0:f06ed53310a3 | 160 | /* |
APS_Lab | 0:f06ed53310a3 | 161 | The function is used |
APS_Lab | 0:f06ed53310a3 | 162 | to read the parsed GPIO codes of the LTC6811. This function will send the requested |
APS_Lab | 0:f06ed53310a3 | 163 | read commands parse the data and store the gpio voltages in aux_codes variable |
APS_Lab | 0:f06ed53310a3 | 164 | */ |
APS_Lab | 0:f06ed53310a3 | 165 | int8_t LTC6811_rdaux(uint8_t reg, //Determines which GPIO voltage register is read back. |
APS_Lab | 0:f06ed53310a3 | 166 | uint8_t total_ic,//the number of ICs in the system |
APS_Lab | 0:f06ed53310a3 | 167 | cell_asic ic[]//A two dimensional array of the gpio voltage codes. |
APS_Lab | 0:f06ed53310a3 | 168 | ) |
APS_Lab | 0:f06ed53310a3 | 169 | { |
APS_Lab | 0:f06ed53310a3 | 170 | int8_t pec_error = 0; |
APS_Lab | 0:f06ed53310a3 | 171 | LTC681x_rdaux(reg,total_ic,ic); |
APS_Lab | 0:f06ed53310a3 | 172 | return (pec_error); |
APS_Lab | 0:f06ed53310a3 | 173 | } |
APS_Lab | 0:f06ed53310a3 | 174 | |
APS_Lab | 0:f06ed53310a3 | 175 | /* |
APS_Lab | 0:f06ed53310a3 | 176 | Reads and parses the LTC6811 stat registers. |
APS_Lab | 0:f06ed53310a3 | 177 | The function is used |
APS_Lab | 0:f06ed53310a3 | 178 | to read the parsed stat codes of the LTC6811. This function will send the requested |
APS_Lab | 0:f06ed53310a3 | 179 | read commands parse the data and store the stat voltages in stat_codes variable |
APS_Lab | 0:f06ed53310a3 | 180 | */ |
APS_Lab | 0:f06ed53310a3 | 181 | int8_t LTC6811_rdstat(uint8_t reg, //Determines which Stat register is read back. |
APS_Lab | 0:f06ed53310a3 | 182 | uint8_t total_ic,//the number of ICs in the system |
APS_Lab | 0:f06ed53310a3 | 183 | cell_asic ic[] |
APS_Lab | 0:f06ed53310a3 | 184 | ) |
APS_Lab | 0:f06ed53310a3 | 185 | { |
APS_Lab | 0:f06ed53310a3 | 186 | int8_t pec_error = 0; |
APS_Lab | 0:f06ed53310a3 | 187 | pec_error = LTC681x_rdstat(reg,total_ic,ic); |
APS_Lab | 0:f06ed53310a3 | 188 | return (pec_error); |
APS_Lab | 0:f06ed53310a3 | 189 | } |
APS_Lab | 0:f06ed53310a3 | 190 | |
APS_Lab | 0:f06ed53310a3 | 191 | /* |
APS_Lab | 0:f06ed53310a3 | 192 | The command clears the cell voltage registers and intiallizes |
APS_Lab | 0:f06ed53310a3 | 193 | all values to 1. The register will read back hexadecimal 0xFF |
APS_Lab | 0:f06ed53310a3 | 194 | after the command is sent. |
APS_Lab | 0:f06ed53310a3 | 195 | */ |
APS_Lab | 0:f06ed53310a3 | 196 | void LTC6811_clrcell() |
APS_Lab | 0:f06ed53310a3 | 197 | { |
APS_Lab | 0:f06ed53310a3 | 198 | LTC681x_clrcell(); |
APS_Lab | 0:f06ed53310a3 | 199 | } |
APS_Lab | 0:f06ed53310a3 | 200 | |
APS_Lab | 0:f06ed53310a3 | 201 | /* |
APS_Lab | 0:f06ed53310a3 | 202 | The command clears the Auxiliary registers and initializes |
APS_Lab | 0:f06ed53310a3 | 203 | all values to 1. The register will read back hexadecimal 0xFF |
APS_Lab | 0:f06ed53310a3 | 204 | after the command is sent. |
APS_Lab | 0:f06ed53310a3 | 205 | */ |
APS_Lab | 0:f06ed53310a3 | 206 | void LTC6811_clraux() |
APS_Lab | 0:f06ed53310a3 | 207 | { |
APS_Lab | 0:f06ed53310a3 | 208 | LTC681x_clraux(); |
APS_Lab | 0:f06ed53310a3 | 209 | } |
APS_Lab | 0:f06ed53310a3 | 210 | |
APS_Lab | 0:f06ed53310a3 | 211 | /* |
APS_Lab | 0:f06ed53310a3 | 212 | The command clears the Stat registers and intiallizes |
APS_Lab | 0:f06ed53310a3 | 213 | all values to 1. The register will read back hexadecimal 0xFF |
APS_Lab | 0:f06ed53310a3 | 214 | after the command is sent. |
APS_Lab | 0:f06ed53310a3 | 215 | |
APS_Lab | 0:f06ed53310a3 | 216 | */ |
APS_Lab | 0:f06ed53310a3 | 217 | void LTC6811_clrstat() |
APS_Lab | 0:f06ed53310a3 | 218 | { |
APS_Lab | 0:f06ed53310a3 | 219 | LTC681x_clrstat(); |
APS_Lab | 0:f06ed53310a3 | 220 | } |
APS_Lab | 0:f06ed53310a3 | 221 | |
APS_Lab | 0:f06ed53310a3 | 222 | /* |
APS_Lab | 0:f06ed53310a3 | 223 | The command clears the Sctrl registers and initializes |
APS_Lab | 0:f06ed53310a3 | 224 | all values to 0. The register will read back hexadecimal 0x00 |
APS_Lab | 0:f06ed53310a3 | 225 | after the command is sent. |
APS_Lab | 0:f06ed53310a3 | 226 | */ |
APS_Lab | 0:f06ed53310a3 | 227 | void LTC6811_clrsctrl() |
APS_Lab | 0:f06ed53310a3 | 228 | { |
APS_Lab | 0:f06ed53310a3 | 229 | LTC681x_clrsctrl(); |
APS_Lab | 0:f06ed53310a3 | 230 | } |
APS_Lab | 0:f06ed53310a3 | 231 | |
APS_Lab | 0:f06ed53310a3 | 232 | //Starts the Mux Decoder diagnostic self test |
APS_Lab | 0:f06ed53310a3 | 233 | void LTC6811_diagn() |
APS_Lab | 0:f06ed53310a3 | 234 | { |
APS_Lab | 0:f06ed53310a3 | 235 | LTC681x_diagn(); |
APS_Lab | 0:f06ed53310a3 | 236 | } |
APS_Lab | 0:f06ed53310a3 | 237 | |
APS_Lab | 0:f06ed53310a3 | 238 | /* |
APS_Lab | 0:f06ed53310a3 | 239 | This command will write the configuration registers of the LTC6811-1s |
APS_Lab | 0:f06ed53310a3 | 240 | connected in a daisy chain stack. The configuration is written in descending |
APS_Lab | 0:f06ed53310a3 | 241 | order so the last device's configuration is written first. |
APS_Lab | 0:f06ed53310a3 | 242 | */ |
APS_Lab | 0:f06ed53310a3 | 243 | void LTC6811_wrcfg(uint8_t total_ic, //The number of ICs being written to |
APS_Lab | 0:f06ed53310a3 | 244 | cell_asic ic[] //A two dimensional array of the configuration data that will be written |
APS_Lab | 0:f06ed53310a3 | 245 | ) |
APS_Lab | 0:f06ed53310a3 | 246 | { |
APS_Lab | 0:f06ed53310a3 | 247 | LTC681x_wrcfg(total_ic,ic); |
APS_Lab | 0:f06ed53310a3 | 248 | } |
APS_Lab | 0:f06ed53310a3 | 249 | |
APS_Lab | 0:f06ed53310a3 | 250 | |
APS_Lab | 0:f06ed53310a3 | 251 | /* |
APS_Lab | 0:f06ed53310a3 | 252 | Reads configuration registers of a LTC6811 daisy chain |
APS_Lab | 0:f06ed53310a3 | 253 | */ |
APS_Lab | 0:f06ed53310a3 | 254 | int8_t LTC6811_rdcfg(uint8_t total_ic, //Number of ICs in the system |
APS_Lab | 0:f06ed53310a3 | 255 | cell_asic ic[] //A two dimensional array that the function stores the read configuration data. |
APS_Lab | 0:f06ed53310a3 | 256 | ) |
APS_Lab | 0:f06ed53310a3 | 257 | { |
APS_Lab | 0:f06ed53310a3 | 258 | int8_t pec_error = 0; |
APS_Lab | 0:f06ed53310a3 | 259 | pec_error = LTC681x_rdcfg(total_ic,ic); |
APS_Lab | 0:f06ed53310a3 | 260 | return(pec_error); |
APS_Lab | 0:f06ed53310a3 | 261 | } |
APS_Lab | 0:f06ed53310a3 | 262 | |
APS_Lab | 0:f06ed53310a3 | 263 | /* |
APS_Lab | 0:f06ed53310a3 | 264 | Writes the pwm registers of a LTC6811 daisy chain |
APS_Lab | 0:f06ed53310a3 | 265 | */ |
APS_Lab | 0:f06ed53310a3 | 266 | void LTC6811_wrpwm(uint8_t total_ic, |
APS_Lab | 0:f06ed53310a3 | 267 | uint8_t pwmReg, //The number of ICs being written to |
APS_Lab | 0:f06ed53310a3 | 268 | cell_asic ic[] //A two dimensional array of the configuration data that will be written |
APS_Lab | 0:f06ed53310a3 | 269 | ) |
APS_Lab | 0:f06ed53310a3 | 270 | { |
APS_Lab | 0:f06ed53310a3 | 271 | LTC681x_wrpwm(total_ic,pwmReg,ic); |
APS_Lab | 0:f06ed53310a3 | 272 | } |
APS_Lab | 0:f06ed53310a3 | 273 | |
APS_Lab | 0:f06ed53310a3 | 274 | |
APS_Lab | 0:f06ed53310a3 | 275 | /* |
APS_Lab | 0:f06ed53310a3 | 276 | Reads pwm registers of a LTC6811 daisy chain |
APS_Lab | 0:f06ed53310a3 | 277 | */ |
APS_Lab | 0:f06ed53310a3 | 278 | int8_t LTC6811_rdpwm(uint8_t total_ic, //Number of ICs in the system |
APS_Lab | 0:f06ed53310a3 | 279 | uint8_t pwmReg, |
APS_Lab | 0:f06ed53310a3 | 280 | cell_asic ic[] //A two dimensional array that the function stores the read configuration data. |
APS_Lab | 0:f06ed53310a3 | 281 | ) |
APS_Lab | 0:f06ed53310a3 | 282 | { |
APS_Lab | 0:f06ed53310a3 | 283 | int8_t pec_error =0; |
APS_Lab | 0:f06ed53310a3 | 284 | pec_error = LTC681x_rdpwm(total_ic,pwmReg,ic); |
APS_Lab | 0:f06ed53310a3 | 285 | return(pec_error); |
APS_Lab | 0:f06ed53310a3 | 286 | } |
APS_Lab | 0:f06ed53310a3 | 287 | |
APS_Lab | 0:f06ed53310a3 | 288 | /* |
APS_Lab | 0:f06ed53310a3 | 289 | Writes the COMM registers of a LTC6811 daisy chain |
APS_Lab | 0:f06ed53310a3 | 290 | */ |
APS_Lab | 0:f06ed53310a3 | 291 | void LTC6811_wrcomm(uint8_t total_ic, //The number of ICs being written to |
APS_Lab | 0:f06ed53310a3 | 292 | cell_asic ic[] //A two dimensional array of the comm data that will be written |
APS_Lab | 0:f06ed53310a3 | 293 | ) |
APS_Lab | 0:f06ed53310a3 | 294 | { |
APS_Lab | 0:f06ed53310a3 | 295 | LTC681x_wrcomm(total_ic,ic); |
APS_Lab | 0:f06ed53310a3 | 296 | } |
APS_Lab | 0:f06ed53310a3 | 297 | |
APS_Lab | 0:f06ed53310a3 | 298 | /* |
APS_Lab | 0:f06ed53310a3 | 299 | Reads COMM registers of a LTC6811 daisy chain |
APS_Lab | 0:f06ed53310a3 | 300 | */ |
APS_Lab | 0:f06ed53310a3 | 301 | int8_t LTC6811_rdcomm(uint8_t total_ic, //Number of ICs in the system |
APS_Lab | 0:f06ed53310a3 | 302 | cell_asic ic[] //A two dimensional array that the function stores the read configuration data. |
APS_Lab | 0:f06ed53310a3 | 303 | ) |
APS_Lab | 0:f06ed53310a3 | 304 | { |
APS_Lab | 0:f06ed53310a3 | 305 | int8_t pec_error = 0; |
APS_Lab | 0:f06ed53310a3 | 306 | LTC681x_rdcomm(total_ic, ic); |
APS_Lab | 0:f06ed53310a3 | 307 | return(pec_error); |
APS_Lab | 0:f06ed53310a3 | 308 | } |
APS_Lab | 0:f06ed53310a3 | 309 | |
APS_Lab | 0:f06ed53310a3 | 310 | /* |
APS_Lab | 0:f06ed53310a3 | 311 | Shifts data in COMM register out over LTC6811 SPI/I2C port |
APS_Lab | 0:f06ed53310a3 | 312 | */ |
APS_Lab | 0:f06ed53310a3 | 313 | void LTC6811_stcomm() |
APS_Lab | 0:f06ed53310a3 | 314 | { |
APS_Lab | 0:f06ed53310a3 | 315 | LTC681x_stcomm(); |
APS_Lab | 0:f06ed53310a3 | 316 | } |
APS_Lab | 0:f06ed53310a3 | 317 | |
APS_Lab | 0:f06ed53310a3 | 318 | //Helper function to set discharge bit in CFG register |
APS_Lab | 0:f06ed53310a3 | 319 | void LTC6811_set_discharge(int Cell, uint8_t total_ic, cell_asic ic[]) |
APS_Lab | 0:f06ed53310a3 | 320 | { |
APS_Lab | 0:f06ed53310a3 | 321 | for (int i=0; i<total_ic; i++) |
APS_Lab | 0:f06ed53310a3 | 322 | { |
APS_Lab | 0:f06ed53310a3 | 323 | if (Cell<9) |
APS_Lab | 0:f06ed53310a3 | 324 | { |
APS_Lab | 0:f06ed53310a3 | 325 | ic[i].config.tx_data[4] = ic[i].config.tx_data[4] | (1<<(Cell-1)); |
APS_Lab | 0:f06ed53310a3 | 326 | } |
APS_Lab | 0:f06ed53310a3 | 327 | else if (Cell < 13) |
APS_Lab | 0:f06ed53310a3 | 328 | { |
APS_Lab | 0:f06ed53310a3 | 329 | ic[i].config.tx_data[5] = ic[i].config.tx_data[5] | (1<<(Cell-9)); |
APS_Lab | 0:f06ed53310a3 | 330 | } |
APS_Lab | 0:f06ed53310a3 | 331 | } |
APS_Lab | 0:f06ed53310a3 | 332 | } |
APS_Lab | 0:f06ed53310a3 | 333 | |
APS_Lab | 0:f06ed53310a3 | 334 | // Runs the Digital Filter Self Test |
APS_Lab | 0:f06ed53310a3 | 335 | int16_t LTC6811_run_cell_adc_st(uint8_t adc_reg,uint8_t total_ic, cell_asic ic[]) |
APS_Lab | 0:f06ed53310a3 | 336 | { |
APS_Lab | 0:f06ed53310a3 | 337 | int16_t error = 0; |
APS_Lab | 0:f06ed53310a3 | 338 | error = LTC681x_run_cell_adc_st(adc_reg,total_ic,ic); |
APS_Lab | 0:f06ed53310a3 | 339 | return(error); |
APS_Lab | 0:f06ed53310a3 | 340 | } |
APS_Lab | 0:f06ed53310a3 | 341 | |
APS_Lab | 0:f06ed53310a3 | 342 | //runs the redundancy self test |
APS_Lab | 0:f06ed53310a3 | 343 | int16_t LTC6811_run_adc_redundancy_st(uint8_t adc_mode, uint8_t adc_reg, uint8_t total_ic, cell_asic ic[]) |
APS_Lab | 0:f06ed53310a3 | 344 | { |
APS_Lab | 0:f06ed53310a3 | 345 | int16_t error = 0; |
APS_Lab | 0:f06ed53310a3 | 346 | LTC681x_run_adc_redundancy_st(adc_mode,adc_reg,total_ic,ic); |
APS_Lab | 0:f06ed53310a3 | 347 | return(error); |
APS_Lab | 0:f06ed53310a3 | 348 | } |
APS_Lab | 0:f06ed53310a3 | 349 | //Runs the datasheet algorithm for open wire |
APS_Lab | 0:f06ed53310a3 | 350 | void LTC6811_run_openwire(uint8_t total_ic, cell_asic ic[]) |
APS_Lab | 0:f06ed53310a3 | 351 | { |
APS_Lab | 0:f06ed53310a3 | 352 | LTC681x_run_openwire(total_ic,ic); |
APS_Lab | 0:f06ed53310a3 | 353 | } |
APS_Lab | 0:f06ed53310a3 | 354 | // Runs the ADC overlap test for the IC |
APS_Lab | 0:f06ed53310a3 | 355 | uint16_t LTC6811_run_adc_overlap(uint8_t total_ic, cell_asic ic[]) |
APS_Lab | 0:f06ed53310a3 | 356 | { |
APS_Lab | 0:f06ed53310a3 | 357 | uint16_t error = 0; |
APS_Lab | 0:f06ed53310a3 | 358 | LTC681x_run_adc_overlap(total_ic, ic); |
APS_Lab | 0:f06ed53310a3 | 359 | return(error); |
APS_Lab | 0:f06ed53310a3 | 360 | } |
APS_Lab | 0:f06ed53310a3 | 361 | |
APS_Lab | 0:f06ed53310a3 | 362 | void LTC6811_max_min(uint8_t total_ic, cell_asic ic_cells[], |
APS_Lab | 0:f06ed53310a3 | 363 | cell_asic ic_min[], |
APS_Lab | 0:f06ed53310a3 | 364 | cell_asic ic_max[], |
APS_Lab | 0:f06ed53310a3 | 365 | cell_asic ic_delta[]) |
APS_Lab | 0:f06ed53310a3 | 366 | { |
APS_Lab | 0:f06ed53310a3 | 367 | for (int j=0; j < total_ic; j++) |
APS_Lab | 0:f06ed53310a3 | 368 | { |
APS_Lab | 0:f06ed53310a3 | 369 | for (int i = 0; i< 12; i++) |
APS_Lab | 0:f06ed53310a3 | 370 | { |
APS_Lab | 0:f06ed53310a3 | 371 | 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]; |
APS_Lab | 0:f06ed53310a3 | 372 | 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]; |
APS_Lab | 0:f06ed53310a3 | 373 | ic_delta[j].cells.c_codes[i] = ic_max[j].cells.c_codes[i] - ic_min[j].cells.c_codes[i]; |
APS_Lab | 0:f06ed53310a3 | 374 | } |
APS_Lab | 0:f06ed53310a3 | 375 | } |
APS_Lab | 0:f06ed53310a3 | 376 | |
APS_Lab | 0:f06ed53310a3 | 377 | |
APS_Lab | 0:f06ed53310a3 | 378 | |
APS_Lab | 0:f06ed53310a3 | 379 | |
APS_Lab | 0:f06ed53310a3 | 380 | } |
APS_Lab | 0:f06ed53310a3 | 381 | |
APS_Lab | 0:f06ed53310a3 | 382 | void LTC6811_init_max_min(uint8_t total_ic, cell_asic ic[],cell_asic ic_max[],cell_asic ic_min[]) |
APS_Lab | 0:f06ed53310a3 | 383 | { |
APS_Lab | 0:f06ed53310a3 | 384 | for (int j=0; j < total_ic; j++) |
APS_Lab | 0:f06ed53310a3 | 385 | { |
APS_Lab | 0:f06ed53310a3 | 386 | for (int i = 0; i< ic[j].ic_reg.cell_channels; i++) |
APS_Lab | 0:f06ed53310a3 | 387 | { |
APS_Lab | 0:f06ed53310a3 | 388 | ic_max[j].cells.c_codes[i]=0; |
APS_Lab | 0:f06ed53310a3 | 389 | ic_min[j].cells.c_codes[i]=0xFFFF; |
APS_Lab | 0:f06ed53310a3 | 390 | } |
APS_Lab | 0:f06ed53310a3 | 391 | } |
APS_Lab | 0:f06ed53310a3 | 392 | |
APS_Lab | 0:f06ed53310a3 | 393 | } |
APS_Lab | 0:f06ed53310a3 | 394 | |
APS_Lab | 0:f06ed53310a3 | 395 | //Helper function that increments PEC counters |
APS_Lab | 0:f06ed53310a3 | 396 | void LTC6811_check_pec(uint8_t total_ic,uint8_t reg, cell_asic ic[]) |
APS_Lab | 0:f06ed53310a3 | 397 | { |
APS_Lab | 0:f06ed53310a3 | 398 | LTC681x_check_pec(total_ic,reg,ic); |
APS_Lab | 0:f06ed53310a3 | 399 | } |
APS_Lab | 0:f06ed53310a3 | 400 | |
APS_Lab | 0:f06ed53310a3 | 401 | //Helper Function to reset PEC counters |
APS_Lab | 0:f06ed53310a3 | 402 | void LTC6811_reset_crc_count(uint8_t total_ic, cell_asic ic[]) |
APS_Lab | 0:f06ed53310a3 | 403 | { |
APS_Lab | 0:f06ed53310a3 | 404 | LTC681x_reset_crc_count(total_ic,ic); |
APS_Lab | 0:f06ed53310a3 | 405 | } |
APS_Lab | 0:f06ed53310a3 | 406 | |
APS_Lab | 0:f06ed53310a3 | 407 | //Helper function to intialize CFG variables. |
APS_Lab | 0:f06ed53310a3 | 408 | void LTC6811_init_cfg(uint8_t total_ic, cell_asic ic[]) |
APS_Lab | 0:f06ed53310a3 | 409 | { |
APS_Lab | 0:f06ed53310a3 | 410 | LTC681x_init_cfg(total_ic,ic); |
APS_Lab | 0:f06ed53310a3 | 411 | } |
APS_Lab | 0:f06ed53310a3 | 412 | //Helper function to set CFGR variable |
APS_Lab | 0:f06ed53310a3 | 413 | void LTC6811_set_cfgr(uint8_t nIC, cell_asic ic[], bool refon, bool adcopt, bool gpio[5],bool dcc[12]) |
APS_Lab | 0:f06ed53310a3 | 414 | { |
APS_Lab | 0:f06ed53310a3 | 415 | LTC681x_set_cfgr_refon(nIC,ic,refon); |
APS_Lab | 0:f06ed53310a3 | 416 | LTC681x_set_cfgr_adcopt(nIC,ic,adcopt); |
APS_Lab | 0:f06ed53310a3 | 417 | LTC681x_set_cfgr_gpio(nIC,ic,gpio); |
APS_Lab | 0:f06ed53310a3 | 418 | LTC681x_set_cfgr_dis(nIC,ic,dcc); |
APS_Lab | 0:f06ed53310a3 | 419 | } |
APS_Lab | 0:f06ed53310a3 | 420 | //Helper function to set the REFON bit |
APS_Lab | 0:f06ed53310a3 | 421 | void LTC6811_set_cfgr_refon(uint8_t nIC, cell_asic ic[], bool refon) |
APS_Lab | 0:f06ed53310a3 | 422 | { |
APS_Lab | 0:f06ed53310a3 | 423 | LTC681x_set_cfgr_refon(nIC,ic,refon); |
APS_Lab | 0:f06ed53310a3 | 424 | } |
APS_Lab | 0:f06ed53310a3 | 425 | //Helper function to set the adcopt bit |
APS_Lab | 0:f06ed53310a3 | 426 | void LTC6811_set_cfgr_adcopt(uint8_t nIC, cell_asic ic[], bool adcopt) |
APS_Lab | 0:f06ed53310a3 | 427 | { |
APS_Lab | 0:f06ed53310a3 | 428 | LTC681x_set_cfgr_adcopt(nIC,ic,adcopt); |
APS_Lab | 0:f06ed53310a3 | 429 | } |
APS_Lab | 0:f06ed53310a3 | 430 | //Helper function to set GPIO bits |
APS_Lab | 0:f06ed53310a3 | 431 | void LTC6811_set_cfgr_gpio(uint8_t nIC, cell_asic ic[],bool gpio[5]) |
APS_Lab | 0:f06ed53310a3 | 432 | { |
APS_Lab | 0:f06ed53310a3 | 433 | LTC681x_set_cfgr_gpio(nIC,ic,gpio); |
APS_Lab | 0:f06ed53310a3 | 434 | } |
APS_Lab | 0:f06ed53310a3 | 435 | //Helper function to control discharge |
APS_Lab | 0:f06ed53310a3 | 436 | void LTC6811_set_cfgr_dis(uint8_t nIC, cell_asic ic[],bool dcc[12]) |
APS_Lab | 0:f06ed53310a3 | 437 | { |
APS_Lab | 0:f06ed53310a3 | 438 | LTC681x_set_cfgr_dis(nIC,ic,dcc); |
APS_Lab | 0:f06ed53310a3 | 439 | } |
APS_Lab | 0:f06ed53310a3 | 440 | //Helper Function to set uv value in CFG register |
APS_Lab | 0:f06ed53310a3 | 441 | void LTC6811_set_cfgr_uv(uint8_t nIC, cell_asic ic[],uint16_t uv) |
APS_Lab | 0:f06ed53310a3 | 442 | { |
APS_Lab | 0:f06ed53310a3 | 443 | LTC681x_set_cfgr_uv(nIC, ic, uv); |
APS_Lab | 0:f06ed53310a3 | 444 | } |
APS_Lab | 0:f06ed53310a3 | 445 | //helper function to set OV value in CFG register |
APS_Lab | 0:f06ed53310a3 | 446 | void LTC6811_set_cfgr_ov(uint8_t nIC, cell_asic ic[],uint16_t ov) |
APS_Lab | 0:f06ed53310a3 | 447 | { |
APS_Lab | 0:f06ed53310a3 | 448 | LTC681x_set_cfgr_ov( nIC, ic, ov); |
APS_Lab | 0:f06ed53310a3 | 449 | } |