diff --git a/ModbusThermometer.cpp b/ModbusThermometer.cpp index c19d5d5..da185cf 100644 --- a/ModbusThermometer.cpp +++ b/ModbusThermometer.cpp @@ -19,6 +19,7 @@ const uint8_t MODBUS_ID = 3; const uint32_t MODBUS_BAUD = 1200; + ADS1210 ads1210_1; ADS1210 ads1210_2; LED led; @@ -32,16 +33,36 @@ struct { uint16_t modbusRegisters[2]; // 0, 1 } adc1Value; union { - uint32_t in; + float in; uint16_t modbusRegisters[2]; // 2, 3 - } adc2Value; + } adc1U; + union { + float in; + uint16_t modbusRegisters[2]; // 4, 5 + } adc1R; union { uint32_t in; - uint16_t modbusRegisters[2]; // 4, 5 + uint16_t modbusRegisters[2]; // 6, 7 + } adc2Value; + union { + float in; + uint16_t modbusRegisters[2]; // 8, 9 + } adc2U; + union { + float in; + uint16_t modbusRegisters[2]; // 10, 11 + } adc2R; + union { + uint32_t in; + uint16_t modbusRegisters[2]; // 12, 13 } uptimeSeconds; } modbusHoldingRegisters; +float pt1000(float r) { + return (r / PT1000_R0 - 1) / PT1000_Coeff; +} + void setup() { delay(100); led.begin(LED_PIN); @@ -57,9 +78,14 @@ void loop() { ads1210_1.exec(); modbusHoldingRegisters.adc1Value.in = ads1210_1.value; + modbusHoldingRegisters.adc1U.in = ads1210_1.u; + modbusHoldingRegisters.adc1R.in = ads1210_1.r; + ads1210_2.exec(); modbusHoldingRegisters.adc2Value.in = ads1210_2.value; + modbusHoldingRegisters.adc2U.in = ads1210_2.u; + modbusHoldingRegisters.adc2R.in = ads1210_2.r; if (secondTick.check() == 1) { led.toggle(); diff --git a/Thermometer.cpp b/Thermometer.cpp new file mode 100644 index 0000000..e413ce1 --- /dev/null +++ b/Thermometer.cpp @@ -0,0 +1,19 @@ +#include "Thermometer.h" + +using Thermometer; + +Thermometer::Thermometer() { + +} + + +void Thermometer::begin() { + m_lastSmoothedTemperature = 0.0; +} + + +void Thermometer::exec(float r) { + temperatureRaw = (r / PT1000_R0 - 1) / PT1000_Coeff; + + +} \ No newline at end of file diff --git a/Thermometer.h b/Thermometer.h new file mode 100644 index 0000000..bc6e706 --- /dev/null +++ b/Thermometer.h @@ -0,0 +1,28 @@ +#ifndef _THERMOMETER_H_ +#define _THERMOMETER_H_ + +#include +#include + +namespace { + const float R_REF = 3000.0; + const float PT1000_R0 = 1000.0; + const float PT1000_Coeff = 3.85e-3; + + const float ALPHA = 0.1; + const float CYCLE_TIME = 1000; // ms +}; + +class Thermometer { +public: + Thermometer(); + void begin(); + void exec(float r); + float temperature; + float temperatureRaw; +private: + float m_lastSmoothedTemperature; + float m_smoothedTemperature; +}; + +#endif // _THERMOMETER_H_ diff --git a/ads1210.cpp b/ads1210.cpp index 50eed0c..ea57c3d 100644 --- a/ads1210.cpp +++ b/ads1210.cpp @@ -75,6 +75,9 @@ void ADS1210::exec() { //Serial << "DOR1x32: " << _HEX(res.out) << endl; value = res.out; + + u = ((float)(value / V_MAX)) * U_REF; + r = (((float)(V_MAX / value)) - 1.0) * R_REF; if (value == 0) { // fatal(2); diff --git a/ads1210.h b/ads1210.h index e2f648c..5fa40b6 100644 --- a/ads1210.h +++ b/ads1210.h @@ -14,7 +14,9 @@ public: void begin(uint8_t csPin, uint8_t drdyPin); void exec(); - uint32_t value; + uint32_t value; + float u; + float r; private: // register addresses const uint8_t ADDR_DOR2 = 0x00; @@ -67,6 +69,11 @@ private: const uint8_t INSR_MB1 = 0x40; const uint8_t INSR_MB0 = 0x20; const uint8_t INSR_ADDR = 0x0f; + + const float U_REF = 2.5; + const uint32_t V_MAX = 0x3FFFFF; + const float R_REF = 3000.0; + uint8_t m_csPin; uint8_t m_drdyPin;