Merge remote-tracking branch 'upstream/edge' into upstream-master
[clinton/Smoothieware.git] / src / modules / tools / temperaturecontrol / Thermistor.h
1 /*
2 this file is part of smoothie (http://smoothieware.org/). the motion control part is heavily based on grbl (https://github.com/simen/grbl).
3 smoothie 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.
4 smoothie 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.
5 you should have received a copy of the gnu general public license along with smoothie. if not, see <http://www.gnu.org/licenses/>.
6 */
7
8 #ifndef THERMISTOR_H
9 #define THERMISTOR_H
10
11 #include "TempSensor.h"
12 #include "RingBuffer.h"
13 #include "Pin.h"
14
15 #include <tuple>
16
17 #define QUEUE_LEN 32
18
19 class StreamOutput;
20
21 class Thermistor : public TempSensor
22 {
23 public:
24 Thermistor();
25 ~Thermistor();
26
27 // TempSensor interface.
28 void UpdateConfig(uint16_t module_checksum, uint16_t name_checksum);
29 float get_temperature();
30 bool set_optional(const sensor_options_t& options);
31 bool get_optional(sensor_options_t& options);
32 void get_raw();
33 static std::tuple<float,float,float> calculate_steinhart_hart_coefficients(float t1, float r1, float t2, float r2, float t3, float r3);
34 static void print_predefined_thermistors(StreamOutput*);
35
36 private:
37 int new_thermistor_reading();
38 float adc_value_to_temperature(uint32_t adc_value);
39 void calc_jk();
40
41 // Thermistor computation settings using beta, not used if using Steinhart-Hart
42 float r0;
43 float t0;
44
45 // on board resistor settings
46 int r1;
47 int r2;
48
49 union {
50 // this saves memory as we only use either beta or SHH
51 struct{
52 float beta;
53 float j;
54 float k;
55 };
56 struct{
57 float c1;
58 float c2;
59 float c3;
60 };
61 };
62
63 Pin thermistor_pin;
64
65 float min_temp, max_temp;
66 struct {
67 bool bad_config:1;
68 bool use_steinhart_hart:1;
69 };
70 uint8_t thermistor_number;
71 };
72
73 #endif