Skip to content

Commit

Permalink
generate ocv lut
Browse files Browse the repository at this point in the history
  • Loading branch information
tiandahuang committed Jul 3, 2024
1 parent e5844d4 commit c0d38c5
Show file tree
Hide file tree
Showing 5 changed files with 638 additions and 1 deletion.
360 changes: 360 additions & 0 deletions Apps/Inc/VoltageToSoC.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,360 @@
/**
* Look up table for determining state of charge from OCV
* OCV-SOC data pulled from a C/20 discharge curve for LG21700M50T cells.
*
* For more details and the LUT generation script, see `Tools/ocv-soc.ipynb`
*/

#ifndef VOLTAGE_TO_SOC_H
#define VOLTAGE_TO_SOC_H

#include <stdint.h>

#define OCV_SOC_LUT_SIZE 338
#define OCV_SOC_LUT_STRIDE 5
#define OCV_SOC_LUT_MIN_MV 2500
#define OCV_SOC_LUT_MAX_MV 4185
#define OCV_SOC_TOTAL_CAP_uAh 4657289

const uint32_t lg21700m50t_ocv_soc_lut_uAh[OCV_SOC_LUT_SIZE] = {
0,
1021,
2069,
3123,
4180,
5243,
6310,
7380,
8458,
9540,
10626,
11722,
12818,
13921,
15030,
16147,
17266,
18396,
19528,
20674,
21817,
22974,
24135,
25308,
26486,
27672,
28868,
30076,
31287,
32509,
33742,
34988,
36239,
37502,
38781,
40068,
41368,
42682,
44009,
45345,
46701,
48071,
49456,
50859,
52274,
53706,
55159,
56625,
58119,
59630,
61160,
62716,
64285,
65880,
67500,
69146,
70816,
72510,
74238,
75988,
77781,
79598,
81447,
83340,
85272,
87241,
89252,
91309,
93416,
95573,
97779,
100039,
102356,
104728,
107169,
109656,
112202,
114821,
117505,
120245,
123053,
125933,
128869,
131883,
134952,
138091,
141314,
144594,
147940,
151365,
154863,
158438,
162096,
165816,
169636,
173533,
177515,
181570,
185726,
189965,
194297,
198720,
203259,
207880,
212617,
217470,
222434,
227506,
232698,
238016,
243478,
249041,
254732,
260579,
266544,
272658,
278888,
285256,
291742,
298356,
305075,
311904,
318829,
325832,
332927,
340118,
347368,
354654,
362007,
369389,
376813,
384271,
391749,
399283,
406860,
414456,
422120,
429839,
437590,
445421,
453296,
461254,
469277,
477376,
485540,
493795,
502123,
510535,
519033,
527597,
536285,
545076,
553964,
562963,
572104,
581382,
590785,
600289,
609932,
619760,
629747,
639923,
650266,
660734,
671312,
681988,
692736,
703498,
714236,
724996,
735766,
746352,
756789,
766922,
776607,
785855,
794749,
803442,
811903,
820249,
828616,
837090,
846052,
855742,
866579,
878969,
893317,
909813,
928796,
950443,
974613,
1001268,
1030086,
1060526,
1091828,
1122758,
1151831,
1178137,
1201806,
1223552,
1243891,
1263628,
1283183,
1302786,
1322256,
1341928,
1361735,
1382067,
1403195,
1425259,
1448418,
1472618,
1497736,
1523451,
1549615,
1576120,
1602967,
1630415,
1658566,
1687671,
1717768,
1748889,
1780904,
1813525,
1846753,
1880164,
1913502,
1946611,
1979239,
2011272,
2042517,
2072953,
2102507,
2131197,
2159206,
2186370,
2212900,
2238749,
2264123,
2289018,
2313525,
2337716,
2361632,
2385337,
2408884,
2432405,
2455842,
2479321,
2502714,
2526225,
2549770,
2573406,
2597188,
2620976,
2644903,
2668929,
2693108,
2717333,
2741568,
2765828,
2790135,
2814306,
2838370,
2862259,
2885861,
2909094,
2932036,
2954546,
2976577,
2998283,
3019648,
3040709,
3061681,
3082659,
3103915,
3125576,
3147730,
3170475,
3193824,
3217598,
3241800,
3266276,
3290931,
3315543,
3340124,
3364361,
3388295,
3411892,
3435108,
3457994,
3480351,
3502409,
3524042,
3545439,
3566506,
3587381,
3608120,
3628709,
3649343,
3669967,
3690745,
3711612,
3732762,
3754228,
3776235,
3798718,
3821910,
3845906,
3871157,
3898000,
3927386,
3960999,
4001731,
4054622,
4123134,
4198733,
4268511,
4326954,
4374739,
4413802,
4446352,
4473976,
4497739,
4518576,
4537002,
4553568,
4568498,
4582138,
4594618,
4606113,
4616663,
4626417,
4635316,
4643302,
4650090,
4655080,
4657183,
4657289
};

#endif // VOLTAGE_TO_SOC_H
3 changes: 2 additions & 1 deletion Apps/Src/Charge.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
#include "Charge.h"
#include "BSP_Timer.h"
#include "VoltageToSoC.h"

#define CHARGE_RESOLUTION_SCALE 1000000 // What we need to multiply 100% by before storing. Ensure it is >= 10,000 to avoid depleted charge calculation issues
#define MAX_CHARGE_MILLI_AMP_HRS 41300 // In miliamp-hours (mAh), calculated from 12950(mah)*14 bats in parallel
Expand Down Expand Up @@ -61,7 +62,7 @@ void Charge_Calibrate(int8_t faultType){
* @return fixed point percentage. Resolution = 0.000001% (45,550,000 = 45.55%)
*/
uint32_t Charge_GetPercent(void){
return charge;
return lg21700m50t_ocv_soc_lut_uAh[0];
}

/** Charge_SetAccum
Expand Down
Binary file added Tools/lg21700m50t_data_mat/README.xlsx
Binary file not shown.
Binary file added Tools/lg21700m50t_data_mat/capacity_test.mat
Binary file not shown.
Loading

0 comments on commit c0d38c5

Please sign in to comment.