Example 1.

Simple Thermostat Control

 

Consider a controller with a temperature input “iT1” and a digital output “oFan1” connected to drive a cooling fan.  The following is a simple example that implements a thermostat-type control scheme.

 

 

title     "example 1a.  simple thermostat control"

input     iT1;

output    oFan1;

 

if(iT1<75)

 {

  oFan1=0;

  }

 else

  {

   oFan1=1;

   }

 

 

The program is constructed around a single condition.  If the temperature is less than 75 degrees, the fan is off (0).  Otherwise, the fan is on (1).

 

The iNetGrow interpreter saves the instructions in non-volatile memory.  The instructions are executed periodically.  Typically, this happens once every 10 seconds.  Organizing the program logic so that it is implemented with as few instructions as possible is a fundamental drive among programmers.  In the iNetGrow system, such streamlined code takes less memory space and executes faster.  In the spirit of streamlining, consider the following revision.

 

 

title     "example 1b.  simple thermostat control"

input     iT1;

output    oFan1;

 

oFan1=(iT1<75);

 

 

Here, the state of the fan is simply computed as the value of the condition.  If the condition is true, then the fan is turned on.  Otherwise, the fan is off.  The first version uses a conditional statement and two assignment statements.  The second version uses a single assignment statement and a condition.

 

This program uses the set point 75 degrees.  The next example (Example 2) illustrates how set points may be implemented as parameters.  Parameters may be changed without the need to modify the code and download it to the controller.

 

The above program suffers from indeterminacy while the temperature is at the set point (75) degrees.  Suppose the temperature so close to the set point that successive temperature readings give 74 or 75, almost in a random fashion.  The fan may be on one execution cycle and off the next.  Having the fan turn on and off every 10 seconds is undesirable.  Thermostat control may employ dead bands or data smoothing to prevent this phenomenon.  These topics are examined in Example 6.

 

Also see : Programming, Program Examples, Script Syntax

 

 

 


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