Creation de la bibliothèque de mesure de temperature
This commit is contained in:
parent
964c921738
commit
84b3bd56c8
19
lib/MeasureUnit/AdcSetting.cpp
Normal file
19
lib/MeasureUnit/AdcSetting.cpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include "AdcSetting.h"
|
||||||
|
|
||||||
|
AdcSetting::AdcSetting(double vref,
|
||||||
|
uint8_t adcResolution,
|
||||||
|
uint8_t measureIteration,
|
||||||
|
uint16_t delayBetweenIteration) : _vref(vref), _adcResolution(adcResolution), _measureIteration(measureIteration), _delayBetweenIteration(delayBetweenIteration), _quantum(vref/(pow(2.0,(double) adcResolution)-1))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t AdcSetting::getMeasureIteration()
|
||||||
|
{
|
||||||
|
return _measureIteration;
|
||||||
|
}
|
||||||
|
|
||||||
|
double AdcSetting::getQuantum()
|
||||||
|
{
|
||||||
|
return _quantum;
|
||||||
|
}
|
25
lib/MeasureUnit/AdcSetting.h
Normal file
25
lib/MeasureUnit/AdcSetting.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef ADCSETTING_H
|
||||||
|
#define ADCSETTING_H
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
class AdcSetting
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
AdcSetting(double vref, uint8_t adcResolution, uint8_t measureIteration = 5, uint16_t delayBetweenIteration = 5);
|
||||||
|
~AdcSetting(){}
|
||||||
|
|
||||||
|
uint8_t getMeasureIteration();
|
||||||
|
uint16_t getDelayBetweenIteration(){ return _delayBetweenIteration;}
|
||||||
|
double getQuantum();
|
||||||
|
double getVref(){return _vref;}
|
||||||
|
protected:
|
||||||
|
private:
|
||||||
|
double _vref;
|
||||||
|
uint8_t _adcResolution;
|
||||||
|
double _quantum;
|
||||||
|
uint8_t _measureIteration;
|
||||||
|
uint16_t _delayBetweenIteration;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //ADCSETTING_H
|
121
lib/MeasureUnit/MeasureUnit.cpp
Normal file
121
lib/MeasureUnit/MeasureUnit.cpp
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
#include "MeasureUnit.h"
|
||||||
|
|
||||||
|
MeasureUnit::MeasureUnit(uint8_t *analogInput,
|
||||||
|
uint16_t thermistorCount,
|
||||||
|
uint64_t precResistor,
|
||||||
|
ThermistorSetting thermistorSetting,
|
||||||
|
AdcSetting adcSetting) : _analogInput(analogInput), _thermistorCount(thermistorCount), _precResistor(precResistor), _thermistorSetting(thermistorSetting), _adcSetting(adcSetting), _globalOffset(0), _error(OK)
|
||||||
|
{
|
||||||
|
//Allocation dynamique des différent tableaux
|
||||||
|
_temperatures = (double*) calloc(_thermistorCount, sizeof(double));
|
||||||
|
_rOffsetMap = (double*) calloc(_thermistorCount, sizeof(double));
|
||||||
|
_resistanceMap = (double*) calloc(_thermistorCount, sizeof(double));
|
||||||
|
|
||||||
|
if(_temperatures == NULL || _rOffsetMap == NULL || _resistanceMap == NULL)
|
||||||
|
{
|
||||||
|
_error = MALLOC_ERR;
|
||||||
|
_temperatures != NULL ? free(_temperatures):(void)_temperatures;
|
||||||
|
_rOffsetMap != NULL ? free(_rOffsetMap):(void)_rOffsetMap;
|
||||||
|
_resistanceMap != NULL ? free(_resistanceMap):(void)_resistanceMap;
|
||||||
|
|
||||||
|
_temperatures = NULL;
|
||||||
|
_rOffsetMap = NULL;
|
||||||
|
_resistanceMap = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MeasureUnit::~MeasureUnit()
|
||||||
|
{
|
||||||
|
if(_error != MALLOC_ERR)
|
||||||
|
{
|
||||||
|
free(_temperatures);
|
||||||
|
free(_rOffsetMap);
|
||||||
|
free(_resistanceMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Methode permettant d'effectuer les mesures de température et de les récupérer
|
||||||
|
*/
|
||||||
|
double *MeasureUnit::getTemperatures()
|
||||||
|
{
|
||||||
|
double courant(0), deltaTension(0);
|
||||||
|
//1) Nous calculons le courant présent dans la branche grace à la résistance de précision
|
||||||
|
#ifdef DEBUG
|
||||||
|
Serial.println("-------------");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
for(int i(0); i < _adcSetting.getMeasureIteration(); i++)
|
||||||
|
{
|
||||||
|
delay(_adcSetting.getDelayBetweenIteration());
|
||||||
|
|
||||||
|
int sample = analogRead(_analogInput[0]);
|
||||||
|
deltaTension += sample;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
Serial.print("Adc value : ");Serial.println(sample);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
Serial.println("-------------");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
deltaTension /= _adcSetting.getMeasureIteration();
|
||||||
|
#ifdef DEBUG
|
||||||
|
Serial.print("Adc value average : ");Serial.println(deltaTension);
|
||||||
|
#endif
|
||||||
|
deltaTension *= _adcSetting.getQuantum();
|
||||||
|
#ifdef DEBUG
|
||||||
|
char buffer[10] = "";
|
||||||
|
sprintf(buffer,"%.8f", deltaTension);
|
||||||
|
Serial.print("R prec voltage : ");Serial.println(buffer);
|
||||||
|
#endif
|
||||||
|
courant = deltaTension / (double) _precResistor;
|
||||||
|
#ifdef DEBUG
|
||||||
|
sprintf(buffer,"%.8f", courant);
|
||||||
|
Serial.print("R prec current : ");Serial.println(buffer);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//2) Nous calculons le delta de tensions pour chaque thermistances
|
||||||
|
for(int i(1); i < _thermistorCount; i++)
|
||||||
|
{
|
||||||
|
for(int j(0); j < _adcSetting.getMeasureIteration(); j++)
|
||||||
|
{
|
||||||
|
delay(_adcSetting.getDelayBetweenIteration());
|
||||||
|
|
||||||
|
int sample = analogRead(_analogInput[i]);
|
||||||
|
_resistanceMap[i-1] += sample;
|
||||||
|
}
|
||||||
|
_resistanceMap[i-1] /= _adcSetting.getMeasureIteration();
|
||||||
|
if(i == 1)
|
||||||
|
_resistanceMap[i-1] -= deltaTension;
|
||||||
|
else
|
||||||
|
_resistanceMap[i-1] -= _resistanceMap[i-2];
|
||||||
|
}
|
||||||
|
|
||||||
|
//Pour la dernière valeur:
|
||||||
|
_resistanceMap[7] = _adcSetting.getVref() - _resistanceMap[6];
|
||||||
|
|
||||||
|
|
||||||
|
for(int i(0); i < _thermistorCount; i++)
|
||||||
|
{
|
||||||
|
//3) Nous en déduisons la résistance
|
||||||
|
_resistanceMap[i] /= courant;
|
||||||
|
//4) Nous en déduisons la temperature
|
||||||
|
_temperatures[i] = (((25.0+273.15) * (double)_thermistorSetting.getBeta()) / ((double)_thermistorSetting.getBeta() + (25.0+273.15)*log(_resistanceMap[i]/(double) _thermistorSetting.getRat25()))) - 273.15;
|
||||||
|
}
|
||||||
|
|
||||||
|
return _temperatures;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MeasureUnit::setGlobalTempOffset(double offset)
|
||||||
|
{
|
||||||
|
_globalOffset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
double MeasureUnit::getGlobalTempOffset()
|
||||||
|
{
|
||||||
|
return _globalOffset;
|
||||||
|
}
|
35
lib/MeasureUnit/MeasureUnit.h
Normal file
35
lib/MeasureUnit/MeasureUnit.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef MEASUREUNIT_H
|
||||||
|
#define MEASUREUNIT_H
|
||||||
|
#include "AdcSetting.h"
|
||||||
|
#include "ThermistorSetting.h"
|
||||||
|
|
||||||
|
#define DEBUG
|
||||||
|
|
||||||
|
class MeasureUnit
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
enum ERROR {OK = 0, MALLOC_ERR = 1};
|
||||||
|
MeasureUnit(uint8_t *analogInput, uint16_t thermistorCount, uint64_t precResistor, ThermistorSetting thermistorSetting, AdcSetting adcSetting);
|
||||||
|
~MeasureUnit();
|
||||||
|
void setGlobalTempOffset(double offset);
|
||||||
|
double getGlobalTempOffset();
|
||||||
|
double *getTemperatures();
|
||||||
|
|
||||||
|
ERROR getError(){return _error;}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
private:
|
||||||
|
double _globalOffset; //Correspond à l'offset global nécessaire afin d'avoir une température qui corresponde à la réalité
|
||||||
|
double *_temperatures; //Tableau contenant toutes les températures
|
||||||
|
double *_rOffsetMap; //Tableau qui contient les offsets individuels pour chaque thermistance
|
||||||
|
double *_resistanceMap; //Tableau qui contient les resistances associées aux thermistances (pour debug seulement)
|
||||||
|
uint8_t *_analogInput; //Pointeur qui garde l'adresse du tableau contenant le nom des entrées analogiques
|
||||||
|
uint16_t _thermistorCount;
|
||||||
|
uint64_t _precResistor;
|
||||||
|
ERROR _error;
|
||||||
|
|
||||||
|
AdcSetting _adcSetting;
|
||||||
|
ThermistorSetting _thermistorSetting;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //MEASUREUNIT_H
|
30
lib/MeasureUnit/MeasureUnit.ino
Normal file
30
lib/MeasureUnit/MeasureUnit.ino
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* Cet exemple correspond à l'application de test de la bibliothèque MeasureUnit qui
|
||||||
|
* permet de calculer la température mesurée par une matrice de thermistance
|
||||||
|
*
|
||||||
|
* Anatole SCHRAMM-HENRY
|
||||||
|
* 17/12/2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "MeasureUnit.h"
|
||||||
|
|
||||||
|
uint8_t analogInput[] = {PA0,PA1,PA2,PA3,PA4,PA5,PA6,PA7};
|
||||||
|
ThermistorSetting thermistorSetting(4050, 47000);
|
||||||
|
AdcSetting adcSetting(3.3, 12, 30, 20);
|
||||||
|
|
||||||
|
MeasureUnit measureUnit(analogInput, 8, 1000, thermistorSetting, adcSetting);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
// put your setup code here, to run once:
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("Start setup");
|
||||||
|
|
||||||
|
Serial.println("End setup");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// put your main code here, to run repeatedly:
|
||||||
|
measureUnit.getTemperatures();
|
||||||
|
delay(5000);
|
||||||
|
}
|
21
lib/MeasureUnit/ThermistorSetting.cpp
Normal file
21
lib/MeasureUnit/ThermistorSetting.cpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include "ThermistorSetting.h"
|
||||||
|
|
||||||
|
ThermistorSetting::ThermistorSetting(uint16_t beta, uint64_t rAt25) : _beta(beta), _rAt25(rAt25)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ThermistorSetting::~ThermistorSetting()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t ThermistorSetting::getBeta()
|
||||||
|
{
|
||||||
|
return _beta;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t ThermistorSetting::getRat25()
|
||||||
|
{
|
||||||
|
return _rAt25;
|
||||||
|
}
|
18
lib/MeasureUnit/ThermistorSetting.h
Normal file
18
lib/MeasureUnit/ThermistorSetting.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef THERMISTORSETTING_H
|
||||||
|
#define THERMISTORSETTING_H
|
||||||
|
#include <Arduino.h> //Necessaire afin d'avoir les types : uintxx_t
|
||||||
|
|
||||||
|
class ThermistorSetting
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ThermistorSetting(uint16_t beta, uint64_t rAt25);
|
||||||
|
~ThermistorSetting();
|
||||||
|
uint16_t getBeta();
|
||||||
|
uint64_t getRat25();
|
||||||
|
protected:
|
||||||
|
private:
|
||||||
|
uint16_t _beta;
|
||||||
|
uint64_t _rAt25;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif //THERMISTORSETTING_H
|
Loading…
Reference in New Issue
Block a user