Сбор информации о погодных условиях
Dependencies: RF24 USBDevice mbed
Sensors/Thermistor.h@6:db4538895ae7, 2015-12-05 (annotated)
- Committer:
- pro100kot14
- Date:
- Sat Dec 05 16:57:30 2015 +0000
- Revision:
- 6:db4538895ae7
- Parent:
- 4:7cd67d988145
Added unit testing. Test results are displayed on the device LEDs.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pro100kot14 | 1:8766173d267f | 1 | #ifndef Thermistor_H |
pro100kot14 | 1:8766173d267f | 2 | #define Thermistor_H |
pro100kot14 | 1:8766173d267f | 3 | |
pro100kot14 | 1:8766173d267f | 4 | #include "mbed.h" |
pro100kot14 | 1:8766173d267f | 5 | #include <math.h> |
pro100kot14 | 1:8766173d267f | 6 | /** |
pro100kot14 | 1:8766173d267f | 7 | * Reads the resistance of thermistor and using Steinhart–Hart equation |
pro100kot14 | 1:8766173d267f | 8 | * converts it to Celsius |
pro100kot14 | 1:8766173d267f | 9 | * |
pro100kot14 | 1:8766173d267f | 10 | */ |
pro100kot14 | 1:8766173d267f | 11 | class Thermistor{ |
pro100kot14 | 1:8766173d267f | 12 | public: |
pro100kot14 | 1:8766173d267f | 13 | /** |
pro100kot14 | 1:8766173d267f | 14 | * Constructor. In the calculations used a model of |
pro100kot14 | 1:8766173d267f | 15 | * the resistance of a semiconductor at different temperatures - |
pro100kot14 | 1:8766173d267f | 16 | * The Steinhart–Hart equation. Need to set the coefficients a, b, c. |
pro100kot14 | 1:8766173d267f | 17 | * |
pro100kot14 | 1:8766173d267f | 18 | * @param inputChanel The analog input is connected to the sensor |
pro100kot14 | 1:8766173d267f | 19 | * @param a Steinhart–Hart coefficient |
pro100kot14 | 1:8766173d267f | 20 | * @param b Steinhart–Hart coefficient |
pro100kot14 | 1:8766173d267f | 21 | * @param c Steinhart–Hart coefficient |
pro100kot14 | 1:8766173d267f | 22 | */ |
pro100kot14 | 1:8766173d267f | 23 | Thermistor(AnalogIn inputChanel, double a, double b, double c); |
pro100kot14 | 1:8766173d267f | 24 | |
pro100kot14 | 1:8766173d267f | 25 | /** |
pro100kot14 | 1:8766173d267f | 26 | * The temperature in degrees Celsius |
pro100kot14 | 1:8766173d267f | 27 | * @returns Temperature |
pro100kot14 | 1:8766173d267f | 28 | */ |
pro100kot14 | 1:8766173d267f | 29 | double getTemperature(); |
pro100kot14 | 1:8766173d267f | 30 | |
pro100kot14 | 1:8766173d267f | 31 | /** |
pro100kot14 | 6:db4538895ae7 | 32 | * The temperature in degrees Celsius, calculated based on a parameter. |
pro100kot14 | 6:db4538895ae7 | 33 | * Сomfortably for testing. |
pro100kot14 | 6:db4538895ae7 | 34 | * |
pro100kot14 | 6:db4538895ae7 | 35 | * @param adcVal ADC value on the port to which the sensor is connected |
pro100kot14 | 6:db4538895ae7 | 36 | * @param a Steinhart–Hart coefficient |
pro100kot14 | 6:db4538895ae7 | 37 | * @param b Steinhart–Hart coefficient |
pro100kot14 | 6:db4538895ae7 | 38 | * @param c Steinhart–Hart coefficient |
pro100kot14 | 6:db4538895ae7 | 39 | * @param error Error in Ohms (0 by default) |
pro100kot14 | 6:db4538895ae7 | 40 | * |
pro100kot14 | 6:db4538895ae7 | 41 | * @returns Temperature |
pro100kot14 | 6:db4538895ae7 | 42 | */ |
pro100kot14 | 6:db4538895ae7 | 43 | static double getTemperatureByAdcValue(float adcVal, double a, double b, double c, double error = 0); |
pro100kot14 | 6:db4538895ae7 | 44 | |
pro100kot14 | 6:db4538895ae7 | 45 | /** |
pro100kot14 | 1:8766173d267f | 46 | * Set error value used in the calculation. |
pro100kot14 | 1:8766173d267f | 47 | * The resulting resistance is computed as <real resistance> - error; |
pro100kot14 | 1:8766173d267f | 48 | * @param error Error in Ohms |
pro100kot14 | 1:8766173d267f | 49 | */ |
pro100kot14 | 1:8766173d267f | 50 | void setError(double error); |
pro100kot14 | 1:8766173d267f | 51 | |
pro100kot14 | 1:8766173d267f | 52 | /** |
pro100kot14 | 1:8766173d267f | 53 | * Error value used in the calculation |
pro100kot14 | 1:8766173d267f | 54 | * The resulting resistance is computed as <real resistance> - error; |
pro100kot14 | 1:8766173d267f | 55 | * @returns Error in Ohms |
pro100kot14 | 1:8766173d267f | 56 | */ |
pro100kot14 | 1:8766173d267f | 57 | double getError(); |
pro100kot14 | 1:8766173d267f | 58 | |
pro100kot14 | 1:8766173d267f | 59 | /** |
pro100kot14 | 1:8766173d267f | 60 | * Set a coefficient of Steinhart–Hart equation |
pro100kot14 | 1:8766173d267f | 61 | * @param a a-coefficient |
pro100kot14 | 1:8766173d267f | 62 | */ |
pro100kot14 | 1:8766173d267f | 63 | void setCoefficientA(double a); |
pro100kot14 | 1:8766173d267f | 64 | |
pro100kot14 | 1:8766173d267f | 65 | /** |
pro100kot14 | 1:8766173d267f | 66 | * Set b coefficient of Steinhart–Hart equation |
pro100kot14 | 1:8766173d267f | 67 | * @param b b-coefficient |
pro100kot14 | 1:8766173d267f | 68 | */ |
pro100kot14 | 1:8766173d267f | 69 | void setCoefficientB(double b); |
pro100kot14 | 1:8766173d267f | 70 | |
pro100kot14 | 1:8766173d267f | 71 | /** |
pro100kot14 | 1:8766173d267f | 72 | * Set c coefficient of Steinhart–Hart equation |
pro100kot14 | 1:8766173d267f | 73 | * @param c c-coefficient |
pro100kot14 | 1:8766173d267f | 74 | */ |
pro100kot14 | 1:8766173d267f | 75 | void setCoefficientC(double c); |
pro100kot14 | 1:8766173d267f | 76 | |
pro100kot14 | 1:8766173d267f | 77 | /** |
pro100kot14 | 1:8766173d267f | 78 | * a coefficient of Steinhart–Hart equation |
pro100kot14 | 1:8766173d267f | 79 | * @returns a coefficient |
pro100kot14 | 1:8766173d267f | 80 | */ |
pro100kot14 | 1:8766173d267f | 81 | double getCoefficientA(); |
pro100kot14 | 1:8766173d267f | 82 | |
pro100kot14 | 1:8766173d267f | 83 | /** |
pro100kot14 | 1:8766173d267f | 84 | * b coefficient of Steinhart–Hart equation |
pro100kot14 | 1:8766173d267f | 85 | * @returns b coefficient |
pro100kot14 | 1:8766173d267f | 86 | */ |
pro100kot14 | 1:8766173d267f | 87 | double getCoefficientB(); |
pro100kot14 | 1:8766173d267f | 88 | |
pro100kot14 | 1:8766173d267f | 89 | /** |
pro100kot14 | 1:8766173d267f | 90 | * c coefficient of Steinhart–Hart equation |
pro100kot14 | 1:8766173d267f | 91 | * @returns c coefficient |
pro100kot14 | 1:8766173d267f | 92 | */ |
pro100kot14 | 1:8766173d267f | 93 | double getCoefficientC(); |
pro100kot14 | 1:8766173d267f | 94 | |
pro100kot14 | 1:8766173d267f | 95 | private: |
pro100kot14 | 1:8766173d267f | 96 | AnalogIn input; |
pro100kot14 | 1:8766173d267f | 97 | //Thermistor error in Ohms |
pro100kot14 | 1:8766173d267f | 98 | double error; |
pro100kot14 | 1:8766173d267f | 99 | double a, b, c; |
pro100kot14 | 1:8766173d267f | 100 | }; |
pro100kot14 | 1:8766173d267f | 101 | |
pro100kot14 | 6:db4538895ae7 | 102 | /** |
pro100kot14 | 6:db4538895ae7 | 103 | * Tested the class Thermistor |
pro100kot14 | 6:db4538895ae7 | 104 | */ |
pro100kot14 | 6:db4538895ae7 | 105 | class ThermistorTest{ |
pro100kot14 | 6:db4538895ae7 | 106 | public: |
pro100kot14 | 6:db4538895ae7 | 107 | static bool adcValue_0_049_is_0_degree(); |
pro100kot14 | 6:db4538895ae7 | 108 | static bool adcValue_0_104_is_15_degree(); |
pro100kot14 | 6:db4538895ae7 | 109 | static bool adcValue_0_202_is_30_degree(); |
pro100kot14 | 6:db4538895ae7 | 110 | }; |
pro100kot14 | 6:db4538895ae7 | 111 | |
pro100kot14 | 1:8766173d267f | 112 | #endif |