TLMoto

Dependents:   BMS_2 BMS_4 BMS_8

Committer:
ser1516
Date:
Fri Sep 09 13:46:07 2016 +0000
Revision:
0:f6b9d13870f2
Child:
1:c55c4c93681f
imprime ate a celula 4

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ser1516 0:f6b9d13870f2 1 /*!
ser1516 0:f6b9d13870f2 2 LTC6804-1 Multicell Battery Monitor
ser1516 0:f6b9d13870f2 3
ser1516 0:f6b9d13870f2 4 http://www.linear.com/product/LTC6804-1
ser1516 0:f6b9d13870f2 5
ser1516 0:f6b9d13870f2 6 http://www.linear.com/product/LTC6804-1#demoboards
ser1516 0:f6b9d13870f2 7
ser1516 0:f6b9d13870f2 8 REVISION HISTORY
ser1516 0:f6b9d13870f2 9 $Revision: 4432 $
ser1516 0:f6b9d13870f2 10 $Date: 2015-11-30 14:03:02 -0800 (Mon, 30 Nov 2015) $
ser1516 0:f6b9d13870f2 11
ser1516 0:f6b9d13870f2 12 Copyright (c) 2013, Linear Technology Corp.(LTC)
ser1516 0:f6b9d13870f2 13 All rights reserved.
ser1516 0:f6b9d13870f2 14
ser1516 0:f6b9d13870f2 15 Redistribution and use in source and binary forms, with or without
ser1516 0:f6b9d13870f2 16 modification, are permitted provided that the following conditions are met:
ser1516 0:f6b9d13870f2 17
ser1516 0:f6b9d13870f2 18 1. Redistributions of source code must retain the above copyright notice, this
ser1516 0:f6b9d13870f2 19 list of conditions and the following disclaimer.
ser1516 0:f6b9d13870f2 20 2. Redistributions in binary form must reproduce the above copyright notice,
ser1516 0:f6b9d13870f2 21 this list of conditions and the following disclaimer in the documentation
ser1516 0:f6b9d13870f2 22 and/or other materials provided with the distribution.
ser1516 0:f6b9d13870f2 23
ser1516 0:f6b9d13870f2 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ser1516 0:f6b9d13870f2 25 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
ser1516 0:f6b9d13870f2 26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ser1516 0:f6b9d13870f2 27 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ser1516 0:f6b9d13870f2 28 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
ser1516 0:f6b9d13870f2 29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
ser1516 0:f6b9d13870f2 30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ser1516 0:f6b9d13870f2 31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
ser1516 0:f6b9d13870f2 32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
ser1516 0:f6b9d13870f2 33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ser1516 0:f6b9d13870f2 34
ser1516 0:f6b9d13870f2 35 The views and conclusions contained in the software and documentation are those
ser1516 0:f6b9d13870f2 36 of the authors and should not be interpreted as representing official policies,
ser1516 0:f6b9d13870f2 37 either expressed or implied, of Linear Technology Corp.
ser1516 0:f6b9d13870f2 38
ser1516 0:f6b9d13870f2 39 The Linear Technology Linduino is not affiliated with the official Arduino team.
ser1516 0:f6b9d13870f2 40 However, the Linduino is only possible because of the Arduino team's commitment
ser1516 0:f6b9d13870f2 41 to the open-source community. Please, visit http://www.arduino.cc and
ser1516 0:f6b9d13870f2 42 http://store.arduino.cc , and consider a purchase that will help fund their
ser1516 0:f6b9d13870f2 43 ongoing work.
ser1516 0:f6b9d13870f2 44
ser1516 0:f6b9d13870f2 45 Copyright 2013 Linear Technology Corp. (LTC)
ser1516 0:f6b9d13870f2 46 ***********************************************************/
ser1516 0:f6b9d13870f2 47
ser1516 0:f6b9d13870f2 48 /*! @file
ser1516 0:f6b9d13870f2 49 @ingroup LTC68041
ser1516 0:f6b9d13870f2 50 Header for LTC6804-1 Multicell Battery Monitor
ser1516 0:f6b9d13870f2 51 */
ser1516 0:f6b9d13870f2 52
ser1516 0:f6b9d13870f2 53 #ifndef LTC68041_H
ser1516 0:f6b9d13870f2 54 #define LTC68041_H
ser1516 0:f6b9d13870f2 55
ser1516 0:f6b9d13870f2 56
ser1516 0:f6b9d13870f2 57 #ifndef LTC6804_CS
ser1516 0:f6b9d13870f2 58 #define LTC6804_CS spi_cs
ser1516 0:f6b9d13870f2 59 #endif
ser1516 0:f6b9d13870f2 60
ser1516 0:f6b9d13870f2 61
ser1516 0:f6b9d13870f2 62 /*
ser1516 0:f6b9d13870f2 63 Pre computed crc15 table used for the LTC6804 PEC calculation
ser1516 0:f6b9d13870f2 64
ser1516 0:f6b9d13870f2 65 The code used to generate the crc15 table is:
ser1516 0:f6b9d13870f2 66
ser1516 0:f6b9d13870f2 67 void generate_crc15_table()
ser1516 0:f6b9d13870f2 68 {
ser1516 0:f6b9d13870f2 69 int remainder;
ser1516 0:f6b9d13870f2 70 for(int i = 0; i<256;i++)
ser1516 0:f6b9d13870f2 71 {
ser1516 0:f6b9d13870f2 72 remainder = i<< 7;
ser1516 0:f6b9d13870f2 73 for (int bit = 8; bit > 0; --bit)
ser1516 0:f6b9d13870f2 74 {
ser1516 0:f6b9d13870f2 75
ser1516 0:f6b9d13870f2 76 if ((remainder & 0x4000) > 0)//equivalent to remainder & 2^14 simply check for MSB
ser1516 0:f6b9d13870f2 77 {
ser1516 0:f6b9d13870f2 78 remainder = ((remainder << 1)) ;
ser1516 0:f6b9d13870f2 79 remainder = (remainder ^ 0x4599);
ser1516 0:f6b9d13870f2 80 }
ser1516 0:f6b9d13870f2 81 else
ser1516 0:f6b9d13870f2 82 {
ser1516 0:f6b9d13870f2 83 remainder = ((remainder << 1));
ser1516 0:f6b9d13870f2 84 }
ser1516 0:f6b9d13870f2 85 }
ser1516 0:f6b9d13870f2 86
ser1516 0:f6b9d13870f2 87 crc15Table[i] = remainder&0xFFFF;
ser1516 0:f6b9d13870f2 88
ser1516 0:f6b9d13870f2 89 }
ser1516 0:f6b9d13870f2 90 }
ser1516 0:f6b9d13870f2 91 */
ser1516 0:f6b9d13870f2 92
ser1516 0:f6b9d13870f2 93 static const unsigned int crc15Table[256] = {0x0,0xc599, 0xceab, 0xb32, 0xd8cf, 0x1d56, 0x1664, 0xd3fd, 0xf407, 0x319e, 0x3aac, //!<precomputed CRC15 Table
ser1516 0:f6b9d13870f2 94 0xff35, 0x2cc8, 0xe951, 0xe263, 0x27fa, 0xad97, 0x680e, 0x633c, 0xa6a5, 0x7558, 0xb0c1,
ser1516 0:f6b9d13870f2 95 0xbbf3, 0x7e6a, 0x5990, 0x9c09, 0x973b, 0x52a2, 0x815f, 0x44c6, 0x4ff4, 0x8a6d, 0x5b2e,
ser1516 0:f6b9d13870f2 96 0x9eb7, 0x9585, 0x501c, 0x83e1, 0x4678, 0x4d4a, 0x88d3, 0xaf29, 0x6ab0, 0x6182, 0xa41b,
ser1516 0:f6b9d13870f2 97 0x77e6, 0xb27f, 0xb94d, 0x7cd4, 0xf6b9, 0x3320, 0x3812, 0xfd8b, 0x2e76, 0xebef, 0xe0dd,
ser1516 0:f6b9d13870f2 98 0x2544, 0x2be, 0xc727, 0xcc15, 0x98c, 0xda71, 0x1fe8, 0x14da, 0xd143, 0xf3c5, 0x365c,
ser1516 0:f6b9d13870f2 99 0x3d6e, 0xf8f7,0x2b0a, 0xee93, 0xe5a1, 0x2038, 0x7c2, 0xc25b, 0xc969, 0xcf0, 0xdf0d,
ser1516 0:f6b9d13870f2 100 0x1a94, 0x11a6, 0xd43f, 0x5e52, 0x9bcb, 0x90f9, 0x5560, 0x869d, 0x4304, 0x4836, 0x8daf,
ser1516 0:f6b9d13870f2 101 0xaa55, 0x6fcc, 0x64fe, 0xa167, 0x729a, 0xb703, 0xbc31, 0x79a8, 0xa8eb, 0x6d72, 0x6640,
ser1516 0:f6b9d13870f2 102 0xa3d9, 0x7024, 0xb5bd, 0xbe8f, 0x7b16, 0x5cec, 0x9975, 0x9247, 0x57de, 0x8423, 0x41ba,
ser1516 0:f6b9d13870f2 103 0x4a88, 0x8f11, 0x57c, 0xc0e5, 0xcbd7, 0xe4e, 0xddb3, 0x182a, 0x1318, 0xd681, 0xf17b,
ser1516 0:f6b9d13870f2 104 0x34e2, 0x3fd0, 0xfa49, 0x29b4, 0xec2d, 0xe71f, 0x2286, 0xa213, 0x678a, 0x6cb8, 0xa921,
ser1516 0:f6b9d13870f2 105 0x7adc, 0xbf45, 0xb477, 0x71ee, 0x5614, 0x938d, 0x98bf, 0x5d26, 0x8edb, 0x4b42, 0x4070,
ser1516 0:f6b9d13870f2 106 0x85e9, 0xf84, 0xca1d, 0xc12f, 0x4b6, 0xd74b, 0x12d2, 0x19e0, 0xdc79, 0xfb83, 0x3e1a, 0x3528,
ser1516 0:f6b9d13870f2 107 0xf0b1, 0x234c, 0xe6d5, 0xede7, 0x287e, 0xf93d, 0x3ca4, 0x3796, 0xf20f, 0x21f2, 0xe46b, 0xef59,
ser1516 0:f6b9d13870f2 108 0x2ac0, 0xd3a, 0xc8a3, 0xc391, 0x608, 0xd5f5, 0x106c, 0x1b5e, 0xdec7, 0x54aa, 0x9133, 0x9a01,
ser1516 0:f6b9d13870f2 109 0x5f98, 0x8c65, 0x49fc, 0x42ce, 0x8757, 0xa0ad, 0x6534, 0x6e06, 0xab9f, 0x7862, 0xbdfb, 0xb6c9,
ser1516 0:f6b9d13870f2 110 0x7350, 0x51d6, 0x944f, 0x9f7d, 0x5ae4, 0x8919, 0x4c80, 0x47b2, 0x822b, 0xa5d1, 0x6048, 0x6b7a,
ser1516 0:f6b9d13870f2 111 0xaee3, 0x7d1e, 0xb887, 0xb3b5, 0x762c, 0xfc41, 0x39d8, 0x32ea, 0xf773, 0x248e, 0xe117, 0xea25,
ser1516 0:f6b9d13870f2 112 0x2fbc, 0x846, 0xcddf, 0xc6ed, 0x374, 0xd089, 0x1510, 0x1e22, 0xdbbb, 0xaf8, 0xcf61, 0xc453,
ser1516 0:f6b9d13870f2 113 0x1ca, 0xd237, 0x17ae, 0x1c9c, 0xd905, 0xfeff, 0x3b66, 0x3054, 0xf5cd, 0x2630, 0xe3a9, 0xe89b,
ser1516 0:f6b9d13870f2 114 0x2d02, 0xa76f, 0x62f6, 0x69c4, 0xac5d, 0x7fa0, 0xba39, 0xb10b, 0x7492, 0x5368, 0x96f1, 0x9dc3,
ser1516 0:f6b9d13870f2 115 0x585a, 0x8ba7, 0x4e3e, 0x450c, 0x8095
ser1516 0:f6b9d13870f2 116 };
ser1516 0:f6b9d13870f2 117
ser1516 0:f6b9d13870f2 118
ser1516 0:f6b9d13870f2 119
ser1516 0:f6b9d13870f2 120 /*!
ser1516 0:f6b9d13870f2 121
ser1516 0:f6b9d13870f2 122 |MD| Dec | ADC Conversion Model|
ser1516 0:f6b9d13870f2 123 |--|------|---------------------|
ser1516 0:f6b9d13870f2 124 |01| 1 | Fast |
ser1516 0:f6b9d13870f2 125 |10| 2 | Normal |
ser1516 0:f6b9d13870f2 126 |11| 3 | Filtered |
ser1516 0:f6b9d13870f2 127 */
ser1516 0:f6b9d13870f2 128 #define MD_FAST 1
ser1516 0:f6b9d13870f2 129 #define MD_NORMAL 2
ser1516 0:f6b9d13870f2 130 #define MD_FILTERED 3
ser1516 0:f6b9d13870f2 131
ser1516 0:f6b9d13870f2 132
ser1516 0:f6b9d13870f2 133 /*!
ser1516 0:f6b9d13870f2 134 |CH | Dec | Channels to convert |
ser1516 0:f6b9d13870f2 135 |---|------|---------------------|
ser1516 0:f6b9d13870f2 136 |000| 0 | All Cells |
ser1516 0:f6b9d13870f2 137 |001| 1 | Cell 1 and Cell 7 |
ser1516 0:f6b9d13870f2 138 |010| 2 | Cell 2 and Cell 8 |
ser1516 0:f6b9d13870f2 139 |011| 3 | Cell 3 and Cell 9 |
ser1516 0:f6b9d13870f2 140 |100| 4 | Cell 4 and Cell 10 |
ser1516 0:f6b9d13870f2 141 |101| 5 | Cell 5 and Cell 11 |
ser1516 0:f6b9d13870f2 142 |110| 6 | Cell 6 and Cell 12 |
ser1516 0:f6b9d13870f2 143 */
ser1516 0:f6b9d13870f2 144
ser1516 0:f6b9d13870f2 145 #define CELL_CH_ALL 0
ser1516 0:f6b9d13870f2 146 #define CELL_CH_1and7 1
ser1516 0:f6b9d13870f2 147 #define CELL_CH_2and8 2
ser1516 0:f6b9d13870f2 148 #define CELL_CH_3and9 3
ser1516 0:f6b9d13870f2 149 #define CELL_CH_4and10 4
ser1516 0:f6b9d13870f2 150 #define CELL_CH_5and11 5
ser1516 0:f6b9d13870f2 151 #define CELL_CH_6and12 6
ser1516 0:f6b9d13870f2 152
ser1516 0:f6b9d13870f2 153
ser1516 0:f6b9d13870f2 154 /*!
ser1516 0:f6b9d13870f2 155
ser1516 0:f6b9d13870f2 156 |CHG | Dec |Channels to convert |
ser1516 0:f6b9d13870f2 157 |----|------|----------------------|
ser1516 0:f6b9d13870f2 158 |000 | 0 | All GPIOS and 2nd Ref|
ser1516 0:f6b9d13870f2 159 |001 | 1 | GPIO 1 |
ser1516 0:f6b9d13870f2 160 |010 | 2 | GPIO 2 |
ser1516 0:f6b9d13870f2 161 |011 | 3 | GPIO 3 |
ser1516 0:f6b9d13870f2 162 |100 | 4 | GPIO 4 |
ser1516 0:f6b9d13870f2 163 |101 | 5 | GPIO 5 |
ser1516 0:f6b9d13870f2 164 |110 | 6 | Vref2 |
ser1516 0:f6b9d13870f2 165 */
ser1516 0:f6b9d13870f2 166
ser1516 0:f6b9d13870f2 167 #define AUX_CH_ALL 0
ser1516 0:f6b9d13870f2 168 #define AUX_CH_GPIO1 1
ser1516 0:f6b9d13870f2 169 #define AUX_CH_GPIO2 2
ser1516 0:f6b9d13870f2 170 #define AUX_CH_GPIO3 3
ser1516 0:f6b9d13870f2 171 #define AUX_CH_GPIO4 4
ser1516 0:f6b9d13870f2 172 #define AUX_CH_GPIO5 5
ser1516 0:f6b9d13870f2 173 #define AUX_CH_VREF2 6
ser1516 0:f6b9d13870f2 174
ser1516 0:f6b9d13870f2 175 //uint8_t CHG = 0; //!< aux channels to be converted
ser1516 0:f6b9d13870f2 176 /*!****************************************************
ser1516 0:f6b9d13870f2 177 \brief Controls if Discharging transitors are enabled
ser1516 0:f6b9d13870f2 178 or disabled during Cell conversions.
ser1516 0:f6b9d13870f2 179
ser1516 0:f6b9d13870f2 180 |DCP | Discharge Permitted During conversion |
ser1516 0:f6b9d13870f2 181 |----|----------------------------------------|
ser1516 0:f6b9d13870f2 182 |0 | No - discharge is not permitted |
ser1516 0:f6b9d13870f2 183 |1 | Yes - discharge is permitted |
ser1516 0:f6b9d13870f2 184
ser1516 0:f6b9d13870f2 185 ********************************************************/
ser1516 0:f6b9d13870f2 186 #define DCP_DISABLED 0
ser1516 0:f6b9d13870f2 187 #define DCP_ENABLED 1
ser1516 0:f6b9d13870f2 188
ser1516 0:f6b9d13870f2 189
ser1516 0:f6b9d13870f2 190
ser1516 0:f6b9d13870f2 191
ser1516 0:f6b9d13870f2 192 void LTC6804_initialize();
ser1516 0:f6b9d13870f2 193
ser1516 0:f6b9d13870f2 194 void set_adc(uint8_t MD, uint8_t DCP, uint8_t CH, uint8_t CHG);
ser1516 0:f6b9d13870f2 195
ser1516 0:f6b9d13870f2 196 void LTC6804_adcv();
ser1516 0:f6b9d13870f2 197
ser1516 0:f6b9d13870f2 198 void LTC6804_adax();
ser1516 0:f6b9d13870f2 199
ser1516 0:f6b9d13870f2 200 uint8_t LTC6804_rdcv(uint8_t reg, uint8_t total_ic, uint16_t cell_codes[][12]);
ser1516 0:f6b9d13870f2 201
ser1516 0:f6b9d13870f2 202 void LTC6804_rdcv_reg(uint8_t reg, uint8_t nIC, uint8_t *data);
ser1516 0:f6b9d13870f2 203
ser1516 0:f6b9d13870f2 204 int8_t LTC6804_rdaux(uint8_t reg, uint8_t nIC, uint16_t aux_codes[][6]);
ser1516 0:f6b9d13870f2 205
ser1516 0:f6b9d13870f2 206 void LTC6804_rdaux_reg(uint8_t reg, uint8_t nIC,uint8_t *data);
ser1516 0:f6b9d13870f2 207
ser1516 0:f6b9d13870f2 208 void LTC6804_clrcell();
ser1516 0:f6b9d13870f2 209
ser1516 0:f6b9d13870f2 210 void LTC6804_clraux();
ser1516 0:f6b9d13870f2 211
ser1516 0:f6b9d13870f2 212 void LTC6804_wrcfg(uint8_t nIC,uint8_t config[][6]);
ser1516 0:f6b9d13870f2 213
ser1516 0:f6b9d13870f2 214 int8_t LTC6804_rdcfg(uint8_t nIC, uint8_t r_config[][8]);
ser1516 0:f6b9d13870f2 215
ser1516 0:f6b9d13870f2 216 void wakeup_idle();
ser1516 0:f6b9d13870f2 217
ser1516 0:f6b9d13870f2 218 void wakeup_sleep();
ser1516 0:f6b9d13870f2 219
ser1516 0:f6b9d13870f2 220 uint16_t pec15_calc(uint8_t len, uint8_t *data);
ser1516 0:f6b9d13870f2 221
ser1516 0:f6b9d13870f2 222 void spi_write_array( uint8_t length, uint8_t *data);
ser1516 0:f6b9d13870f2 223
ser1516 0:f6b9d13870f2 224 void spi_write_read(uint8_t *TxData, uint8_t TXlen, uint8_t *rx_data, uint8_t RXlen);
ser1516 0:f6b9d13870f2 225 void output_low(uint8_t pin);
ser1516 0:f6b9d13870f2 226
ser1516 0:f6b9d13870f2 227 void output_high(uint8_t pin);
ser1516 0:f6b9d13870f2 228
ser1516 0:f6b9d13870f2 229 #endif