Compare commits
4 Commits
4c6953e85d
...
7774ef334e
Author | SHA1 | Date | |
---|---|---|---|
|
7774ef334e | ||
|
9c7ca05f68 | ||
|
a0bf6de46d | ||
|
1bd7c088a5 |
6174
doc/ClassDiagram.mdj
Normal file
6174
doc/ClassDiagram.mdj
Normal file
File diff suppressed because it is too large
Load Diff
21
lib/MeasureUnit/Adc.cpp
Normal file
21
lib/MeasureUnit/Adc.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
#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;
|
||||
}
|
26
lib/MeasureUnit/Adc.h
Normal file
26
lib/MeasureUnit/Adc.h
Normal file
@ -0,0 +1,26 @@
|
||||
#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
|
85
lib/MeasureUnit/Ads1115.cpp
Normal file
85
lib/MeasureUnit/Ads1115.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
#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;
|
||||
}
|
24
lib/MeasureUnit/Ads1115.h
Normal file
24
lib/MeasureUnit/Ads1115.h
Normal file
@ -0,0 +1,24 @@
|
||||
#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,10 +1,11 @@
|
||||
#include "MeasureUnit.h"
|
||||
//#define DEBUG
|
||||
|
||||
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)
|
||||
Adc &adc) : _analogInput(analogInput), _thermistorCount(thermistorCount), _precResistor(precResistor), _thermistorSetting(thermistorSetting), _adc(adc), _globalOffset(0), _error(OK)
|
||||
{
|
||||
//Allocation dynamique des différent tableaux
|
||||
_temperatures = (double*) calloc(_thermistorCount, sizeof(double));
|
||||
@ -22,6 +23,9 @@ AdcSetting adcSetting) : _analogInput(analogInput), _thermistorCount(thermistorC
|
||||
_rOffsetMap = NULL;
|
||||
_resistanceMap = NULL;
|
||||
}
|
||||
|
||||
//We start the comm with the adcs
|
||||
_adc.begin();
|
||||
}
|
||||
|
||||
MeasureUnit::~MeasureUnit()
|
||||
@ -44,75 +48,33 @@ double *MeasureUnit::getTemperatures()
|
||||
#ifdef DEBUG
|
||||
Serial.println("-------------");
|
||||
#endif
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
rPrecTension = _adc.sampleVoltage(0);
|
||||
#ifdef DEBUG
|
||||
Serial.println("-------------");
|
||||
Serial.print("R prec voltage mV : ");Serial.println(rPrecTension,6);
|
||||
#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;
|
||||
//#ifdef DEBUG
|
||||
char buffer[10] = "";
|
||||
sprintf(buffer,"%.8f", courant);
|
||||
Serial.print("R prec current : ");Serial.println(buffer);
|
||||
//#endif
|
||||
#ifdef DEBUG
|
||||
Serial.print("R prec current mA : ");Serial.println(courant,6);
|
||||
#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();
|
||||
|
||||
_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[i-1] = _adc.sampleVoltage(_analogInput[i]);
|
||||
#ifdef DEBUG
|
||||
Serial.print("Voltage steps ");Serial.print(i-1);Serial.print(" : ");Serial.println(_resistanceMap[i-1]);
|
||||
#endif
|
||||
}
|
||||
_resistanceMap[7] = _adcSetting.getVref();
|
||||
_resistanceMap[7] = _adc.getAdcSetting().getVref();
|
||||
#ifdef DEBUG
|
||||
Serial.print("Voltage steps 7 : ");Serial.println(_resistanceMap[7]);
|
||||
#endif
|
||||
|
||||
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
|
||||
@ -123,6 +85,7 @@ double *MeasureUnit::getTemperatures()
|
||||
for(int i(0); i < _thermistorCount; i++)
|
||||
{
|
||||
//3) Nous en déduisons la résistance
|
||||
//Serial.print("Resistance ");Serial.print(i);Serial.print(" ");Serial.println(_resistanceMap[i]);
|
||||
_resistanceMap[i] /= courant;
|
||||
//4) Nous en déduisons la temperature
|
||||
_temperatures[i] = computeTemperature(_thermistorSetting.getBeta(), _resistanceMap[i], _thermistorSetting.getRat25());
|
||||
@ -156,7 +119,14 @@ double MeasureUnit::getGlobalTempOffset()
|
||||
void MeasureUnit::levelTemperaturesOff()
|
||||
{
|
||||
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++)
|
||||
{
|
||||
averageTemp += _temperatures[i];
|
||||
|
@ -1,6 +1,6 @@
|
||||
#ifndef MEASUREUNIT_H
|
||||
#define MEASUREUNIT_H
|
||||
#include "AdcSetting.h"
|
||||
#include "Ads1115.h"
|
||||
#include "ThermistorSetting.h"
|
||||
|
||||
//#define DEBUG_TEMP
|
||||
@ -9,7 +9,7 @@ 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(uint8_t *analogInput, uint16_t thermistorCount, uint64_t precResistor, ThermistorSetting thermistorSetting, Adc &adc);
|
||||
~MeasureUnit();
|
||||
void setGlobalTempOffset(double offset);
|
||||
void levelTemperaturesOff();
|
||||
@ -32,7 +32,7 @@ class MeasureUnit
|
||||
uint64_t _precResistor;
|
||||
ERROR _error;
|
||||
|
||||
AdcSetting _adcSetting;
|
||||
Adc &_adc;
|
||||
ThermistorSetting _thermistorSetting;
|
||||
};
|
||||
|
||||
|
@ -7,21 +7,27 @@
|
||||
*/
|
||||
|
||||
#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;
|
||||
|
||||
ThermistorSetting thermistorSetting(4050, 47000);
|
||||
AdcSetting adcSetting(3.3, 12, 310, 3);
|
||||
ThermistorSetting thermistorSetting(3380, 10000);
|
||||
//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() {
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(115200);
|
||||
delay(5000);
|
||||
delay(1000);
|
||||
Serial.println("Start setup");
|
||||
|
||||
adc.setAdcSetting(adcSetting);
|
||||
//measureUnit.setGlobalTempOffset(-17);
|
||||
Serial.println("End setup");
|
||||
|
||||
Serial.println("| T1 | T2 | T3 | T4 | T5 | T6 | T7 | T8 |");
|
||||
@ -39,11 +45,11 @@ void loop() {
|
||||
{
|
||||
if(i != 7)
|
||||
{
|
||||
Serial.print(" ");Serial.print(tempArray[i]);Serial.print(" |");
|
||||
Serial.print(" ");Serial.print(tempArray[i],2);Serial.print(" |");
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print(" ");Serial.print(tempArray[i]);Serial.println(" |");
|
||||
Serial.print(" ");Serial.print(tempArray[i],2);Serial.println(" |");
|
||||
}
|
||||
}
|
||||
|
||||
@ -54,6 +60,16 @@ void loop() {
|
||||
measureUnit.levelTemperaturesOff();
|
||||
Serial.println("********************End calibration********************");
|
||||
}
|
||||
|
||||
if(Serial.available())
|
||||
{
|
||||
if(Serial.read() == 'c')
|
||||
{
|
||||
Serial.println("********************Start calibration********************");
|
||||
measureUnit.levelTemperaturesOff();
|
||||
Serial.println("********************End calibration********************");
|
||||
}
|
||||
}
|
||||
|
||||
compteur++;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user