mn
Thermistor.h@2:ee3997416bcc, 2019-08-12 (annotated)
- Committer:
- attila0970
- Date:
- Mon Aug 12 11:10:04 2019 +0000
- Revision:
- 2:ee3997416bcc
- Parent:
- 1:601e1435dfb8
asd;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
unix_guru | 0:000a8be2414d | 1 | #ifndef THERMISTOR_H |
unix_guru | 0:000a8be2414d | 2 | #define THERMISTOR_H |
unix_guru | 0:000a8be2414d | 3 | /// |
unix_guru | 0:000a8be2414d | 4 | /// @mainpage Thermistor Temperature library |
unix_guru | 0:000a8be2414d | 5 | /// |
unix_guru | 0:000a8be2414d | 6 | /// This is a Thermistor to Temerature conversion library |
unix_guru | 0:000a8be2414d | 7 | /// |
unix_guru | 0:000a8be2414d | 8 | /// Much thanks to @Adafruit for this tutorial: |
unix_guru | 0:000a8be2414d | 9 | /// https://learn.adafruit.com/thermistor/using-a-thermistor |
unix_guru | 0:000a8be2414d | 10 | /// |
unix_guru | 0:000a8be2414d | 11 | /// The 100K Thermistor is configured with a 4.7k series resistor |
unix_guru | 0:000a8be2414d | 12 | /// tied to vcc (3.3v) like this: |
unix_guru | 0:000a8be2414d | 13 | /// |
unix_guru | 0:000a8be2414d | 14 | /// +3.3v |
unix_guru | 0:000a8be2414d | 15 | /// | |
unix_guru | 0:000a8be2414d | 16 | /// \ |
unix_guru | 0:000a8be2414d | 17 | /// / 4.7k series resistor |
unix_guru | 0:000a8be2414d | 18 | /// \ |
unix_guru | 0:000a8be2414d | 19 | /// / |
unix_guru | 0:000a8be2414d | 20 | /// | |
unix_guru | 0:000a8be2414d | 21 | /// .-----------O To Anlog pin on FRDM board |
unix_guru | 0:000a8be2414d | 22 | /// | |
unix_guru | 0:000a8be2414d | 23 | /// \ |
unix_guru | 0:000a8be2414d | 24 | /// / |
unix_guru | 0:000a8be2414d | 25 | /// Thermistor 100k Nominal |
unix_guru | 0:000a8be2414d | 26 | /// \ |
unix_guru | 0:000a8be2414d | 27 | /// / |
unix_guru | 0:000a8be2414d | 28 | /// | |
unix_guru | 0:000a8be2414d | 29 | /// --- |
unix_guru | 0:000a8be2414d | 30 | /// GND |
unix_guru | 0:000a8be2414d | 31 | /// |
unix_guru | 0:000a8be2414d | 32 | /// |
unix_guru | 0:000a8be2414d | 33 | /// @author Michael J. Ball |
unix_guru | 0:000a8be2414d | 34 | /// unix_guru at hotmail.com |
unix_guru | 0:000a8be2414d | 35 | /// @unix_guru on Twitter |
unix_guru | 0:000a8be2414d | 36 | /// March 2016 |
unix_guru | 0:000a8be2414d | 37 | /// |
unix_guru | 0:000a8be2414d | 38 | /// @code |
unix_guru | 1:601e1435dfb8 | 39 | /// #include "mbed.h" |
unix_guru | 1:601e1435dfb8 | 40 | /// #include "Thermistor.h" |
unix_guru | 1:601e1435dfb8 | 41 | /// |
unix_guru | 1:601e1435dfb8 | 42 | /// Serial pc(USBTX, USBRX); |
unix_guru | 1:601e1435dfb8 | 43 | /// |
unix_guru | 0:000a8be2414d | 44 | /// Thermistor bed(PTB10); |
unix_guru | 1:601e1435dfb8 | 45 | /// Thermistor extruder(PTB11); |
unix_guru | 1:601e1435dfb8 | 46 | /// |
unix_guru | 1:601e1435dfb8 | 47 | /// int main() |
unix_guru | 1:601e1435dfb8 | 48 | /// { |
unix_guru | 1:601e1435dfb8 | 49 | /// pc.baud(115200); |
unix_guru | 1:601e1435dfb8 | 50 | /// pc.printf("\r\nThermistor Test - Build " __DATE__ " " __TIME__ "\r\n"); |
unix_guru | 1:601e1435dfb8 | 51 | /// |
unix_guru | 1:601e1435dfb8 | 52 | /// while(1) { |
unix_guru | 1:601e1435dfb8 | 53 | /// pc.printf("Bed Temperature %f *C\r\n",bed.get_temperature()); |
unix_guru | 1:601e1435dfb8 | 54 | /// wait(.5); |
unix_guru | 1:601e1435dfb8 | 55 | /// pc.printf("Extruder Temperature %f *C\r\n",extruder.get_temperature()); |
unix_guru | 1:601e1435dfb8 | 56 | /// wait(.5); |
unix_guru | 1:601e1435dfb8 | 57 | /// } |
unix_guru | 1:601e1435dfb8 | 58 | /// } |
unix_guru | 1:601e1435dfb8 | 59 | |
unix_guru | 0:000a8be2414d | 60 | /// ... |
unix_guru | 0:000a8be2414d | 61 | /// @endcode |
unix_guru | 0:000a8be2414d | 62 | /// |
unix_guru | 0:000a8be2414d | 63 | /// @license |
unix_guru | 0:000a8be2414d | 64 | /// Licensed under the Apache License, Version 2.0 (the "License"); |
unix_guru | 0:000a8be2414d | 65 | /// you may not use this file except in compliance with the License. |
unix_guru | 0:000a8be2414d | 66 | /// You may obtain a copy of the License at |
unix_guru | 0:000a8be2414d | 67 | /// |
unix_guru | 0:000a8be2414d | 68 | /// http://www.apache.org/licenses/LICENSE-2.0 |
unix_guru | 0:000a8be2414d | 69 | /// |
unix_guru | 0:000a8be2414d | 70 | /// Unless required by applicable law or agreed to in writing, software |
unix_guru | 0:000a8be2414d | 71 | /// distributed under the License is distributed on an "AS IS" BASIS, |
unix_guru | 0:000a8be2414d | 72 | /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
unix_guru | 0:000a8be2414d | 73 | /// See the License for the specific language governing permissions and |
unix_guru | 0:000a8be2414d | 74 | /// limitations under the License. |
unix_guru | 0:000a8be2414d | 75 | /// |
unix_guru | 0:000a8be2414d | 76 | |
unix_guru | 0:000a8be2414d | 77 | |
unix_guru | 0:000a8be2414d | 78 | #include "mbed.h" |
unix_guru | 0:000a8be2414d | 79 | |
unix_guru | 0:000a8be2414d | 80 | |
attila0970 | 2:ee3997416bcc | 81 | #define THERMISTORNOMINAL 10000 // 100k default |
unix_guru | 0:000a8be2414d | 82 | // temp. for nominal resistance (almost always 25 C) |
unix_guru | 0:000a8be2414d | 83 | #define TEMPERATURENOMINAL 25 |
unix_guru | 0:000a8be2414d | 84 | // The beta coefficient of the thermistor (usually 3000-4000) |
unix_guru | 0:000a8be2414d | 85 | #define BCOEFFICIENT 3950 |
unix_guru | 0:000a8be2414d | 86 | // the value of the 'other' resistor |
unix_guru | 0:000a8be2414d | 87 | #define SERIESRESISTOR 4700 |
unix_guru | 0:000a8be2414d | 88 | |
unix_guru | 0:000a8be2414d | 89 | |
unix_guru | 0:000a8be2414d | 90 | class Thermistor { |
unix_guru | 0:000a8be2414d | 91 | public: |
unix_guru | 0:000a8be2414d | 92 | Thermistor(PinName pin); |
unix_guru | 0:000a8be2414d | 93 | /** Receives a PinName variable. |
unix_guru | 0:000a8be2414d | 94 | * @param pin mbed pin to which the thermistor is connected |
unix_guru | 0:000a8be2414d | 95 | */ |
unix_guru | 0:000a8be2414d | 96 | |
unix_guru | 0:000a8be2414d | 97 | |
unix_guru | 0:000a8be2414d | 98 | float get_temperature(); |
unix_guru | 0:000a8be2414d | 99 | /** This is the workhorse routine that calculates the temperature |
unix_guru | 0:000a8be2414d | 100 | * using the Steinhart-Hart equation for thermistors |
unix_guru | 0:000a8be2414d | 101 | * https://en.wikipedia.org/wiki/Steinhart%E2%80%93Hart_equation |
unix_guru | 0:000a8be2414d | 102 | */ |
unix_guru | 0:000a8be2414d | 103 | void init(); // Set default Steinhart-Hart values |
unix_guru | 0:000a8be2414d | 104 | void set_ThermistorNominal(float thermnom); // Change the thermistors nominal resistance |
unix_guru | 0:000a8be2414d | 105 | void set_TemperatureNominal(float tempnom); // Change the thermistors nominal temperature |
unix_guru | 0:000a8be2414d | 106 | void set_BCoefficient(float bcoefficient); // Change the thermistors BCoefficient |
unix_guru | 0:000a8be2414d | 107 | void set_SeriesResistor(float resistor); // Change the value of the series resistor |
unix_guru | 0:000a8be2414d | 108 | |
unix_guru | 0:000a8be2414d | 109 | private: |
unix_guru | 0:000a8be2414d | 110 | AnalogIn _pin; |
attila0970 | 2:ee3997416bcc | 111 | double ThermistorNominal; |
attila0970 | 2:ee3997416bcc | 112 | double TemperatureNominal; |
attila0970 | 2:ee3997416bcc | 113 | double BCoefficient; |
attila0970 | 2:ee3997416bcc | 114 | double SeriesResistor; |
unix_guru | 0:000a8be2414d | 115 | }; |
unix_guru | 0:000a8be2414d | 116 | |
unix_guru | 0:000a8be2414d | 117 | #endif |