forked from tinfever/FU-Dyson-BMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththermistor.h
255 lines (230 loc) · 5.44 KB
/
thermistor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/*
* FU-Dyson-BMS - (unofficial) Firmware Upgrade for Dyson BMS - V6/V7 Vacuums
* Copyright (C) 2022 tinfever
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The author can be contacted at tinfever6@(insert-everyone's-favorite-google-email-domain).com
*
* NOTE: As an addendum to the GNU General Public License, any hardware using code or information from this project must also make publicly available complete electrical schematics and a bill of materials for such hardware.
*/
#ifndef THERMISTOR_H
#define THERMISTOR_H
#include <stdint.h>
#include "main.h"
enum {
voltage = 0,
temp = 1,
};
/* First value in array is voltage at a given temperature, in 10mV steps. Ex. value of 24 = 240mV
Second value is temperature in Celsius
Data was computed in Google Sheets with the following layout and formulas:
* Column A is temperature in Celsius in 1 degree steps from 0-99C
* Column B is resistance of thermistor at temp with formula =$L$2/EXP(($L$3*((A2+273.15)-($L$1+273.15)))/((A2+273.15)*($L$1+273.15)))
* Column C is voltage output (mV) of the resistor + thermistor voltage divider with formula =1000*$L$5*B2/(B2+$L$6)
* Voltage values in mV were then divided by 10 and rounded to nearest whole number. Duplicate voltage values were removed, retaining highest temp duplicate.
* Lines containing voltage values greater than 255 were discarded.
* Variables were:
* Cell L1 = 25 = Thermistor rating temp in C
* Cell L2 = 10000 = Thermistor rated resistance at rating temp in Ohms
* Cell L3 = 3500 = beta of thermistor
* Cell L5 = 3.3 = Vin for resistor divider calc
* Cell L6 = 23700 = Thermistor series resistor / voltage divider resistance in Ohms
*/
//You could probably save 160 bytes of flash by removing the celsius values and using the array index as the temperature. Just have to add handling for when two temps would have same voltage.
#define SV09_LUT_SIZE_DEF 93
uint8_t const SV09_thermistor_LUT[SV09_LUT_SIZE_DEF][2] = {
{45,99},
{46,98},
{47,97},
{48,96},
{49,95},
{50,94},
{51,93},
{52,92},
{53,91},
{54,90},
{56,89},
{57,88},
{58,87},
{59,86},
{61,85},
{62,84},
{64,83},
{65,82},
{66,81},
{68,80},
{69,79},
{71,78},
{73,77},
{74,76},
{76,75},
{78,74},
{79,73},
{81,72},
{83,71},
{85,70},
{87,69},
{89,68},
{91,67},
{93,66},
{95,65},
{97,64},
{99,63},
{101,62},
{103,61},
{105,60},
{108,59},
{110,58},
{112,57},
{115,56},
{117,55},
{120,54},
{122,53},
{125,52},
{127,51},
{130,50},
{133,49},
{135,48},
{138,47},
{141,46},
{144,45},
{146,44},
{149,43},
{152,42},
{155,41},
{158,40},
{161,39},
{164,38},
{167,37},
{170,36},
{173,35},
{176,34},
{179,33},
{182,32},
{185,31},
{188,30},
{191,29},
{194,28},
{198,27},
{201,26},
{204,25},
{207,24},
{210,23},
{213,22},
{216,21},
{219,20},
{222,19},
{225,18},
{228,17},
{231,16},
{234,15},
{236,14},
{239,13},
{242,12},
{245,11},
{248,10},
{250,9},
{253,8},
{255,7}
};
#define SV11_LUT_SIZE_DEF 84
uint8_t const SV11_thermistor_LUT[SV11_LUT_SIZE_DEF][2] = {
{13,99},
{14,97},
{15,94},
{16,91},
{17,89},
{18,86},
{19,84},
{20,82},
{21,80},
{22,79},
{23,77},
{24,75},
{25,74},
{26,72},
{27,71},
{28,69},
{29,68},
{30,67},
{31,66},
{32,64},
{33,63},
{34,62},
{35,61},
{36,60},
{37,59},
{38,58},
{39,57},
{40,56},
{42,55},
{43,54},
{44,53},
{45,52},
{47,51},
{48,50},
{49,49},
{51,48},
{52,47},
{54,46},
{55,45},
{57,44},
{59,43},
{60,42},
{62,41},
{64,40},
{66,39},
{68,38},
{70,37},
{72,36},
{74,35},
{76,34},
{78,33},
{80,32},
{83,31},
{85,30},
{88,29},
{90,28},
{93,27},
{95,26},
{98,25},
{101,24},
{103,23},
{106,22},
{109,21},
{112,20},
{115,19},
{118,18},
{122,17},
{125,16},
{128,15},
{131,14},
{135,13},
{138,12},
{142,11},
{145,10},
{149,9},
{152,8},
{156,7},
{160,6},
{163,5},
{167,4},
{171,3},
{175,2},
{179,1},
{182,0}
};
const modelnum_t LUT_SIZE[NUM_OF_MODELS] = { //This works because the indexes in this array align with the enum modelnum_t from main.h
SV09_LUT_SIZE_DEF,
SV11_LUT_SIZE_DEF,
};
//I think this is a two element array of pointers, and each pointer itself points to a two element array.
//The target two element array can then be incremented to parse through the LUT elements.
uint8_t const (*ThermistorLUT[2])[2] = {SV09_thermistor_LUT, SV11_thermistor_LUT};
uint8_t getThermistorTemp (modelnum_t modelnum);
#endif /* THERMISTOR_H */