all calibrations at once
This commit is contained in:
parent
84f06c66e8
commit
0f16b2c3a9
@ -171,7 +171,6 @@ unsigned char AD7190_Init(void)
|
|||||||
// TIME_DelayMs(1);
|
// TIME_DelayMs(1);
|
||||||
delay(1); // arduino function
|
delay(1); // arduino function
|
||||||
regVal = AD7190_GetRegisterValue(AD7190_REG_ID, 1, 1);
|
regVal = AD7190_GetRegisterValue(AD7190_REG_ID, 1, 1);
|
||||||
Serial.print(String("regVal: ") + regVal + "\n");
|
|
||||||
if( (regVal & AD7190_ID_MASK) != ID_AD7190)
|
if( (regVal & AD7190_ID_MASK) != ID_AD7190)
|
||||||
{
|
{
|
||||||
status = 0;
|
status = 0;
|
||||||
|
@ -82,6 +82,8 @@ const String TEXT_RESOURCES[] = {
|
|||||||
"mbus address: ",
|
"mbus address: ",
|
||||||
"collisions: ",
|
"collisions: ",
|
||||||
"r: ",
|
"r: ",
|
||||||
|
"setR: i=",
|
||||||
|
"r=",
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -81,6 +81,8 @@ const uint8_t MBC_INVALID_CHECKSUM_CNT_KEY = 65;
|
|||||||
const uint8_t MBC_ADDRESS_LONG_KEY = 66;
|
const uint8_t MBC_ADDRESS_LONG_KEY = 66;
|
||||||
const uint8_t MBC_COLLISION_CNT_KEY = 67;
|
const uint8_t MBC_COLLISION_CNT_KEY = 67;
|
||||||
const uint8_t R_KEY = 68;
|
const uint8_t R_KEY = 68;
|
||||||
|
const uint8_t SET_R_KEY = 69;
|
||||||
|
const uint8_t R_EQUALS_KEY = 70;
|
||||||
|
|
||||||
|
|
||||||
const String& getResource(uint8_t key);
|
const String& getResource(uint8_t key);
|
||||||
|
@ -20,6 +20,8 @@ void setup() {
|
|||||||
pinMode(OK_LED_PIN, OUTPUT);
|
pinMode(OK_LED_PIN, OUTPUT);
|
||||||
digitalWrite(OK_LED_PIN, LOW);
|
digitalWrite(OK_LED_PIN, LOW);
|
||||||
|
|
||||||
|
// delay(5000);
|
||||||
|
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
Config::initialize();
|
Config::initialize();
|
||||||
|
@ -26,6 +26,8 @@ String MeterBusClientConfig::exec(String params) {
|
|||||||
if (params.startsWith("a ") && (space != -1)) {
|
if (params.startsWith("a ") && (space != -1)) {
|
||||||
unsigned int a = atoi(pb1);
|
unsigned int a = atoi(pb1);
|
||||||
m_meterBusClient->setAddress(a);
|
m_meterBusClient->setAddress(a);
|
||||||
|
Serial.print("Address is now "); Serial.println(a);
|
||||||
|
Serial.print("MBC is at "); Serial.println((long) m_meterBusClient, 16);
|
||||||
} else if (params.startsWith("debug ") && (space != -1)) {
|
} else if (params.startsWith("debug ") && (space != -1)) {
|
||||||
bool b = (strcmp(pb1, "on") == 0);
|
bool b = (strcmp(pb1, "on") == 0);
|
||||||
m_meterBusClient->setDebug(b);
|
m_meterBusClient->setDebug(b);
|
||||||
@ -52,12 +54,14 @@ String MeterBusClientConfig::exec(String params) {
|
|||||||
MeterBusClient::MeterBusClient() : m_meterBusClientConfig(this), m_address(0),
|
MeterBusClient::MeterBusClient() : m_meterBusClientConfig(this), m_address(0),
|
||||||
m_frameCnt(0), m_myFrameCnt(0), m_invalidFrameCnt(0), m_invalidChecksum(0),
|
m_frameCnt(0), m_myFrameCnt(0), m_invalidFrameCnt(0), m_invalidChecksum(0),
|
||||||
m_collisionCnt(0) {
|
m_collisionCnt(0) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void MeterBusClient::begin(CmdServer *cmdServer, Thermometer *thermometer) {
|
void MeterBusClient::begin(CmdServer *cmdServer, Thermometer *thermometer) {
|
||||||
|
Serial.print("I'm at "); Serial.println((long)this, 16);
|
||||||
|
|
||||||
|
|
||||||
m_meterBusClientConfig.registerYourself(cmdServer);
|
m_meterBusClientConfig.registerYourself(cmdServer);
|
||||||
m_thermometer = thermometer;
|
m_thermometer = thermometer;
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class MeterBusClient;
|
|||||||
|
|
||||||
class MeterBusClientConfig : public Cmd {
|
class MeterBusClientConfig : public Cmd {
|
||||||
public:
|
public:
|
||||||
MeterBusClientConfig(MeterBusClient *meterBusClient) : m_meterBusClient(meterBusClient) {};
|
MeterBusClientConfig(MeterBusClient *meterBusClient) : m_meterBusClient(meterBusClient) { };
|
||||||
virtual String getCmdName() { return "MBCC"; }
|
virtual String getCmdName() { return "MBCC"; }
|
||||||
virtual String getHelp() { return getResource(MBC_CONFIG_HELP_KEY); }
|
virtual String getHelp() { return getResource(MBC_CONFIG_HELP_KEY); }
|
||||||
virtual String exec(String params);
|
virtual String exec(String params);
|
||||||
|
@ -98,13 +98,8 @@ String ThermCalibrate::exec(String params) {
|
|||||||
m_stream->println(getResource(CALI_HELP_4_KEY));
|
m_stream->println(getResource(CALI_HELP_4_KEY));
|
||||||
m_stream->println(getResource(CALI_HELP_5_KEY));
|
m_stream->println(getResource(CALI_HELP_5_KEY));
|
||||||
m_stream->println(getResource(CALI_HELP_6_KEY));
|
m_stream->println(getResource(CALI_HELP_6_KEY));
|
||||||
} else if (params.startsWith("start ") && (space != -1) && m_enabled) {
|
} else if (params.startsWith("start") && m_enabled) {
|
||||||
m_channel = atoi(pb1);
|
m_start_highCalibration = true;
|
||||||
if ((m_channel + 1) > NUM_OF_CHANNELS) {
|
|
||||||
res = "Invalid channel number";
|
|
||||||
} else {
|
|
||||||
m_start_highCalibration = true;
|
|
||||||
}
|
|
||||||
} else if (params.startsWith("stop")) {
|
} else if (params.startsWith("stop")) {
|
||||||
m_start_highCalibration = false;
|
m_start_highCalibration = false;
|
||||||
} else if (params.startsWith("r ") && (space != -1)) {
|
} else if (params.startsWith("r ") && (space != -1)) {
|
||||||
@ -182,6 +177,14 @@ float pt1000(float r) {
|
|||||||
return (r / PT1000_R0 - 1) / PT1000_Coeff;
|
return (r / PT1000_R0 - 1) / PT1000_Coeff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Thermometer::setR(unsigned int index, float r) {
|
||||||
|
m_r[index] = r;
|
||||||
|
if (getDebug() || getInfo()) {
|
||||||
|
Serial.print(getResource(SET_R_KEY)); Serial.print(index); Serial.print(getResource(COMMA_SPACE_KEY));
|
||||||
|
Serial.print(getResource(R_EQUALS_KEY)); Serial.print(r, 2); Serial.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Thermometer::setTemperature(unsigned int index, float t) {
|
void Thermometer::setTemperature(unsigned int index, float t) {
|
||||||
m_temperature[index] = t;
|
m_temperature[index] = t;
|
||||||
|
|
||||||
@ -342,7 +345,7 @@ void Thermometer::exec() {
|
|||||||
SPI_Disable(AD7190_SLAVE_ID);
|
SPI_Disable(AD7190_SLAVE_ID);
|
||||||
|
|
||||||
if (m_calibrationHighMode || thermCalibrate.m_start_highCalibration) {
|
if (m_calibrationHighMode || thermCalibrate.m_start_highCalibration) {
|
||||||
Serial.println(getResource(CALIBRATION_MODE_HINT_KEY));
|
if (getDebug()) { Serial.println(getResource(CALIBRATION_MODE_HINT_KEY)); }
|
||||||
state = 20;
|
state = 20;
|
||||||
} else if (m_calibrationZeroMode || thermCalibrate.m_start_zeroCalibration) {
|
} else if (m_calibrationZeroMode || thermCalibrate.m_start_zeroCalibration) {
|
||||||
Serial.println(getResource(CALIBRATION_ZEOR_MODE_HINT_KEY));
|
Serial.println(getResource(CALIBRATION_ZEOR_MODE_HINT_KEY));
|
||||||
@ -355,7 +358,7 @@ void Thermometer::exec() {
|
|||||||
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.print("calibrateFactor="); Serial.print(getCalibrateFactor(i), 6); Serial.print(getResource(COMMA_SPACE_KEY)); }
|
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.print("calibrateFactor="); Serial.print(getCalibrateFactor(i), 6); Serial.print(getResource(COMMA_SPACE_KEY)); }
|
||||||
float r = (((float)(m_n[i] - ((i == 3) ? 0 : m_n[i + 1]))) / ((float)N_MAX)) * R_REF * getCalibrateFactor(i);
|
float r = (((float)(m_n[i] - ((i == 3) ? 0 : m_n[i + 1]))) / ((float)N_MAX)) * R_REF * getCalibrateFactor(i);
|
||||||
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.print("r="); Serial.print(r); Serial.print(getResource(COMMA_SPACE_KEY)); }
|
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.print("r="); Serial.print(r); Serial.print(getResource(COMMA_SPACE_KEY)); }
|
||||||
m_r[i] = r;
|
setR(i, r);
|
||||||
float t = pt1000(r);
|
float t = pt1000(r);
|
||||||
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.print("t="); Serial.print(t); Serial.print(getResource(COMMA_SPACE_KEY)); }
|
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.print("t="); Serial.print(t); Serial.print(getResource(COMMA_SPACE_KEY)); }
|
||||||
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.println(); }
|
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.println(); }
|
||||||
@ -383,25 +386,29 @@ void Thermometer::exec() {
|
|||||||
if (thermCalibrate.m_start_highCalibration) {
|
if (thermCalibrate.m_start_highCalibration) {
|
||||||
if (m_calibrationHighMode) {
|
if (m_calibrationHighMode) {
|
||||||
// do the calibration stuff
|
// do the calibration stuff
|
||||||
|
(thermCalibrate.m_turn)++;
|
||||||
for (unsigned int i = 0; i < NUM_OF_CHANNELS; i++) {
|
for (unsigned int i = 0; i < NUM_OF_CHANNELS; i++) {
|
||||||
float r = (((float)(m_n[i] - ((i == 3) ? 0 : m_n[i + 1]))) / ((float)N_MAX)) * R_REF;
|
float r = (((float)(m_n[i] - ((i == 3) ? 0 : m_n[i + 1]))) / ((float)N_MAX)) * R_REF;
|
||||||
Serial.print("t="); Serial.print(thermCalibrate.m_turn); Serial.print(", c="); Serial.print(i);
|
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.print("t="); Serial.print(thermCalibrate.m_turn); Serial.print(", c="); Serial.print(i); }
|
||||||
Serial.print(", r="); Serial.print(r, 6); Serial.print(", n="); Serial.print(m_n[i]);
|
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.print(", r="); Serial.print(r, 6); Serial.print(", n="); Serial.print(m_n[i]); }
|
||||||
if (i == thermCalibrate.m_channel) {
|
thermCalibrate.m_r_sum[i] += r;
|
||||||
thermCalibrate.m_r_sum += r;
|
float r_avg = thermCalibrate.m_r_sum[i] / thermCalibrate.m_turn;
|
||||||
}
|
if (getDebug() || getInfo()) { Serial.print(thermCalibrate.m_turn); Serial.print(getResource(COMMA_SPACE_KEY)); Serial.print(getResource(STATE_20_MSG_1_KEY)); Serial.print(i); Serial.print(getResource(COLON_SPACE_KEY)); Serial.print(r_avg, 6); }
|
||||||
|
float calFact = thermCalibrate.m_r_cal / r_avg;
|
||||||
|
if (getDebug() || getInfo()) { Serial.print(getResource(COMMA_SPACE_KEY)); Serial.print(getResource(STATE_20_MSG_2_KEY)); Serial.print(calFact, 6); Serial.println(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((thermCalibrate.m_turn) >= NUM_OF_CALIBRATION_CYCLES) {
|
||||||
|
thermCalibrate.m_start_highCalibration = false;
|
||||||
}
|
}
|
||||||
(thermCalibrate.m_turn)++;
|
|
||||||
float r_avg = thermCalibrate.m_r_sum / thermCalibrate.m_turn;
|
|
||||||
Serial.print(getResource(STATE_20_MSG_1_KEY)); Serial.print(thermCalibrate.m_channel); Serial.print(getResource(COLON_SPACE_KEY)); Serial.print(r_avg, 6);
|
|
||||||
float calFact = thermCalibrate.m_r_cal / r_avg;
|
|
||||||
Serial.print(getResource(STATE_20_MSG_2_KEY)); Serial.print(calFact, 6); Serial.println();
|
|
||||||
} else {
|
} else {
|
||||||
thermCalibrate.m_preserved_alpha = m_alpha;
|
thermCalibrate.m_preserved_alpha = m_alpha;
|
||||||
m_alpha = 1;
|
m_alpha = 1;
|
||||||
thermCalibrate.m_preserved_period = m_periodMillis;
|
thermCalibrate.m_preserved_period = m_periodMillis;
|
||||||
m_periodMillis = 500;
|
m_periodMillis = CALIBRATION_CYCLE_TIME;
|
||||||
thermCalibrate.m_r_sum = 0.0;
|
for (unsigned int i = 0; i < NUM_OF_CHANNELS; i++) {
|
||||||
|
thermCalibrate.m_r_sum[i] = 0.0;
|
||||||
|
}
|
||||||
thermCalibrate.m_turn = 0;
|
thermCalibrate.m_turn = 0;
|
||||||
m_calibrationHighMode = true;
|
m_calibrationHighMode = true;
|
||||||
}
|
}
|
||||||
@ -410,12 +417,15 @@ void Thermometer::exec() {
|
|||||||
m_calibrationHighMode = false;
|
m_calibrationHighMode = false;
|
||||||
m_alpha = thermCalibrate.m_preserved_alpha;
|
m_alpha = thermCalibrate.m_preserved_alpha;
|
||||||
m_periodMillis = thermCalibrate.m_preserved_period;
|
m_periodMillis = thermCalibrate.m_preserved_period;
|
||||||
Serial.println(getResource(STATE_20_MSG_3_KEY));
|
for (unsigned int i = 0; i < NUM_OF_CHANNELS; i++) {
|
||||||
float r_avg = thermCalibrate.m_r_sum / thermCalibrate.m_turn;
|
Serial.println(getResource(STATE_20_MSG_3_KEY));
|
||||||
float calFact = thermCalibrate.m_r_cal / r_avg;
|
float r_avg = thermCalibrate.m_r_sum[i] / thermCalibrate.m_turn;
|
||||||
Serial.print(getResource(STATE_20_MSG_4_KEY)); Serial.print(thermCalibrate.m_channel);
|
float calFact = thermCalibrate.m_r_cal / r_avg;
|
||||||
Serial.print(getResource(COLON_SPACE_KEY)); Serial.print(calFact, 6); Serial.println();
|
|
||||||
setCalibrateFactor(thermCalibrate.m_channel, calFact);
|
Serial.print(getResource(STATE_20_MSG_4_KEY)); Serial.print(i);
|
||||||
|
Serial.print(getResource(COLON_SPACE_KEY)); Serial.print(calFact, 6); Serial.println();
|
||||||
|
setCalibrateFactor(i, calFact);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
state = 11;
|
state = 11;
|
||||||
|
@ -21,6 +21,8 @@ const float R_REF = 6200.0;
|
|||||||
const float PT1000_R0 = 1000.0;
|
const float PT1000_R0 = 1000.0;
|
||||||
const float PT1000_Coeff = 3.85e-3;
|
const float PT1000_Coeff = 3.85e-3;
|
||||||
const unsigned long CONV_TIMEOUT = 0xfffff;
|
const unsigned long CONV_TIMEOUT = 0xfffff;
|
||||||
|
const unsigned long NUM_OF_CALIBRATION_CYCLES = 250;
|
||||||
|
const unsigned long CALIBRATION_CYCLE_TIME = 100; // ms
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -61,9 +63,8 @@ private:
|
|||||||
float m_r_cal;
|
float m_r_cal;
|
||||||
float m_preserved_alpha;
|
float m_preserved_alpha;
|
||||||
unsigned long m_preserved_period;
|
unsigned long m_preserved_period;
|
||||||
unsigned int m_channel;
|
|
||||||
unsigned int m_turn;
|
unsigned int m_turn;
|
||||||
float m_r_sum;
|
float m_r_sum[NUM_OF_CHANNELS];
|
||||||
};
|
};
|
||||||
|
|
||||||
class Thermometer {
|
class Thermometer {
|
||||||
@ -101,6 +102,7 @@ private:
|
|||||||
void prepareAdc();
|
void prepareAdc();
|
||||||
|
|
||||||
void setTemperature(unsigned int index, float t);
|
void setTemperature(unsigned int index, float t);
|
||||||
|
void setR(unsigned int index, float r);
|
||||||
void setPeriodMeasure(unsigned long p);
|
void setPeriodMeasure(unsigned long p);
|
||||||
unsigned long getPeriodMeasure();
|
unsigned long getPeriodMeasure();
|
||||||
void setAlpha(float a);
|
void setAlpha(float a);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user