diff --git a/tecs/tecs.c b/tecs/tecs.c index 94fe5af..440c725 100644 --- a/tecs/tecs.c +++ b/tecs/tecs.c @@ -176,7 +176,8 @@ static int nScan=0, /* number of scanned channels */ alarmListSize=0, keepT=0, /* keep control over power-up */ - swRangeOn=0, /* switch heater range on when controller switched it off */ + swRangeOn=60, /* when not happen several times with less than 60 sec. delay, + switch heater range on when controller switched it off */ initMaxPower=0, /* set MaxPower for the first time */ lockAlarm, cntError; @@ -221,7 +222,7 @@ static float gradata[COC_RES_LEN/4-100]; static char grapar[128]; static int* grasize; -static char ttp[64]; /* temperature, target and power */ +static char ttp[80]; /* temperature, target and power */ typedef struct { char cmd[COC_CMD_LEN]; @@ -622,7 +623,7 @@ again: tLimit=0; tMaxLimit=0; keepT=0; - swRangeOn=0; + swRangeOn=60; loop=1; initMaxPower=1; resist=10; @@ -1203,6 +1204,10 @@ float Power2Percent(float power) { } int ReadHeater(int full) { + static time_t lastOff=0; + static int cntOff=3; + time_t now; + if (loop==1) { if (full) { if (relay) { @@ -1212,8 +1217,22 @@ int ReadHeater(int full) { ERR_P(LscCmd(ser, "HTR?>htr;HTRST?>htrst;RELAYST?1>relay;RANGE?>ibuf")); if (jRange!=0 && ibuf==0) { if (swRangeOn) { - logfileOut(LOG_MAIN, "controller switched heater off - switch on again\n"); - ERR_P(LscCmd(ser, "RANGE:[jRange]")); + time(&now); + if (lastOff > 0) { + if (now > lastOff + swRangeOn * 2) { + if (cntOff < 3) cntOff++; + } else if (now < lastOff + swRangeOn) { + cntOff--; + } + } + lastOff = now; + if (cntOff > 0) { + logfileOut(LOG_MAIN, "controller switched heater off - switch on again (%d more tries)\n", cntOff-1); + ERR_P(LscCmd(ser, "RANGE:[jRange]")); + } else { + logfileOut(LOG_MAIN, "controller switched heater off definitely (happened to often)\n"); + jRange=0; + } } else { logfileOut(LOG_MAIN, "controller switched heater off\n"); jRange=0; @@ -1260,7 +1279,7 @@ int SetTemp(int switchOn) { tLim = (tLimit+tMaxLimit)*0.5; if (set+tShift <= 0) { /* set + tShift must not be negative */ tShift = -0.999 * set; - } else if (set + tShift > tLim) { /* prevent overshoot */ + } else if (set + tShift > tLim) { /* prevent limit overshoot */ tShift = tLim - set; } setH=FakeScale(ctlSens, set+tShift); @@ -2130,7 +2149,6 @@ void maxSlope(Slope *s, float value) { static Slope slopeS, slopeU, slopeL; - int PeriodicTask(void) { char buf[256], lbuf[16]; char *next, *alms; @@ -2290,7 +2308,7 @@ int PeriodicTask(void) { ERR_I(ReadTemp()); - snprintf(ttp, sizeof(ttp), "%.6g %.6g %.6g", tm, tr, power); + snprintf(ttp, sizeof(ttp), "%.6g %.6g %.6g %.6g %.6g", tm, tr, power, tx, set); if (htrst!=htrst0) { LogMinMax(0); @@ -2397,9 +2415,10 @@ int PeriodicTask(void) { if (oldSet == 0) oldSet = samp.temp; if (oldSet != set || fabsf(d) > 50*ml) { if (oldSet != set) { - if (set < oldSet) { - tShift *= set/oldSet; - } + float f = fabsf((oldSet - set)/ (oldSet + set)); + oldShift *= exp(-f*f*25); + tShift = oldShift; + statCrop(&mStat, sStat.lower+tShift, sStat.upper+tShift); state = 1; } else { state = 0; @@ -2424,16 +2443,18 @@ int PeriodicTask(void) { } } else { if (state != 2) { - tShift = oldShift; + /* tShift = oldShift; */ state = 2; statCrop(&mStat, sStat.lower+tShift, sStat.upper+tShift); + } else { + if (shiftLow > tShift) { + tShift = shiftLow; + oldShift = tShift; + } else if (shiftUp < tShift) { + tShift = shiftUp; + oldShift = tShift; + } } - if (shiftLow > tShift) { - tShift = shiftLow; - } else if (shiftUp < tShift) { - tShift = shiftUp; - } - oldShift = tShift; } if (tShift > ml * maxShift) { tShift = ml * maxShift;