~gabe/flashlight-firmware/anduril2

188.4.12 by Selene Scriven
updated NarsilM to 1.3, based on Tom E's NarsilMulti v1.3 2019-04-25.zip
1
#ifndef TK_CALIBRATION_H
2
#define TK_CALIBRATION_H
3
/*
4
 * Attiny calibration header.
5
 * This allows using a single set of hardcoded values across multiple projects.
6
 *
7
 * Copyright (C) 2015 Selene Scriven
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation, either version 3 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
25
/********************** Voltage ADC calibration **************************/
26
27
//-------------------------------------------------------------------------------------------
28
//  The tables below represent the max value for reporting of that associated voltage value.
29
// For example, for 3.0V reporting in the 1000K table, the max value is 125, but the range
30
// for 3.0V is 122 to 125.
31
// The tables are all calculated values, the equations used: 
32
//
33
//  ADC_FACTOR = R2/ (R2+R1) * 256/1.1, Val = (V - D1) * ADC_FACTOR
34
//
35
//-------------------------------------------------------------------------------------------
36
37
38
#ifdef USING_1000K   // GT-buck
39
// The ADC values we expect for specific voltages: 2.2v to 4.4v per cell. This is
40
//  for 4S cells (17.6V max) using R1=1000K, R2=47K, D1=0, and direct connection from Batt+
41
//  to R1, no diode in-between
42
//
43
#define ADC_22     94
44
#define ADC_23     98
45
#define ADC_24     102
46
#define ADC_25     107
47
#define ADC_26     111
48
#define ADC_27     115
49
#define ADC_28     119	//   0%
50
#define ADC_29     123
51
#define ADC_30     127
52
#define ADC_31     132
53
#define ADC_32     136
54
#define ADC_33     140
55
#define ADC_34     144
56
#define ADC_35     148	//  25% (3.5V)
57
#define ADC_36     153
58
#define ADC_37     157	//  50% (3.72V)
59
#define ADC_38     161
60
#define ADC_39     165
61
#define ADC_40     169	//  75% (3.95V)
62
#define ADC_41     173
63
#define ADC_42     178	// 100%
64
#define ADC_43     182
65
#define ADC_44     188
66
#endif
67
68
#ifdef USING_360K
69
// The ADC values we expect for specific voltages: 4.4V to 8.8V (2.2v to 4.4v per cell). This is
70
//  for using R1=360K/36K, R2=47K/4.7K, and direct connection from Batt+
71
//  to R1, no diode in-between, with an LDO and a 2S battery configuration.
72
73
// MAX value for the voltage range:
74
#define ADC_22     121
75
#define ADC_23     126
76
#define ADC_24     132
77
#define ADC_25     137
78
#define ADC_26     142
79
#define ADC_27     148
80
#define ADC_28     153	//   0%
81
#define ADC_29     159
82
#define ADC_30     164
83
#define ADC_31     169
84
#define ADC_32     175
85
#define ADC_33     180
86
#define ADC_34     185
87
#define ADC_35     191	//  25% (3.5V)
88
#define ADC_36     196
89
#define ADC_37     202	//  50% (3.72V)
90
#define ADC_38     207
91
#define ADC_39     212
92
#define ADC_40     218	//  75% (3.95V)
93
#define ADC_41     223
94
#define ADC_42     228	// 100%
95
#define ADC_43     234
96
#define ADC_44     239
97
#endif
98
99
#ifdef USING_220K
100
// The ADC values we expect for specific voltages: 2.2v to 4.4v. This is
101
//  for using R1=220K/22K, R2=47K/4.7K, and direct connection from Batt+
102
//  to R1, no diode in-between
103
#define ADC_22     92
104
#define ADC_23     96
105
#define ADC_24     100
106
#define ADC_25     104
107
#define ADC_26     109
108
#define ADC_27     113
109
#define ADC_28     117	//   0%
110
#define ADC_29     121
111
#define ADC_30     125
112
#define ADC_31     129
113
#define ADC_32     133
114
#define ADC_33     137
115
#define ADC_34     141
116
#define ADC_35     145	//  25% (3.5V)
117
#define ADC_36     150
118
#define ADC_37     154	//  50% (3.72V)
119
#define ADC_38     158
120
#define ADC_39     162
121
#define ADC_40     166	//  75% (3.95V)
122
#define ADC_41     170
123
#define ADC_42     174	// 100%
124
#define ADC_43     178
125
#define ADC_44     182
126
#endif
127
128
#define ADC_LOW    ADC_30  // When do we start ramping down
129
#define ADC_CRIT   ADC_28  // When do we shut the light off
130
131
#endif  // TK_CALIBRATION_H