8 Commits

Author SHA1 Message Date
2ada607813 don't know 2015-05-29 10:26:29 +02:00
hg
ebc835c794 changes 2014-05-04 20:56:03 +02:00
hg
45bdbe0a57 * disable real text
* shorter calibration cycle (10ms)
* higher baudrate (115k2)
2014-04-05 11:36:57 +02:00
hg
0f16b2c3a9 all calibrations at once 2014-04-04 20:38:11 +02:00
hg
84f06c66e8 less digit in output 2014-04-03 22:34:03 +02:00
hg
db5cb1829a changes 2014-04-02 22:50:17 +02:00
hg
26b47b1159 response delay 2014-03-09 21:12:17 +01:00
hg
ec6b7c0647 Added tag MBC_WORKING_FIRST_FRAME_ANSWERED for changeset 4c0a748c4e06 2014-03-09 00:26:42 +01:00
12 changed files with 346 additions and 57 deletions

View File

@ -1 +1,2 @@
55e33ac01375df1e3e295262fcc03a568ddf48e3 before_switch_to_arm
4c0a748c4e0681d22d1d3e1faf4e09266a64dc8c MBC_WORKING_FIRST_FRAME_ANSWERED

View File

@ -3,7 +3,7 @@
<configuration id="it.baeyens.arduino.core.toolChain.release.1909314976" name="Release">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider class="it.baeyens.arduino.toolchain.ArduinoLanguageProvider" console="false" env-hash="-2011256820" id="it.baeyens.arduino.languageSettingsProvider" keep-relative-paths="false" name="Arduino Compiler Settings" parameter="${COMMAND} -E -P -v -dD ${INPUTS}" prefer-non-shared="true">
<provider class="it.baeyens.arduino.toolchain.ArduinoLanguageProvider" console="false" env-hash="-1881042430836" id="it.baeyens.arduino.languageSettingsProvider" keep-relative-paths="false" name="Arduino Compiler Settings" parameter="${COMMAND} -E -P -v -dD ${INPUTS}" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>

View File

@ -171,7 +171,6 @@ unsigned char AD7190_Init(void)
// TIME_DelayMs(1);
delay(1); // arduino function
regVal = AD7190_GetRegisterValue(AD7190_REG_ID, 1, 1);
Serial.print(String("regVal: ") + regVal + "\n");
if( (regVal & AD7190_ID_MASK) != ID_AD7190)
{
status = 0;

View File

@ -9,9 +9,12 @@
#include "Resources.h"
#define USE_REAL_TEXTS 1
//String TEXT;
#ifndef USE_REAL_TEXTS
String TEXT;
#else
const String TEXT_RESOURCES[] = {
"Text1",
"PeriodMeasure (ms): ",
@ -80,14 +83,21 @@ const String TEXT_RESOURCES[] = {
"invalid frames: ",
"invalid checksum: ",
"mbus address: ",
"collisions: ",
"r: ",
"setR: i=",
"r=",
};
#endif
const String& getResource(uint8_t key) {
//TEXT = String("T") + key + String(": ");
//return TEXT;
#ifndef USE_REAL_TEXTS
TEXT = String(" T") + key + String(": ");
return TEXT;
#else
return TEXT_RESOURCES[key];
#endif
}

View File

@ -79,6 +79,10 @@ const uint8_t MBC_MYFRAMES_KEY = 63;
const uint8_t MBC_INVALID_FRAMES_KEY = 64;
const uint8_t MBC_INVALID_CHECKSUM_CNT_KEY = 65;
const uint8_t MBC_ADDRESS_LONG_KEY = 66;
const uint8_t MBC_COLLISION_CNT_KEY = 67;
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);

View File

@ -8,6 +8,7 @@
#include "meterBusClient.h"
const unsigned char OK_LED_PIN = 2;
static CmdServer cmdServer(&Serial);
static ConfigInvalidateCmd configInvalidateCmd;
@ -16,7 +17,12 @@ static Thermometer thermometer;
static MeterBusClient meterBusClient;
void setup() {
Serial.begin(9600);
pinMode(OK_LED_PIN, OUTPUT);
digitalWrite(OK_LED_PIN, LOW);
// delay(5000);
Serial.begin(115200);
Config::initialize();
@ -27,7 +33,9 @@ void setup() {
configInvalidateCmd.registerYourself(&cmdServer);
uptime.begin(&cmdServer);
thermometer.begin(&cmdServer);
meterBusClient.begin(&cmdServer, &thermometer);
meterBusClient.begin(&cmdServer, &thermometer, &uptime);
digitalWrite(OK_LED_PIN, HIGH);
}

View File

@ -26,6 +26,8 @@ String MeterBusClientConfig::exec(String params) {
if (params.startsWith("a ") && (space != -1)) {
unsigned int a = atoi(pb1);
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)) {
bool b = (strcmp(pb1, "on") == 0);
m_meterBusClient->setDebug(b);
@ -37,6 +39,7 @@ String MeterBusClientConfig::exec(String params) {
Serial.print(getResource(MBC_MYFRAMES_KEY)); Serial.print(m_meterBusClient->m_myFrameCnt); Serial.println();
Serial.print(getResource(MBC_INVALID_FRAMES_KEY)); Serial.print(m_meterBusClient->m_invalidFrameCnt); Serial.println();
Serial.print(getResource(MBC_INVALID_CHECKSUM_CNT_KEY)); Serial.print(m_meterBusClient->m_invalidChecksum); Serial.println();
Serial.print(getResource(MBC_COLLISION_CNT_KEY)); Serial.print(m_meterBusClient->m_collisionCnt); Serial.println();
Serial.print(getResource(MBC_ADDRESS_LONG_KEY)); Serial.print(m_meterBusClient->getAddress()); Serial.println();
} else {
res = "subcommand not found";
@ -49,17 +52,25 @@ String MeterBusClientConfig::exec(String params) {
MeterBusClient::MeterBusClient() : m_meterBusClientConfig(this), m_address(0),
m_frameCnt(0), m_myFrameCnt(0), m_invalidFrameCnt(0), m_invalidChecksum(0) {
m_frameCnt(0), m_accessCnt(0), m_myFrameCnt(0), m_invalidFrameCnt(0), m_invalidChecksum(0),
m_collisionCnt(0) {
}
void MeterBusClient::begin(CmdServer *cmdServer, Thermometer *thermometer) {
void MeterBusClient::begin(CmdServer *cmdServer, Thermometer *thermometer, Uptime *uptime) {
Serial.print("I'm at "); Serial.println((long)this, 16);
m_meterBusClientConfig.registerYourself(cmdServer);
m_thermometer = thermometer;
m_uptime = uptime;
//Serial3.begin(1200);
//Serial3.begin(2400, SERIAL_8E1);
Serial3.begin(2400);
UART2_C1 |= UART_C1_PE | UART_C1_M;
Serial3.begin(1200);
setAddress(Config::getUChar(Config::METERBUSCLIENT_ADDRESS));
@ -93,6 +104,13 @@ bool MeterBusClient::getInfo() {
return m_info;
}
unsigned char MeterBusClient::getStatus() {
return 0;
}
unsigned char MeterBusClient::getAccessCnt() {
return m_accessCnt;
}
/*
@ -147,7 +165,8 @@ bool isChecksumValid(MeterBusFrame frame) {
void MeterBusClient::handleFrame() {
bool MeterBusClient::handleFrame() {
bool res = false;
m_frameCnt++;
if (! isChecksumValid(m_frame)) {
Serial.println(getResource(MBC_INVALID_CHECKSUM_KEY));
@ -176,18 +195,23 @@ void MeterBusClient::handleFrame() {
if (m_frame.startDelimiter == 0x10) {
if (m_frame.cField == 0x40) {
SND_NKE();
res = true;
} else if (m_frame.cField == 0x5b) {
m_accessCnt++;
REQ_UD2();
res = true;
} else {
Serial.println(getResource(MBC_UNHANDLED_FRAME_KEY));
}
}
}
return res;
}
typedef enum {
STATE_START, STATE_IDLE, STATE_SHORT_FRAME, STATE_LONG_CTRL_FRAME, STATE_HANDLE, STATE_INVALID, STATE_DONE
STATE_START, STATE_IDLE, STATE_SHORT_FRAME, STATE_LONG_CTRL_FRAME, STATE_HANDLE, STATE_INVALID, STATE_DONE,
STATE_DELAYED_RESPONSE, STATE_DELAY, STATE_RESPONSE, STATE_RECEIVE_ECHO
} e_meterBusClientState;
typedef enum {
@ -200,8 +224,13 @@ void MeterBusClient::exec() {
static e_meterBusClientState state = STATE_IDLE;
static e_meterBusClientSubState subState = SUBSTATE_LENGTH;
static unsigned char userDataCnt = 0;
static unsigned int echoReceiveCnt = 0;
static unsigned long receivedDoneTimestamp;
int chi = Serial3.read();
//if (chi != -1) {
// Serial.print("Received: "); Serial.println(chi, 16);
//}
char ch = (char) chi;
switch (state) {
@ -310,17 +339,48 @@ void MeterBusClient::exec() {
break;
case STATE_INVALID:
Serial.println("INVALID FRAME");
m_invalidFrameCnt++;
state = STATE_START;
break;
case STATE_HANDLE:
if (m_frame.valid) {
handleFrame();
} else {
Serial.println(getResource(MBC_NO_VALID_FRAME_KEY));
}
state = STATE_DONE;
if (m_frame.valid) {
receivedDoneTimestamp = millis();
if (handleFrame()) {
state = STATE_DELAY;
}
}
break;
case STATE_DELAY:
if ((receivedDoneTimestamp + RESPONSE_DELAY) < millis()) {
state = STATE_DELAYED_RESPONSE;
}
break;
case STATE_DELAYED_RESPONSE:
for (unsigned int i = 0; i < m_sendBufferLen; i++) {
Serial3.write(m_sendBuffer[i]);
}
echoReceiveCnt = 0;
state = STATE_RECEIVE_ECHO;
break;
case STATE_RECEIVE_ECHO:
if (chi != -1) {
//Serial.println("echo character");
if (ch == m_sendBuffer[echoReceiveCnt]) {
echoReceiveCnt++;
if (echoReceiveCnt == m_sendBufferLen) {
state = STATE_DONE;
}
} else {
m_collisionCnt++;
state = STATE_DONE;
}
}
break;
case STATE_DONE:

View File

@ -14,6 +14,11 @@
#include "Config.h"
#include "Resources.h"
#include "Thermometer.h"
#include "uptime.h"
const unsigned long RESPONSE_DELAY = 50;
class MeterBusClient;
@ -21,7 +26,7 @@ class MeterBusClient;
class MeterBusClientConfig : public Cmd {
public:
MeterBusClientConfig(MeterBusClient *meterBusClient) : m_meterBusClient(meterBusClient) {};
MeterBusClientConfig(MeterBusClient *meterBusClient) : m_meterBusClient(meterBusClient) { };
virtual String getCmdName() { return "MBCC"; }
virtual String getHelp() { return getResource(MBC_CONFIG_HELP_KEY); }
virtual String exec(String params);
@ -67,22 +72,37 @@ struct MeterBusFrame {
class MeterBusClient {
public:
MeterBusClient();
void begin(CmdServer *cmdServer, Thermometer *thermometer);
void begin(CmdServer *cmdServer, Thermometer *thermometer, Uptime *uptime);
void exec();
friend class MeterBusClientConfig;
private:
MeterBusClientConfig m_meterBusClientConfig;
Thermometer *m_thermometer;
Uptime *m_uptime;
unsigned char m_address;
void setAddress(unsigned char address);
unsigned char getAddress();
void handleFrame();
bool handleFrame();
MeterBusFrame m_frame;
unsigned char m_sendBuffer[265];
unsigned int m_sendBufferLen;
void aSB(unsigned char v); // append to send buffer
void aSB(unsigned int v);
void aSB(unsigned long v);
void aSB(float v);
unsigned char calcSendChecksum();
void calcAndSetFrameLength();
unsigned long m_frameCnt;
unsigned char m_accessCnt;
unsigned long m_myFrameCnt;
unsigned long m_invalidFrameCnt;
unsigned long m_invalidChecksum;
unsigned long m_collisionCnt;
unsigned char getAccessCnt();
unsigned char getStatus();
bool m_debug;
bool getDebug();

View File

@ -7,13 +7,180 @@
#include "meterBusClient.h"
void MeterBusClient::aSB(unsigned char v) {
m_sendBuffer[m_sendBufferLen] = v;
m_sendBufferLen++;
}
void MeterBusClient::aSB(unsigned int v) {
// 16 bit
union {
unsigned int i;
unsigned char c[2];
} u;
u.i = v;
m_sendBuffer[m_sendBufferLen] = u.c[0];
m_sendBufferLen++;
m_sendBuffer[m_sendBufferLen] = u.c[1];
m_sendBufferLen++;
}
void MeterBusClient::aSB(unsigned long v) {
// 32 bit
union{
unsigned long l;
unsigned char c[4];
} u;
u.l = v;
m_sendBuffer[m_sendBufferLen] = u.c[0];
m_sendBufferLen++;
m_sendBuffer[m_sendBufferLen] = u.c[1];
m_sendBufferLen++;
m_sendBuffer[m_sendBufferLen] = u.c[2];
m_sendBufferLen++;
m_sendBuffer[m_sendBufferLen] = u.c[3];
m_sendBufferLen++;
}
void MeterBusClient::aSB(float v) {
// 32 bit
union{
float f;
unsigned char c[4];
} u;
u.f = v;
m_sendBuffer[m_sendBufferLen] = u.c[0];
m_sendBufferLen++;
m_sendBuffer[m_sendBufferLen] = u.c[1];
m_sendBufferLen++;
m_sendBuffer[m_sendBufferLen] = u.c[2];
m_sendBufferLen++;
m_sendBuffer[m_sendBufferLen] = u.c[3];
m_sendBufferLen++;
}
unsigned char MeterBusClient::calcSendChecksum() {
unsigned char checksum = 0;
for (unsigned int i = 4; i < m_sendBufferLen; i++) {
checksum += m_sendBuffer[i];
}
return checksum;
}
void MeterBusClient::calcAndSetFrameLength() {
unsigned char frameLength = m_sendBufferLen - 6;
m_sendBuffer[1] = frameLength;
m_sendBuffer[2] = frameLength;
}
void MeterBusClient::SND_NKE() {
Serial3.write(0xE5);
m_sendBufferLen = 0;
aSB((unsigned char)0xE5);
}
void MeterBusClient::REQ_UD2() {
m_sendBufferLen = 0;
// frame header
aSB((unsigned char)0x68);
aSB((unsigned char)0x00);
aSB((unsigned char)0x00);
aSB((unsigned char)0x68);
// C
aSB((unsigned char)0x08);
// A
aSB(getAddress());
// CI
aSB((unsigned char)0x72);
// Header
aSB((unsigned long)0); // Ident
aSB((unsigned int)0); // Manu.
aSB((unsigned char)1); // Version
aSB((unsigned char)0); // Medium: other
aSB(getAccessCnt()); // Access
aSB(getStatus()); // Status
aSB((unsigned int)0); // Signatur
// Uptime
// DIF
aSB((unsigned char)0x01);
// VIF
aSB((unsigned char)0x24);
aSB(m_uptime->getSeconds());
// DIF
aSB((unsigned char)0x01);
// VIF
aSB((unsigned char)0x25);
aSB(m_uptime->getMinutes());
// DIF
aSB((unsigned char)0x01);
// VIF
aSB((unsigned char)0x26);
aSB(m_uptime->getHours());
// DIF
aSB((unsigned char)0x02);
// VIF
aSB((unsigned char)0x27);
aSB((unsigned int)m_uptime->getDays());
// Temperatur 1
// DIF
aSB((unsigned char)0x05);
// VIF
aSB((unsigned char)0x67);
// value
aSB(m_thermometer->getTemperature(0));
// Temperatur 2
// DIF
aSB((unsigned char)0x05);
// VIF
aSB((unsigned char)0x67);
// value
aSB(m_thermometer->getTemperature(1));
// Temperatur 3
// DIF
aSB((unsigned char)0x05);
// VIF
aSB((unsigned char)0x67);
// value
aSB(m_thermometer->getTemperature(2));
// Temperatur 4
// DIF
aSB((unsigned char)0x05);
// VIF
aSB((unsigned char)0x67);
// value
aSB(m_thermometer->getTemperature(3));
// Structured Manufacturer Data
// DIF
aSB((unsigned char)0x0f);
aSB(m_frameCnt);
aSB(m_myFrameCnt);
aSB(m_invalidFrameCnt);
aSB(m_invalidChecksum);
aSB(m_collisionCnt);
aSB(m_thermometer->getCalibrateFactor(0));
aSB(m_thermometer->getCalibrateFactor(1));
aSB(m_thermometer->getCalibrateFactor(2));
aSB(m_thermometer->getCalibrateFactor(3));
aSB(m_thermometer->getAlpha());
aSB(m_thermometer->getPeriodMeasure());
aSB(calcSendChecksum());
aSB((unsigned char)0x16);
calcAndSetFrameLength();
}

View File

@ -63,8 +63,9 @@ String ThermValues::exec(String params) {
for (unsigned int i = 0; i < NUM_OF_CHANNELS; i++) {
m_stream->print(getResource(INDEX_KEY)); m_stream->print(i); m_stream->print(getResource(COMMA_SPACE_KEY));
m_stream->print(getResource(CAL_KEY)); m_stream->print(m_thermometer->getCalibrateFactor(i), 6); m_stream->print(getResource(COMMA_SPACE_KEY));
m_stream->print(getResource(T_KEY)); m_stream->print(m_thermometer->m_temperature[i], 6); m_stream->print(getResource(COMMA_SPACE_KEY));
m_stream->print(getResource(TS_KEY)); m_stream->print(m_thermometer->m_smoothedTemperature[i], 6);
m_stream->print(getResource(R_KEY)); m_stream->print(m_thermometer->m_r[i], 2); m_stream->print(getResource(COMMA_SPACE_KEY));
m_stream->print(getResource(T_KEY)); m_stream->print(m_thermometer->m_temperature[i], 2); m_stream->print(getResource(COMMA_SPACE_KEY));
m_stream->print(getResource(TS_KEY)); m_stream->print(m_thermometer->m_smoothedTemperature[i], 2);
m_stream->println();
}
@ -97,13 +98,8 @@ String ThermCalibrate::exec(String params) {
m_stream->println(getResource(CALI_HELP_4_KEY));
m_stream->println(getResource(CALI_HELP_5_KEY));
m_stream->println(getResource(CALI_HELP_6_KEY));
} else if (params.startsWith("start ") && (space != -1) && m_enabled) {
m_channel = atoi(pb1);
if ((m_channel + 1) > NUM_OF_CHANNELS) {
res = "Invalid channel number";
} else {
m_start_highCalibration = true;
}
} else if (params.startsWith("start") && m_enabled) {
m_start_highCalibration = true;
} else if (params.startsWith("stop")) {
m_start_highCalibration = false;
} else if (params.startsWith("r ") && (space != -1)) {
@ -181,6 +177,14 @@ float pt1000(float r) {
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) {
m_temperature[index] = t;
@ -198,6 +202,10 @@ void Thermometer::setTemperature(unsigned int index, float t) {
m_lastSmoothedTemperature[index] = m_smoothedTemperature[index];
}
float Thermometer::getTemperature(unsigned int index) {
return m_temperature[index];
}
void Thermometer::prepareAdc() {
unsigned long oldRegValue = AD7190_GetRegisterValue(AD7190_REG_CONF, 3, 1);
oldRegValue &= ~(AD7190_CONF_CHAN(0xFF));
@ -341,7 +349,7 @@ void Thermometer::exec() {
SPI_Disable(AD7190_SLAVE_ID);
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;
} else if (m_calibrationZeroMode || thermCalibrate.m_start_zeroCalibration) {
Serial.println(getResource(CALIBRATION_ZEOR_MODE_HINT_KEY));
@ -354,6 +362,7 @@ void Thermometer::exec() {
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);
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.print("r="); Serial.print(r); Serial.print(getResource(COMMA_SPACE_KEY)); }
setR(i, 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.println(); }
@ -381,25 +390,29 @@ void Thermometer::exec() {
if (thermCalibrate.m_start_highCalibration) {
if (m_calibrationHighMode) {
// do the calibration stuff
(thermCalibrate.m_turn)++;
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;
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 (i == thermCalibrate.m_channel) {
thermCalibrate.m_r_sum += r;
}
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.print("t="); Serial.print(thermCalibrate.m_turn); Serial.print(", c="); Serial.print(i); }
if (COMPILE_TIME_DEBUG && getDebug()) { Serial.print(", r="); Serial.print(r, 6); Serial.print(", n="); Serial.print(m_n[i]); }
thermCalibrate.m_r_sum[i] += 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 {
thermCalibrate.m_preserved_alpha = m_alpha;
m_alpha = 1;
thermCalibrate.m_preserved_period = m_periodMillis;
m_periodMillis = 500;
thermCalibrate.m_r_sum = 0.0;
m_periodMillis = CALIBRATION_CYCLE_TIME;
for (unsigned int i = 0; i < NUM_OF_CHANNELS; i++) {
thermCalibrate.m_r_sum[i] = 0.0;
}
thermCalibrate.m_turn = 0;
m_calibrationHighMode = true;
}
@ -408,12 +421,15 @@ void Thermometer::exec() {
m_calibrationHighMode = false;
m_alpha = thermCalibrate.m_preserved_alpha;
m_periodMillis = thermCalibrate.m_preserved_period;
Serial.println(getResource(STATE_20_MSG_3_KEY));
float r_avg = thermCalibrate.m_r_sum / thermCalibrate.m_turn;
float calFact = thermCalibrate.m_r_cal / r_avg;
Serial.print(getResource(STATE_20_MSG_4_KEY)); Serial.print(thermCalibrate.m_channel);
Serial.print(getResource(COLON_SPACE_KEY)); Serial.print(calFact, 6); Serial.println();
setCalibrateFactor(thermCalibrate.m_channel, calFact);
for (unsigned int i = 0; i < NUM_OF_CHANNELS; i++) {
Serial.println(getResource(STATE_20_MSG_3_KEY));
float r_avg = thermCalibrate.m_r_sum[i] / thermCalibrate.m_turn;
float calFact = thermCalibrate.m_r_cal / r_avg;
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;

View File

@ -21,6 +21,8 @@ const float R_REF = 6200.0;
const float PT1000_R0 = 1000.0;
const float PT1000_Coeff = 3.85e-3;
const unsigned long CONV_TIMEOUT = 0xfffff;
const unsigned long NUM_OF_CALIBRATION_CYCLES = 250;
const unsigned long CALIBRATION_CYCLE_TIME = 10; // ms
@ -61,9 +63,8 @@ private:
float m_r_cal;
float m_preserved_alpha;
unsigned long m_preserved_period;
unsigned int m_channel;
unsigned int m_turn;
float m_r_sum;
float m_r_sum[NUM_OF_CHANNELS];
};
class Thermometer {
@ -73,6 +74,10 @@ public:
void exec();
friend class ThermConfig;
friend class ThermValues;
float getTemperature(unsigned int index);
float getCalibrateFactor(unsigned int i);
unsigned long getPeriodMeasure();
float getAlpha();
private:
unsigned long m_periodMillis;
@ -85,6 +90,7 @@ private:
unsigned long m_n[NUM_OF_CHANNELS];
float m_calibrateFactor[NUM_OF_CHANNELS];
float m_r[NUM_OF_CHANNELS];
float m_temperature[NUM_OF_CHANNELS];
float m_lastSmoothedTemperature[NUM_OF_CHANNELS];
float m_smoothedTemperature[NUM_OF_CHANNELS];
@ -100,12 +106,10 @@ private:
void prepareAdc();
void setTemperature(unsigned int index, float t);
void setR(unsigned int index, float r);
void setPeriodMeasure(unsigned long p);
unsigned long getPeriodMeasure();
void setAlpha(float a);
float getAlpha();
void setCalibrateFactor(unsigned int i, float c);
float getCalibrateFactor(unsigned int i);
void setDebug(bool b);
bool getDebug();
void setInfo(bool b);

View File

@ -26,7 +26,7 @@ public:
uint8_t getSeconds() { return m_seconds; };
uint8_t getMinutes() { return m_minutes; };
uint8_t getHours() { return m_hours; };
uint8_t getDays() { return m_days; };
uint16_t getDays() { return m_days; };
private:
UptimeCmd m_uptimeCmd;
uint8_t m_seconds;