- changed the behaviour when heater is switched off by the controller

- optimized double control
This commit is contained in:
zolliker
2007-02-23 12:48:35 +00:00
parent 190883982c
commit 6c6da3f11f

View File

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