ESP-LiveControl  1.99.1
HTTP server, AJAX API backend and Vue.js web application implementing self-contained, zero-install WiFi remote control of hardware modules attached to the Espressif ESP32 SoC
sensor_kty81_1xx.hpp
Go to the documentation of this file.
1 
9 #ifndef SENSOR_KTY81_1XX_HPP__
10 #define SENSOR_KTY81_1XX_HPP__
11 
12 #include <array>
13 
14 #include "esp32_adc_channel.hpp"
15 #include "app_config.hpp"
16 
23 {
24  // Objects are constexpr, so members can be used as template parameters etc.
25  constexpr KTY81_1xxCommonConfig(){};
26 
31  adc_atten_t adc_ch_attenuation = ADC_ATTEN_DB_6;
33  size_t averaged_samples = 32;
35  size_t moving_average_filter_len = 32;
37  float temp_fsr_lower_lin = 0.0f;
38  float temp_fsr_upper_lin = 100.0f;
40  int32_t v_in_fsr_lower_lin = 886; // Corresponds to 0°C
41  int32_t v_in_fsr_upper_lin = 1428; // Corresponds to 100°C
42 
44 
45  int32_t v_in_fsr_lower_lut = 596; // Corresponds to -55°C
46  int32_t v_in_fsr_upper_lut = 1646; // Corresponds to 150°C
54  size_t lut_size = 32;
55  std::array<float, 32> lut_temp_kty81_121 {
56  // For KTY81-121:
57  -55.0 , -48.22273805, -41.51141124, -34.84623091,
58  -28.34434926, -22.05459193, -15.78849403, -9.53746745,
59  -3.3772341 , 2.7675195 , 8.9372679 , 15.0916243 ,
60  21.14820431, 27.2082161 , 33.34543424, 39.41134763,
61  45.57173941, 51.73398583, 57.85244115, 64.10680179,
62  70.45422093, 76.763773 , 83.14712256, 89.64071316,
63  96.17984636, 102.82297981, 109.58309561, 116.4296579 ,
64  123.60532846, 131.27866698, 139.78106609, 150.0};
65  // For KTY81-110 and KTY81-120:
66  std::array<float, 32> lut_temp_kty81_110_120 {
67  -55.0 , -48.16279303, -41.39749472, -34.8911357 ,
68  -28.54294667, -22.192432 , -15.83544756, -9.56004681,
69  -3.43833483, 2.66313257, 8.80135444, 14.90432723,
70  20.97767882, 27.03976174, 33.13792626, 39.28966437,
71  45.38382931, 51.48407173, 57.67841773, 63.97159787,
72  70.30279723, 76.61562129, 83.00362829, 89.50586837,
73  96.07234208, 102.68301035, 109.39886725, 116.34253305,
74  123.5137051 , 131.2558412 , 139.76912438, 150.0};
75 };
76 
77 
107 {
108 public:
109  static constexpr auto _common_conf = KTY81_1xxCommonConfig{};
110  ESP32ADCChannelFiltered<_common_conf.moving_average_filter_len> adc_ch;
111 
119  SensorKTY81_1xx(adc1_channel_t channel,
121 
126  void update_filter();
127 
137  float get_temp_pwl();
138 
147  float get_temp_lin();
148 
149 protected:
150  EquidistantPWLUInt16<_common_conf.lut_size> *_interpolator;
151 };
152 
153 
160 {
161 public:
162  SensorKTY81_121(adc1_channel_t channel)
163  : SensorKTY81_1xx{channel,
164  new EquidistantPWLUInt16<_common_conf.lut_size>{
165  _common_conf.lut_temp_kty81_121}
166  }
167  {}
168  ~SensorKTY81_121() {
169  delete _interpolator;
170  }
171 };
172 
179 {
180 public:
181  SensorKTY81_110_120(adc1_channel_t channel)
182  : SensorKTY81_1xx{channel,
183  new EquidistantPWLUInt16<_common_conf.lut_size>{
184  _common_conf.lut_temp_kty81_110_120}
185  }
186  {}
188  delete _interpolator;
189  }
190 };
191 
192 #endif
Application, network and hardware settings, constants and preset configuration.
ESP32 ADC 1 channel access with configurable moving average filter. Moving average filtering/smoothin...
Definition: esp32_adc_channel.hpp:106
KTY81-110 or KTY81-120 type silicon temperature sensor readout using the ESP32 ADC in its high-linear...
Definition: sensor_kty81_1xx.hpp:179
KTY81-121 type silicon temperature sensor readout using the ESP32 ADC in its high-linearity region.
Definition: sensor_kty81_1xx.hpp:160
KTY81-1xx type silicon temperature sensor readout and conversion functions using the ESP32 ADC in its...
Definition: sensor_kty81_1xx.hpp:107
SensorKTY81_1xx(adc1_channel_t channel, EquidistantPWLUInt16< _common_conf.lut_size > *interpolator)
Initialize the analog ADC channel for use with the sensor.
Definition: sensor_kty81_1xx.cpp:15
float get_temp_pwl()
Excellent precision temperature sensing using piecewise linear interpolation of Look-Up-Table values ...
Definition: sensor_kty81_1xx.cpp:41
void update_filter()
Updates the moving average with a new sampled value from ADC.
Definition: sensor_kty81_1xx.cpp:33
float get_temp_lin()
Fairly precise temperature conversion if the temperature sensor voltage has good linearisation....
Definition: sensor_kty81_1xx.cpp:49
Configuration constants and Look-Up-Table values which are supposed to be the same for all sensors.
Definition: sensor_kty81_1xx.hpp:23
int32_t v_in_fsr_lower_lut
Definition: sensor_kty81_1xx.hpp:45
size_t lut_size
Look-Up-Table temperatures for 31 equidistant voltage steps. Table only valid for linearised circuit ...
Definition: sensor_kty81_1xx.hpp:54
int32_t v_in_fsr_lower_lin
Definition: sensor_kty81_1xx.hpp:40
adc_atten_t adc_ch_attenuation
Suggested ADC input voltage Range for ESP32 using ADC_ATTEN_DB_6 is 150 ~ 1750 millivolts according t...
Definition: sensor_kty81_1xx.hpp:31