Mise à jour de la bibliothèque permettant de mesurer la température
This commit is contained in:
parent
84b3bd56c8
commit
4c6953e85d
@ -9,7 +9,7 @@ AdcSetting adcSetting) : _analogInput(analogInput), _thermistorCount(thermistorC
|
||||
//Allocation dynamique des différent tableaux
|
||||
_temperatures = (double*) calloc(_thermistorCount, sizeof(double));
|
||||
_rOffsetMap = (double*) calloc(_thermistorCount, sizeof(double));
|
||||
_resistanceMap = (double*) calloc(_thermistorCount, sizeof(double));
|
||||
_resistanceMap = (double*) malloc(_thermistorCount * sizeof(double));
|
||||
|
||||
if(_temperatures == NULL || _rOffsetMap == NULL || _resistanceMap == NULL)
|
||||
{
|
||||
@ -39,18 +39,18 @@ MeasureUnit::~MeasureUnit()
|
||||
*/
|
||||
double *MeasureUnit::getTemperatures()
|
||||
{
|
||||
double courant(0), deltaTension(0);
|
||||
double courant(0), rPrecTension(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++)
|
||||
for(int i(0); i < /*_adcSetting.getMeasureIteration()*/2500; i++)
|
||||
{
|
||||
delay(_adcSetting.getDelayBetweenIteration());
|
||||
delay(/*_adcSetting.getDelayBetweenIteration()*/2);
|
||||
|
||||
int sample = analogRead(_analogInput[0]);
|
||||
deltaTension += sample;
|
||||
unsigned int sample = analogRead(_analogInput[0]);
|
||||
rPrecTension += sample;
|
||||
|
||||
#ifdef DEBUG
|
||||
Serial.print("Adc value : ");Serial.println(sample);
|
||||
@ -61,55 +61,85 @@ double *MeasureUnit::getTemperatures()
|
||||
Serial.println("-------------");
|
||||
#endif
|
||||
|
||||
deltaTension /= _adcSetting.getMeasureIteration();
|
||||
rPrecTension /= 2500;//_adcSetting.getMeasureIteration();
|
||||
#ifdef DEBUG
|
||||
Serial.print("Adc value average : ");Serial.println(deltaTension);
|
||||
Serial.print("Adc value average : ");Serial.println(rPrecTension);
|
||||
#endif
|
||||
deltaTension *= _adcSetting.getQuantum();
|
||||
rPrecTension *= _adcSetting.getQuantum();
|
||||
#ifdef DEBUG
|
||||
char buffer[10] = "";
|
||||
sprintf(buffer,"%.8f", deltaTension);
|
||||
sprintf(buffer,"%.8f", rPrecTension);
|
||||
Serial.print("R prec voltage : ");Serial.println(buffer);
|
||||
#endif
|
||||
courant = deltaTension / (double) _precResistor;
|
||||
#ifdef DEBUG
|
||||
courant = rPrecTension / (double) _precResistor;
|
||||
//#ifdef DEBUG
|
||||
char buffer[10] = "";
|
||||
sprintf(buffer,"%.8f", courant);
|
||||
Serial.print("R prec current : ");Serial.println(buffer);
|
||||
#endif
|
||||
//#endif
|
||||
|
||||
|
||||
//2) Nous calculons le delta de tensions pour chaque thermistances
|
||||
for(int i(1); i < _thermistorCount; i++)
|
||||
{
|
||||
_resistanceMap[i-1] = 0;
|
||||
|
||||
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;
|
||||
|
||||
_resistanceMap[i-1] *= _adcSetting.getQuantum();
|
||||
|
||||
/*if(i == 1)
|
||||
_resistanceMap[i-1] -= rPrecTension;
|
||||
else
|
||||
_resistanceMap[i-1] -= _resistanceMap[i-2];
|
||||
}
|
||||
_resistanceMap[i-1] -= _resistanceMap[i-2];*/
|
||||
|
||||
//Pour la dernière valeur:
|
||||
_resistanceMap[7] = _adcSetting.getVref() - _resistanceMap[6];
|
||||
/*#ifdef DEBUG
|
||||
Serial.print("Debug voltage delta : ");Serial.println(_resistanceMap[i-1]);
|
||||
#endif*/
|
||||
}
|
||||
_resistanceMap[7] = _adcSetting.getVref();
|
||||
|
||||
for(int i(_thermistorCount-1); i > 0; i--)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
Serial.print("Debug voltage level ");Serial.print(i);Serial.print(" : ");Serial.println(_resistanceMap[i]);
|
||||
#endif
|
||||
//Calcule de delta :
|
||||
_resistanceMap[i] -= _resistanceMap[i-1];
|
||||
#ifdef DEBUG
|
||||
Serial.print("Debug voltage delta : ");Serial.println(_resistanceMap[i]);
|
||||
#endif
|
||||
}
|
||||
|
||||
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;
|
||||
_temperatures[i] = computeTemperature(_thermistorSetting.getBeta(), _resistanceMap[i], _thermistorSetting.getRat25());
|
||||
_temperatures[i] += _rOffsetMap[i] + _globalOffset;
|
||||
#ifdef DEBUG_TEMP
|
||||
Serial.print("Temperature ");Serial.print(i);Serial.print(" : ");Serial.println(_temperatures[i]);
|
||||
#endif
|
||||
}
|
||||
|
||||
return _temperatures;
|
||||
}
|
||||
|
||||
double MeasureUnit::computeTemperature(double beta, double resistance, double rAt25)
|
||||
{
|
||||
return (((25.0+273.15) * beta) / (beta + (25.0+273.15)*log(resistance / rAt25))) - 273.15;
|
||||
}
|
||||
|
||||
void MeasureUnit::setGlobalTempOffset(double offset)
|
||||
{
|
||||
_globalOffset = offset;
|
||||
@ -119,3 +149,29 @@ double MeasureUnit::getGlobalTempOffset()
|
||||
{
|
||||
return _globalOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette méthode permet de calibrer toutes les temperatures en faisans la moyenne et appliquant un offset individuel
|
||||
*/
|
||||
void MeasureUnit::levelTemperaturesOff()
|
||||
{
|
||||
double averageTemp(0);
|
||||
|
||||
for(int i(0); i < _thermistorCount; i++)
|
||||
{
|
||||
averageTemp += _temperatures[i];
|
||||
}
|
||||
|
||||
averageTemp /= _thermistorCount;
|
||||
|
||||
for(int i(0); i < _thermistorCount; i++)
|
||||
{
|
||||
_rOffsetMap[i] = averageTemp - _temperatures[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
double *MeasureUnit::getROffsetMap()
|
||||
{
|
||||
return _rOffsetMap;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include "AdcSetting.h"
|
||||
#include "ThermistorSetting.h"
|
||||
|
||||
#define DEBUG
|
||||
//#define DEBUG_TEMP
|
||||
|
||||
class MeasureUnit
|
||||
{
|
||||
@ -12,13 +12,17 @@ class MeasureUnit
|
||||
MeasureUnit(uint8_t *analogInput, uint16_t thermistorCount, uint64_t precResistor, ThermistorSetting thermistorSetting, AdcSetting adcSetting);
|
||||
~MeasureUnit();
|
||||
void setGlobalTempOffset(double offset);
|
||||
void levelTemperaturesOff();
|
||||
double getGlobalTempOffset();
|
||||
double *getTemperatures();
|
||||
double *getROffsetMap();
|
||||
|
||||
ERROR getError(){return _error;}
|
||||
|
||||
protected:
|
||||
private:
|
||||
double computeTemperature(double beta, double resistance, double rAt25);
|
||||
|
||||
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
|
||||
|
@ -9,22 +9,51 @@
|
||||
#include "MeasureUnit.h"
|
||||
|
||||
uint8_t analogInput[] = {PA0,PA1,PA2,PA3,PA4,PA5,PA6,PA7};
|
||||
double *tempArray = NULL;
|
||||
|
||||
ThermistorSetting thermistorSetting(4050, 47000);
|
||||
AdcSetting adcSetting(3.3, 12, 30, 20);
|
||||
AdcSetting adcSetting(3.3, 12, 310, 3);
|
||||
|
||||
MeasureUnit measureUnit(analogInput, 8, 1000, thermistorSetting, adcSetting);
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(115200);
|
||||
delay(5000);
|
||||
Serial.println("Start setup");
|
||||
|
||||
Serial.println("End setup");
|
||||
|
||||
Serial.println("| T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 |");
|
||||
|
||||
}
|
||||
|
||||
int compteur(0);
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
measureUnit.getTemperatures();
|
||||
delay(5000);
|
||||
tempArray = measureUnit.getTemperatures();
|
||||
|
||||
Serial.print("|");
|
||||
for(int i(0); i < 8; i++)
|
||||
{
|
||||
if(i != 7)
|
||||
{
|
||||
Serial.print(" ");Serial.print(tempArray[i]);Serial.print(" |");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print(" ");Serial.print(tempArray[i]);Serial.println(" |");
|
||||
}
|
||||
}
|
||||
|
||||
//On effectue la calibration
|
||||
if(compteur == 5)
|
||||
{
|
||||
Serial.println("********************Start calibration********************");
|
||||
measureUnit.levelTemperaturesOff();
|
||||
Serial.println("********************End calibration********************");
|
||||
}
|
||||
|
||||
compteur++;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user