Merge remote-tracking branch 'upstream/edge' into upstream-master
[clinton/Smoothieware.git] / src / modules / tools / temperaturecontrol / Thermistor.h
CommitLineData
9d955060 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
76f53dc6
JM
8#ifndef THERMISTOR_H
9#define THERMISTOR_H
9d955060 10
11#include "TempSensor.h"
12#include "RingBuffer.h"
76f53dc6 13#include "Pin.h"
9d955060 14
1f8dab1a
JM
15#include <tuple>
16
67bcde10 17#define QUEUE_LEN 32
9d955060 18
4c8f5447 19class StreamOutput;
9d955060 20
21class Thermistor : public TempSensor
22{
23 public:
d8baddd9 24 Thermistor();
25 ~Thermistor();
f1e38d95 26
d8baddd9 27 // TempSensor interface.
28 void UpdateConfig(uint16_t module_checksum, uint16_t name_checksum);
9d955060 29 float get_temperature();
f1e38d95
JM
30 bool set_optional(const sensor_options_t& options);
31 bool get_optional(sensor_options_t& options);
76f53dc6 32 void get_raw();
1f8dab1a 33 static std::tuple<float,float,float> calculate_steinhart_hart_coefficients(float t1, float r1, float t2, float r2, float t3, float r3);
4c8f5447 34 static void print_predefined_thermistors(StreamOutput*);
f1e38d95 35
9d955060 36 private:
d8baddd9 37 int new_thermistor_reading();
c0c44ac0 38 float adc_value_to_temperature(uint32_t adc_value);
f1e38d95 39 void calc_jk();
9d955060 40
3bf6fbfd 41 // Thermistor computation settings using beta, not used if using Steinhart-Hart
9d955060 42 float r0;
43 float t0;
ea4d3faa
JM
44
45 // on board resistor settings
9d955060 46 int r1;
47 int r2;
0f50aa5a
JM
48
49 union {
50 // this saves memory as we only use either beta or SHH
76f53dc6
JM
51 struct{
52 float beta;
53 float j;
54 float k;
55 };
56 struct{
57 float c1;
58 float c2;
59 float c3;
60 };
0f50aa5a 61 };
9d955060 62
63 Pin thermistor_pin;
64
5ec4700e 65 float min_temp, max_temp;
76f53dc6
JM
66 struct {
67 bool bad_config:1;
68 bool use_steinhart_hart:1;
69 };
a2e5f877 70 uint8_t thermistor_number;
9d955060 71};
72
73#endif