Echelon Mini FX User Manual

Page 104

Advertising
background image

Mini FX User's Guide

91


Thermostat();
}

when(timer_expires(sampleTimer)) {
Thermostat();
}

when(nv_update_occurs(nviSetpoint)) {
Thermostat();
}

void OnButtonPressed(void)
{
// do nothing in this application

}

The Thermostat() function then implements the behavior of the functional block:

//
// The Thermostat function samples the current temperature,
// computes the control values for heater and cooler, and
// updates the status network variable as it goes along.
// Current and setpoint values are being displayed, and the
// next sample is scheduled.
//
// Thermostat() uses the Display() utility function.
//
void Display(unsigned row, unsigned column,
const char* format, SNVT_temp_p value);

void Thermostat(void)
{
SNVT_temp_p reading;

// Get the true current temperature
reading = GetTemperature();

// Discard current reading and use previous value, if new
// reading is still within hysteresis band:
if (nciHysteresis == 0
|| reading < nvoCurrent-nciHysteresis
|| reading > nvoCurrent+nciHysteresis) {
nvoCurrent = reading;
} else {
// refresh output network variable for re-propagation
// (heartbeat)
nvoCurrent = nvoCurrent;
}

// compute cooler and heater control values
if (nvoCurrent < nviSetpoint) {
nvoCool = 0;
nvoHeat = nvoUnitStatus.heat_output_primary =
muldiv(nviSetpoint-nvoCurrent,
nciHeatFactor.multiplier,
nciHeatFactor.divisor);
nvoUnitStatus.mode = HVAC_HEAT;
}
if (nvoCurrent > nviSetpoint) {
nvoHeat = 0;
nvoCool = nvoUnitStatus.cool_output =
muldiv(nvoCurrent-nviSetpoint,
nciCoolFactor.multiplier,
nciCoolFactor.divisor);
nvoUnitStatus.mode = HVAC_COOL;
}
// Indicate heat/cool status and drive value display
SetLeds((boolean)nvoCool, (boolean)nvoHeat);

Display(2,0, "Current: 0.00", nvoCurrent);

Advertising