Example 6.

Data Conditioning

 

The previous examples show how outputs are computed from the inputs in a rather straightforward manner.  In some cases, rather than using the inputs as they are read, raw data needs to be conditioned.  First consider the case of using two temperature sensors in a thermostat control, similar to that of Example 1.  The following program uses the average temperature from the two sensors to decide when the cooling fan should be turned on.

 

 

title  "example 6a. average temperature"

input  iT1, iT2;

output oFan1;

var    vT_Average;

 

vT_Average = (iT1+iT2)/2;

 

oFan1=(vT_Average>75);

 

 

In other cases, you may wish to use the maximum temperature rather than the average.

 

 

title  "example 6b. maximum temperature"

input  iT1, iT2;

output oFan1;

var    vT_Max;

 

if(iT1>iT2)

 {

  vT_Max = iT1;

  }

 else

  {

   vT_Max = iT2;

   }

 

oFan1=(vT_Max>75);

 

 

Averaging the readings from several temperature sensors is a good idea.  You may also consider averaging the readings from a single sensor.  This reduces large swings from the sensor due to unusual circumstances.  For instance, a temperature probe may read a lower temperature if it were accidentally sprayed with water.  The following approach is called data smoothing, or “exponential” smoothing.  The successive readings are weighted according to a scheme.

 

 

title  "example 6b. data smoothing"

input  iT1;

output oFan1;

var    vT_Smooth;

 

vT_Smooth = ((9*vT_Smooth) + iT1 )/10;

oFan1 = if(vT_Smooth>75);

 

 

As long as the temperature changes slowly, the smoothed value would be equal to the temperature.  On the other hand, outliers in the data would have less effect on the smoothed value.  Other than outliers, smoothing helps with the operation of the program when the temperature input is at the cutoff point.  In this case, the successive evaluations of the condition may produce several on and off cycles until the temperature moves away from the cutoff point.  Using smoothed data reduces the tendency of many on and off cycles.

 

The indeterminism encountered when the input is close to the cutoff point can also be addressed by implementing hysteresis.  Hysteresis means that the set point is different for raising and falling values of the input.  Another way of looking at hysteresis is to consider a “dead band” around the set point, in which the output is not changed.

 

 

title  "example 6c. hysteresis "

input  iT1;

output oFan1;

 

if(iT1<74)

 {

  oFan1 = 0;

  }

if(T1>76)

 {

  oFan1=1;

  }

 

 

In the program above, the fan is switched on when the temperature exceeds 76 degrees.  The fan remains on until the temperature drops below 74 degrees.  Now, the fan will once again be turned on when the temperature exceeds 76 degrees.  So in the range 74 to 76, the fan may be on or off, depending on whether the temperature had been rising or dropping.

 

Also see : Programming, Program Examples, Script Syntax

 

 


© Rigel Corporation iNetGrow 2003-2006.  All rights reserved.