PT100.h 2.55 KB
Newer Older
João Lino's avatar
v0.1  
João Lino committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/*
  PT100.h - Library for measuring temperature with a PT100.
  Created by João Lino, June 24, 2015.
  Released into the public domain.
*/
#ifndef PT100_h
#define PT100_h

#include "Arduino.h"

#define DEBUG

#define CONSTANT_ADC_STEP_COUNT 	1024.0

#define TEMPERATURE_AVERAGE_VALUE_I				50
#define TEMPERATURE_AVERAGE_VALUE_F 			50.0
//#define TEMPERATURE_AVERATE_INIT_VALUES		0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
#define TEMPERATURE_AVERATE_INIT_VALUES		0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
#define TEMPERATURE_AVERATE_INIT_VALUES_I		0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
#define TEMPERATURE_SETTING_MAX_VALUE 		120

class PT100
{
  public:
		// PT100(PT100_OUTPUT_PIN, PT100_INPUT_PIN, PT100_TIME_BETWEEN_READINGS, PT100_DEFAULT_ADC_VMAX, PT100_DEFAULT_VS, PT100_DEFAULT_R1_RESISTENCE, PT100_DEFAULT_LINE_RESISTENCE, PT100_DEFAULT_OPERATION_RESISTENCE);
    PT100(char *name,
    				int OutputPin_SensorPower, 
					int InputPin_TemperatureReading, 
					int TimeBetweenReadings = 100, 
					float ADCVmax = 1.081, 
					float Vs = 4.87,
João Lino's avatar
João Lino committed
32
					float R1 = 606.0);
João Lino's avatar
v0.1  
João Lino committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46
    
		void setPower(float ADCVmax = 1.081, float Vs = 4.87);

		void measure(boolean ln);
		void safeHardwarePowerOff();
		
		float getCurrentTemperature();

		float getMeasuredTemperatureDeviation();
		float setMeasuredTemperatureDeviation( float measuredTemperatureDeviation);

		float setSampleDeviation( float sampleDeviation);
  
	private:
João Lino's avatar
João Lino committed
47 48 49 50 51 52 53
		char			*_name;
		int 			_OutputPin_SensorPower; 
		int 			_InputPin_TemperatureReading;
		int 			_TimeBetweenReadings;
		float 			_ADCVmax;
		float			_Vs;
		float 			_R1;
João Lino's avatar
v0.1  
João Lino committed
54 55 56 57 58 59
		
		float           _temperatureAverage;
		float           _measuredTemperature;
		float			_measuredTemperatureDeviation;
		float			_sampleDeviation;
		unsigned long   _lastTemperatureRead;
João Lino's avatar
João Lino committed
60 61
		int           	_VoutAnalogSample;
		int           	_VoutRAnalogSample;
João Lino's avatar
v0.1  
João Lino committed
62 63 64 65
		float           _VoutPreviousAnalogSample;
		int             _temperatureMeasurementsMarker;
		int             _rPT100MeasurementsMarker;
		float           _temperatureMeasurements[TEMPERATURE_AVERAGE_VALUE_I] = {TEMPERATURE_AVERATE_INIT_VALUES};
João Lino's avatar
João Lino committed
66
		int           	_rPT100Measurements[TEMPERATURE_AVERAGE_VALUE_I] = {TEMPERATURE_AVERATE_INIT_VALUES_I};
João Lino's avatar
v0.1  
João Lino committed
67 68 69 70 71 72

		float GetMedian(int array[]);
		float GetMode(float array[]);
};

#endif