Mise à jour de l'objet MeasureUnit permettant de calculer et de retourner un tableau de temperature
This commit is contained in:
parent
a0bf6de46d
commit
9c7ca05f68
@ -1,10 +1,11 @@
|
|||||||
#include "MeasureUnit.h"
|
#include "MeasureUnit.h"
|
||||||
|
//#define DEBUG
|
||||||
|
|
||||||
MeasureUnit::MeasureUnit(uint8_t *analogInput,
|
MeasureUnit::MeasureUnit(uint8_t *analogInput,
|
||||||
uint16_t thermistorCount,
|
uint16_t thermistorCount,
|
||||||
uint64_t precResistor,
|
uint64_t precResistor,
|
||||||
ThermistorSetting thermistorSetting,
|
ThermistorSetting thermistorSetting,
|
||||||
AdcSetting adcSetting) : _analogInput(analogInput), _thermistorCount(thermistorCount), _precResistor(precResistor), _thermistorSetting(thermistorSetting), _adcSetting(adcSetting), _globalOffset(0), _error(OK)
|
Adc &adc) : _analogInput(analogInput), _thermistorCount(thermistorCount), _precResistor(precResistor), _thermistorSetting(thermistorSetting), _adc(adc), _globalOffset(0), _error(OK)
|
||||||
{
|
{
|
||||||
//Allocation dynamique des différent tableaux
|
//Allocation dynamique des différent tableaux
|
||||||
_temperatures = (double*) calloc(_thermistorCount, sizeof(double));
|
_temperatures = (double*) calloc(_thermistorCount, sizeof(double));
|
||||||
@ -22,6 +23,9 @@ AdcSetting adcSetting) : _analogInput(analogInput), _thermistorCount(thermistorC
|
|||||||
_rOffsetMap = NULL;
|
_rOffsetMap = NULL;
|
||||||
_resistanceMap = NULL;
|
_resistanceMap = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//We start the comm with the adcs
|
||||||
|
_adc.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
MeasureUnit::~MeasureUnit()
|
MeasureUnit::~MeasureUnit()
|
||||||
@ -44,75 +48,33 @@ double *MeasureUnit::getTemperatures()
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Serial.println("-------------");
|
Serial.println("-------------");
|
||||||
#endif
|
#endif
|
||||||
|
rPrecTension = _adc.sampleVoltage(0);
|
||||||
for(int i(0); i < /*_adcSetting.getMeasureIteration()*/2500; i++)
|
|
||||||
{
|
|
||||||
delay(/*_adcSetting.getDelayBetweenIteration()*/2);
|
|
||||||
|
|
||||||
unsigned int sample = analogRead(_analogInput[0]);
|
|
||||||
rPrecTension += sample;
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
Serial.print("Adc value : ");Serial.println(sample);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Serial.println("-------------");
|
Serial.println("-------------");
|
||||||
|
Serial.print("R prec voltage mV : ");Serial.println(rPrecTension,6);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rPrecTension /= 2500;//_adcSetting.getMeasureIteration();
|
|
||||||
#ifdef DEBUG
|
|
||||||
Serial.print("Adc value average : ");Serial.println(rPrecTension);
|
|
||||||
#endif
|
|
||||||
rPrecTension *= _adcSetting.getQuantum();
|
|
||||||
#ifdef DEBUG
|
|
||||||
char buffer[10] = "";
|
|
||||||
sprintf(buffer,"%.8f", rPrecTension);
|
|
||||||
Serial.print("R prec voltage : ");Serial.println(buffer);
|
|
||||||
#endif
|
|
||||||
courant = rPrecTension / (double) _precResistor;
|
courant = rPrecTension / (double) _precResistor;
|
||||||
//#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
char buffer[10] = "";
|
Serial.print("R prec current mA : ");Serial.println(courant,6);
|
||||||
sprintf(buffer,"%.8f", courant);
|
#endif
|
||||||
Serial.print("R prec current : ");Serial.println(buffer);
|
|
||||||
//#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;
|
_resistanceMap[i-1] = _adc.sampleVoltage(_analogInput[i]);
|
||||||
|
#ifdef DEBUG
|
||||||
for(int j(0); j < _adcSetting.getMeasureIteration(); j++)
|
Serial.print("Voltage steps ");Serial.print(i-1);Serial.print(" : ");Serial.println(_resistanceMap[i-1]);
|
||||||
{
|
#endif
|
||||||
delay(_adcSetting.getDelayBetweenIteration());
|
|
||||||
|
|
||||||
int sample = analogRead(_analogInput[i]);
|
|
||||||
|
|
||||||
_resistanceMap[i-1] += sample;
|
|
||||||
}
|
}
|
||||||
|
_resistanceMap[7] = _adc.getAdcSetting().getVref();
|
||||||
_resistanceMap[i-1] /= _adcSetting.getMeasureIteration();
|
#ifdef DEBUG
|
||||||
|
Serial.print("Voltage steps 7 : ");Serial.println(_resistanceMap[7]);
|
||||||
_resistanceMap[i-1] *= _adcSetting.getQuantum();
|
#endif
|
||||||
|
|
||||||
/*if(i == 1)
|
|
||||||
_resistanceMap[i-1] -= rPrecTension;
|
|
||||||
else
|
|
||||||
_resistanceMap[i-1] -= _resistanceMap[i-2];*/
|
|
||||||
|
|
||||||
/*#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--)
|
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 :
|
//Calcule de delta :
|
||||||
_resistanceMap[i] -= _resistanceMap[i-1];
|
_resistanceMap[i] -= _resistanceMap[i-1];
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@ -123,6 +85,7 @@ double *MeasureUnit::getTemperatures()
|
|||||||
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
|
||||||
|
//Serial.print("Resistance ");Serial.print(i);Serial.print(" ");Serial.println(_resistanceMap[i]);
|
||||||
_resistanceMap[i] /= courant;
|
_resistanceMap[i] /= courant;
|
||||||
//4) Nous en déduisons la temperature
|
//4) Nous en déduisons la temperature
|
||||||
_temperatures[i] = computeTemperature(_thermistorSetting.getBeta(), _resistanceMap[i], _thermistorSetting.getRat25());
|
_temperatures[i] = computeTemperature(_thermistorSetting.getBeta(), _resistanceMap[i], _thermistorSetting.getRat25());
|
||||||
@ -156,6 +119,13 @@ double MeasureUnit::getGlobalTempOffset()
|
|||||||
void MeasureUnit::levelTemperaturesOff()
|
void MeasureUnit::levelTemperaturesOff()
|
||||||
{
|
{
|
||||||
double averageTemp(0);
|
double averageTemp(0);
|
||||||
|
//We reset the offset
|
||||||
|
for(int i(0); i < _thermistorCount; i++)
|
||||||
|
{
|
||||||
|
_rOffsetMap[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
getTemperatures();
|
||||||
|
|
||||||
for(int i(0); i < _thermistorCount; i++)
|
for(int i(0); i < _thermistorCount; i++)
|
||||||
{
|
{
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#ifndef MEASUREUNIT_H
|
#ifndef MEASUREUNIT_H
|
||||||
#define MEASUREUNIT_H
|
#define MEASUREUNIT_H
|
||||||
#include "AdcSetting.h"
|
#include "Ads1115.h"
|
||||||
#include "ThermistorSetting.h"
|
#include "ThermistorSetting.h"
|
||||||
|
|
||||||
//#define DEBUG_TEMP
|
//#define DEBUG_TEMP
|
||||||
@ -9,7 +9,7 @@ class MeasureUnit
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum ERROR {OK = 0, MALLOC_ERR = 1};
|
enum ERROR {OK = 0, MALLOC_ERR = 1};
|
||||||
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, Adc &adc);
|
||||||
~MeasureUnit();
|
~MeasureUnit();
|
||||||
void setGlobalTempOffset(double offset);
|
void setGlobalTempOffset(double offset);
|
||||||
void levelTemperaturesOff();
|
void levelTemperaturesOff();
|
||||||
@ -32,7 +32,7 @@ class MeasureUnit
|
|||||||
uint64_t _precResistor;
|
uint64_t _precResistor;
|
||||||
ERROR _error;
|
ERROR _error;
|
||||||
|
|
||||||
AdcSetting _adcSetting;
|
Adc &_adc;
|
||||||
ThermistorSetting _thermistorSetting;
|
ThermistorSetting _thermistorSetting;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -7,21 +7,27 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "MeasureUnit.h"
|
#include "MeasureUnit.h"
|
||||||
|
#include "Ads1115.h"
|
||||||
|
|
||||||
uint8_t analogInput[] = {PA0,PA1,PA2,PA3,PA4,PA5,PA6,PA7};
|
uint8_t analogInput[] = {0,1,2,3,4,5,6,7};
|
||||||
double *tempArray = NULL;
|
double *tempArray = NULL;
|
||||||
|
|
||||||
ThermistorSetting thermistorSetting(4050, 47000);
|
ThermistorSetting thermistorSetting(3380, 10000);
|
||||||
AdcSetting adcSetting(3.3, 12, 310, 3);
|
//AdcSetting adcSetting(3300.0, 12, 310, 3);
|
||||||
|
AdcSetting adcSetting(3340.0, 15, 6, 10);
|
||||||
|
|
||||||
MeasureUnit measureUnit(analogInput, 8, 1000, thermistorSetting, adcSetting);
|
Ads1115 adc;
|
||||||
|
|
||||||
|
MeasureUnit measureUnit(analogInput, 8, 990, thermistorSetting, adc);
|
||||||
|
boolean data(false);
|
||||||
|
|
||||||
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);
|
delay(1000);
|
||||||
Serial.println("Start setup");
|
Serial.println("Start setup");
|
||||||
|
adc.setAdcSetting(adcSetting);
|
||||||
|
//measureUnit.setGlobalTempOffset(-17);
|
||||||
Serial.println("End setup");
|
Serial.println("End setup");
|
||||||
|
|
||||||
Serial.println("| T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 |");
|
Serial.println("| T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 |");
|
||||||
@ -39,11 +45,11 @@ void loop() {
|
|||||||
{
|
{
|
||||||
if(i != 7)
|
if(i != 7)
|
||||||
{
|
{
|
||||||
Serial.print(" ");Serial.print(tempArray[i]);Serial.print(" |");
|
Serial.print(" ");Serial.print(tempArray[i],2);Serial.print(" |");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.print(" ");Serial.print(tempArray[i]);Serial.println(" |");
|
Serial.print(" ");Serial.print(tempArray[i],2);Serial.println(" |");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,5 +61,15 @@ void loop() {
|
|||||||
Serial.println("********************End calibration********************");
|
Serial.println("********************End calibration********************");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(Serial.available())
|
||||||
|
{
|
||||||
|
if(Serial.read() == 'c')
|
||||||
|
{
|
||||||
|
Serial.println("********************Start calibration********************");
|
||||||
|
measureUnit.levelTemperaturesOff();
|
||||||
|
Serial.println("********************End calibration********************");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
compteur++;
|
compteur++;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user