calibration

This commit is contained in:
Wolfgang Hottgenroth
2014-11-20 21:27:35 +01:00
parent 421ebcb0d0
commit 80a394d651

View File

@ -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: