Mise à jour de la bibliothèque permettant de mesurer la température

This commit is contained in:
anschrammh 2020-01-01 13:37:55 +01:00
parent 84b3bd56c8
commit 4c6953e85d
3 changed files with 113 additions and 24 deletions

View File

@ -9,7 +9,7 @@ AdcSetting adcSetting) : _analogInput(analogInput), _thermistorCount(thermistorC
//Allocation dynamique des différent tableaux //Allocation dynamique des différent tableaux
_temperatures = (double*) calloc(_thermistorCount, sizeof(double)); _temperatures = (double*) calloc(_thermistorCount, sizeof(double));
_rOffsetMap = (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) if(_temperatures == NULL || _rOffsetMap == NULL || _resistanceMap == NULL)
{ {
@ -39,18 +39,18 @@ MeasureUnit::~MeasureUnit()
*/ */
double *MeasureUnit::getTemperatures() 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 //1) Nous calculons le courant présent dans la branche grace à la résistance de précision
#ifdef DEBUG #ifdef DEBUG
Serial.println("-------------"); Serial.println("-------------");
#endif #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]); unsigned int sample = analogRead(_analogInput[0]);
deltaTension += sample; rPrecTension += sample;
#ifdef DEBUG #ifdef DEBUG
Serial.print("Adc value : ");Serial.println(sample); Serial.print("Adc value : ");Serial.println(sample);
@ -61,55 +61,85 @@ double *MeasureUnit::getTemperatures()
Serial.println("-------------"); Serial.println("-------------");
#endif #endif
deltaTension /= _adcSetting.getMeasureIteration(); rPrecTension /= 2500;//_adcSetting.getMeasureIteration();
#ifdef DEBUG #ifdef DEBUG
Serial.print("Adc value average : ");Serial.println(deltaTension); Serial.print("Adc value average : ");Serial.println(rPrecTension);
#endif #endif
deltaTension *= _adcSetting.getQuantum(); rPrecTension *= _adcSetting.getQuantum();
#ifdef DEBUG #ifdef DEBUG
char buffer[10] = ""; char buffer[10] = "";
sprintf(buffer,"%.8f", deltaTension); sprintf(buffer,"%.8f", rPrecTension);
Serial.print("R prec voltage : ");Serial.println(buffer); Serial.print("R prec voltage : ");Serial.println(buffer);
#endif #endif
courant = deltaTension / (double) _precResistor; courant = rPrecTension / (double) _precResistor;
#ifdef DEBUG //#ifdef DEBUG
char buffer[10] = "";
sprintf(buffer,"%.8f", courant); sprintf(buffer,"%.8f", courant);
Serial.print("R prec current : ");Serial.println(buffer); Serial.print("R prec current : ");Serial.println(buffer);
#endif //#endif
//2) Nous calculons le delta de tensions pour chaque thermistances //2) Nous calculons le delta de tensions pour chaque thermistances
for(int i(1); i < _thermistorCount; i++) for(int i(1); i < _thermistorCount; i++)
{ {
_resistanceMap[i-1] = 0;
for(int j(0); j < _adcSetting.getMeasureIteration(); j++) for(int j(0); j < _adcSetting.getMeasureIteration(); j++)
{ {
delay(_adcSetting.getDelayBetweenIteration()); delay(_adcSetting.getDelayBetweenIteration());
int sample = analogRead(_analogInput[i]); int sample = analogRead(_analogInput[i]);
_resistanceMap[i-1] += sample; _resistanceMap[i-1] += sample;
} }
_resistanceMap[i-1] /= _adcSetting.getMeasureIteration(); _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 else
_resistanceMap[i-1] -= _resistanceMap[i-2]; _resistanceMap[i-1] -= _resistanceMap[i-2];*/
}
//Pour la dernière valeur: /*#ifdef DEBUG
_resistanceMap[7] = _adcSetting.getVref() - _resistanceMap[6]; 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++) for(int i(0); i < _thermistorCount; i++)
{ {
//3) Nous en déduisons la résistance //3) Nous en déduisons la résistance
_resistanceMap[i] /= courant; _resistanceMap[i] /= courant;
//4) Nous en déduisons la temperature //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; 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) void MeasureUnit::setGlobalTempOffset(double offset)
{ {
_globalOffset = offset; _globalOffset = offset;
@ -119,3 +149,29 @@ double MeasureUnit::getGlobalTempOffset()
{ {
return _globalOffset; 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;
}

View File

@ -3,7 +3,7 @@
#include "AdcSetting.h" #include "AdcSetting.h"
#include "ThermistorSetting.h" #include "ThermistorSetting.h"
#define DEBUG //#define DEBUG_TEMP
class MeasureUnit class MeasureUnit
{ {
@ -12,13 +12,17 @@ class MeasureUnit
MeasureUnit(uint8_t *analogInput, uint16_t thermistorCount, uint64_t precResistor, ThermistorSetting thermistorSetting, AdcSetting adcSetting); MeasureUnit(uint8_t *analogInput, uint16_t thermistorCount, uint64_t precResistor, ThermistorSetting thermistorSetting, AdcSetting adcSetting);
~MeasureUnit(); ~MeasureUnit();
void setGlobalTempOffset(double offset); void setGlobalTempOffset(double offset);
void levelTemperaturesOff();
double getGlobalTempOffset(); double getGlobalTempOffset();
double *getTemperatures(); double *getTemperatures();
double *getROffsetMap();
ERROR getError(){return _error;} ERROR getError(){return _error;}
protected: protected:
private: 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 _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 *_temperatures; //Tableau contenant toutes les températures
double *_rOffsetMap; //Tableau qui contient les offsets individuels pour chaque thermistance double *_rOffsetMap; //Tableau qui contient les offsets individuels pour chaque thermistance

View File

@ -9,22 +9,51 @@
#include "MeasureUnit.h" #include "MeasureUnit.h"
uint8_t analogInput[] = {PA0,PA1,PA2,PA3,PA4,PA5,PA6,PA7}; uint8_t analogInput[] = {PA0,PA1,PA2,PA3,PA4,PA5,PA6,PA7};
double *tempArray = NULL;
ThermistorSetting thermistorSetting(4050, 47000); 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); MeasureUnit measureUnit(analogInput, 8, 1000, thermistorSetting, adcSetting);
void setup() { void setup() {
// put your setup code here, to run once: // put your setup code here, to run once:
Serial.begin(115200); Serial.begin(115200);
delay(5000);
Serial.println("Start setup"); Serial.println("Start setup");
Serial.println("End setup"); Serial.println("End setup");
Serial.println("| T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 |");
} }
int compteur(0);
void loop() { void loop() {
// put your main code here, to run repeatedly: // put your main code here, to run repeatedly:
measureUnit.getTemperatures(); tempArray = measureUnit.getTemperatures();
delay(5000);
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++;
} }