Compare commits
No commits in common. "7774ef334e10013b28d88fe256f45e85fc47a7ae" and "4c6953e85d9aadde0dcfee41ef9c2c6bdacb19ca" have entirely different histories.
7774ef334e
...
4c6953e85d
6174
doc/ClassDiagram.mdj
6174
doc/ClassDiagram.mdj
File diff suppressed because it is too large
Load Diff
@ -1,21 +0,0 @@
|
|||||||
#include "Adc.h"
|
|
||||||
|
|
||||||
Adc::Adc() : _lastChannel(0), _adcSetting(0,0)
|
|
||||||
{
|
|
||||||
//Serial.println("Adc constructor called");
|
|
||||||
}
|
|
||||||
|
|
||||||
Adc::~Adc()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Adc::setAdcSetting(AdcSetting adcSetting)
|
|
||||||
{
|
|
||||||
_adcSetting = adcSetting;
|
|
||||||
}
|
|
||||||
|
|
||||||
AdcSetting Adc::getAdcSetting()
|
|
||||||
{
|
|
||||||
return _adcSetting;
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
#ifndef ADC_H
|
|
||||||
#define ADC_H
|
|
||||||
#include "AdcSetting.h"
|
|
||||||
|
|
||||||
class Adc
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual ~Adc() = 0;
|
|
||||||
|
|
||||||
virtual void begin() = 0;
|
|
||||||
virtual int32_t sampleValue(int16_t channel, boolean sgl = true) = 0;
|
|
||||||
virtual int32_t sampleValue() = 0;
|
|
||||||
virtual double sampleVoltage(int16_t channel, boolean sgl = true) = 0;
|
|
||||||
virtual double sampleVoltage() = 0;
|
|
||||||
|
|
||||||
void setAdcSetting(AdcSetting adcSetting);
|
|
||||||
AdcSetting getAdcSetting();
|
|
||||||
protected:
|
|
||||||
Adc();
|
|
||||||
|
|
||||||
int16_t _lastChannel;
|
|
||||||
AdcSetting _adcSetting;
|
|
||||||
private:
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //ADC_H
|
|
@ -1,85 +0,0 @@
|
|||||||
#include "Ads1115.h"
|
|
||||||
#define ADS_DEBUG
|
|
||||||
|
|
||||||
Ads1115::Ads1115() : ads1(0x48), ads2(0x49)
|
|
||||||
{
|
|
||||||
#ifdef ADS_DEBUG
|
|
||||||
Serial.println("Ads1115 constructor called");
|
|
||||||
#endif
|
|
||||||
//We set the adcs up:
|
|
||||||
ads1.setGain(GAIN_ONE);
|
|
||||||
ads2.setGain(GAIN_ONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ads1115::~Ads1115()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Ads1115::begin()
|
|
||||||
{
|
|
||||||
#ifdef ADS_DEBUG
|
|
||||||
Serial.println("Ads1115 : begin");
|
|
||||||
#endif
|
|
||||||
ads1.begin();
|
|
||||||
ads2.begin();
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t Ads1115::sampleValue(int16_t channel, boolean sgl)
|
|
||||||
{
|
|
||||||
int64_t total(0);
|
|
||||||
for(int i(0); i < getAdcSetting().getMeasureIteration(); i++)
|
|
||||||
{
|
|
||||||
delay(getAdcSetting().getDelayBetweenIteration());
|
|
||||||
total += getReading(channel, sgl);
|
|
||||||
}
|
|
||||||
|
|
||||||
//We divide
|
|
||||||
total /= getAdcSetting().getMeasureIteration();
|
|
||||||
|
|
||||||
//We return
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t Ads1115::sampleValue()
|
|
||||||
{
|
|
||||||
int64_t total(0);
|
|
||||||
for(int i(0); i < getAdcSetting().getMeasureIteration(); i++)
|
|
||||||
{
|
|
||||||
delay(getAdcSetting().getDelayBetweenIteration());
|
|
||||||
total += getReading();
|
|
||||||
}
|
|
||||||
|
|
||||||
//We divide
|
|
||||||
total /= getAdcSetting().getMeasureIteration();
|
|
||||||
|
|
||||||
//We return
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
double Ads1115::sampleVoltage(int16_t channel, boolean sgl)
|
|
||||||
{
|
|
||||||
return sampleValue(channel, sgl)*0.125;
|
|
||||||
}
|
|
||||||
|
|
||||||
double Ads1115::sampleVoltage()
|
|
||||||
{
|
|
||||||
return sampleValue()*0.125;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t Ads1115::getReading(int16_t channel, boolean sgl)
|
|
||||||
{
|
|
||||||
int16_t chan(channel == -1 ? _lastChannel : channel);
|
|
||||||
|
|
||||||
_lastChannel = chan > 8 ? 0 : chan;
|
|
||||||
|
|
||||||
if(chan < 4)
|
|
||||||
{
|
|
||||||
return ads1.readADC_SingleEnded(chan);
|
|
||||||
}
|
|
||||||
else if(chan < 8)
|
|
||||||
{
|
|
||||||
return ads2.readADC_SingleEnded(chan - 4);
|
|
||||||
}
|
|
||||||
else return 0;
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
#ifndef ADS1115_H
|
|
||||||
#define ADS1115_H
|
|
||||||
#include "Adc.h"
|
|
||||||
#include <Wire.h>
|
|
||||||
#include <Adafruit_ADS1015.h>
|
|
||||||
|
|
||||||
class Ads1115 : public Adc
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Ads1115();
|
|
||||||
~Ads1115();
|
|
||||||
|
|
||||||
virtual void begin();
|
|
||||||
virtual int32_t sampleValue(int16_t channel, boolean sgl = true);
|
|
||||||
virtual int32_t sampleValue();
|
|
||||||
virtual double sampleVoltage(int16_t channel, boolean sgl = true);
|
|
||||||
virtual double sampleVoltage();
|
|
||||||
protected:
|
|
||||||
private:
|
|
||||||
uint16_t getReading(int16_t channel = -1, boolean sgl = true);
|
|
||||||
Adafruit_ADS1115 ads1, ads2;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif //ADS1115_H
|
|
@ -1,11 +1,10 @@
|
|||||||
#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,
|
||||||
Adc &adc) : _analogInput(analogInput), _thermistorCount(thermistorCount), _precResistor(precResistor), _thermistorSetting(thermistorSetting), _adc(adc), _globalOffset(0), _error(OK)
|
AdcSetting adcSetting) : _analogInput(analogInput), _thermistorCount(thermistorCount), _precResistor(precResistor), _thermistorSetting(thermistorSetting), _adcSetting(adcSetting), _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));
|
||||||
@ -23,9 +22,6 @@ Adc &adc) : _analogInput(analogInput), _thermistorCount(thermistorCount), _precR
|
|||||||
_rOffsetMap = NULL;
|
_rOffsetMap = NULL;
|
||||||
_resistanceMap = NULL;
|
_resistanceMap = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//We start the comm with the adcs
|
|
||||||
_adc.begin();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MeasureUnit::~MeasureUnit()
|
MeasureUnit::~MeasureUnit()
|
||||||
@ -48,33 +44,75 @@ 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
|
||||||
|
|
||||||
courant = rPrecTension / (double) _precResistor;
|
rPrecTension /= 2500;//_adcSetting.getMeasureIteration();
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
Serial.print("R prec current mA : ");Serial.println(courant,6);
|
Serial.print("Adc value average : ");Serial.println(rPrecTension);
|
||||||
#endif
|
#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;
|
||||||
|
//#ifdef DEBUG
|
||||||
|
char buffer[10] = "";
|
||||||
|
sprintf(buffer,"%.8f", courant);
|
||||||
|
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] = _adc.sampleVoltage(_analogInput[i]);
|
_resistanceMap[i-1] = 0;
|
||||||
#ifdef DEBUG
|
|
||||||
Serial.print("Voltage steps ");Serial.print(i-1);Serial.print(" : ");Serial.println(_resistanceMap[i-1]);
|
for(int j(0); j < _adcSetting.getMeasureIteration(); j++)
|
||||||
#endif
|
{
|
||||||
|
delay(_adcSetting.getDelayBetweenIteration());
|
||||||
|
|
||||||
|
int sample = analogRead(_analogInput[i]);
|
||||||
|
|
||||||
|
_resistanceMap[i-1] += sample;
|
||||||
}
|
}
|
||||||
_resistanceMap[7] = _adc.getAdcSetting().getVref();
|
|
||||||
#ifdef DEBUG
|
_resistanceMap[i-1] /= _adcSetting.getMeasureIteration();
|
||||||
Serial.print("Voltage steps 7 : ");Serial.println(_resistanceMap[7]);
|
|
||||||
#endif
|
_resistanceMap[i-1] *= _adcSetting.getQuantum();
|
||||||
|
|
||||||
|
/*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
|
||||||
@ -85,7 +123,6 @@ 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());
|
||||||
@ -119,13 +156,6 @@ 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 "Ads1115.h"
|
#include "AdcSetting.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, Adc &adc);
|
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();
|
void levelTemperaturesOff();
|
||||||
@ -32,7 +32,7 @@ class MeasureUnit
|
|||||||
uint64_t _precResistor;
|
uint64_t _precResistor;
|
||||||
ERROR _error;
|
ERROR _error;
|
||||||
|
|
||||||
Adc &_adc;
|
AdcSetting _adcSetting;
|
||||||
ThermistorSetting _thermistorSetting;
|
ThermistorSetting _thermistorSetting;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -7,27 +7,21 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "MeasureUnit.h"
|
#include "MeasureUnit.h"
|
||||||
#include "Ads1115.h"
|
|
||||||
|
|
||||||
uint8_t analogInput[] = {0,1,2,3,4,5,6,7};
|
uint8_t analogInput[] = {PA0,PA1,PA2,PA3,PA4,PA5,PA6,PA7};
|
||||||
double *tempArray = NULL;
|
double *tempArray = NULL;
|
||||||
|
|
||||||
ThermistorSetting thermistorSetting(3380, 10000);
|
ThermistorSetting thermistorSetting(4050, 47000);
|
||||||
//AdcSetting adcSetting(3300.0, 12, 310, 3);
|
AdcSetting adcSetting(3.3, 12, 310, 3);
|
||||||
AdcSetting adcSetting(3340.0, 15, 6, 10);
|
|
||||||
|
|
||||||
Ads1115 adc;
|
MeasureUnit measureUnit(analogInput, 8, 1000, thermistorSetting, adcSetting);
|
||||||
|
|
||||||
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(1000);
|
delay(5000);
|
||||||
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 |");
|
||||||
@ -45,11 +39,11 @@ void loop() {
|
|||||||
{
|
{
|
||||||
if(i != 7)
|
if(i != 7)
|
||||||
{
|
{
|
||||||
Serial.print(" ");Serial.print(tempArray[i],2);Serial.print(" |");
|
Serial.print(" ");Serial.print(tempArray[i]);Serial.print(" |");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.print(" ");Serial.print(tempArray[i],2);Serial.println(" |");
|
Serial.print(" ");Serial.print(tempArray[i]);Serial.println(" |");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,15 +55,5 @@ 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