From 80a394d65126a8e8ade9f7d8f3acb8f11c71b709 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Thu, 20 Nov 2014 21:27:35 +0100 Subject: [PATCH] calibration --- ModbusThermometer.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ModbusThermometer.cpp b/ModbusThermometer.cpp index 1992f94..bf415a7 100644 --- a/ModbusThermometer.cpp +++ b/ModbusThermometer.cpp @@ -18,9 +18,9 @@ const uint8_t ADC_1_RDY_PIN = 7; const uint8_t ADC_2_CS_PIN = 2; const uint8_t ADC_2_RDY_PIN = 3; -const uint8_t CAL_ENABLE = ..; -const uint8_t CAL_OFFSET_ENABLE = ..; -const uint8_t CAL_FACTOR_ENABLE = ..; +const uint8_t CAL_ENABLE = 18; +const uint8_t CAL_OFFSET_ENABLE = 19; +const uint8_t CAL_FACTOR_ENABLE = 20; const uint8_t MODBUS_TX_ENABLE_PIN = 6; const uint8_t MODBUS_ID = 3; @@ -142,6 +142,22 @@ void loop() { break; case e_CAL_SET: // calculate and set according to selected calibration mode + if (digitalRead(CAL_OFFSET_ENABLE) != 0) { + // for offset calibration, the terminals needs to be shorten + // offset calibration needs to be performed first + float offset = calibrationValueSum / calibrationCycleCnt; + for (uint8_t i = 0; i < NUM_OF_CHANNELS; i++) { + ads1210[i].setCalOffset(offset); + } + } + if (digitalRead(CAL_FACTOR_ENABLE) != 0) { + // for factor calibration, a 1000R resistor needs to be connected + // to the terminals + float factor = 1000.0 / (calibrationValueSum / calibrationCycleCnt); + for (uint8_t i = 0; i < NUM_OF_CHANNELS; i++) { + ads1210[i].setCalFactor(offset); + } + } calibrationState = e_CAL_COMPLETE; break; default: