Example 2: simple light dimmer interface – Echelon Neuron C User Manual

Page 45

Advertising
background image

Neuron C Programmer’s Guide

33

desiredTemp = max(DESIRED_TEMP_MIN, desiredTemp);
}
////////////////////////////////////////////////////////
// Timer task -- execute control algorithm
// A timer is used to decide periodically whether to
// activate heating or cooling. The temperature comparison
// is done only every five minutes to prevent cycling the
// equipment too frequently. There are two digital outputs:
// one for activating the heating equipment, and one for
// activating the cooling equipment.
when (timer_expires(tmCheckHeatOrCool)) {
switch (equip) {
case HEATING:
if (newTemp > desiredTemp) { // if too hot
equip = OFF; // turn off heater
io_out(ioHeatingOn, FALSE);
}
break;

case OFF:
if (newTemp < desiredTemp - BAND_SIZE) {
equip = HEATING;

// if too cold, then

io_out(ioHeatingOn, TRUE); // turn on heater
} else if (newTemp > desiredTemp + BAND_SIZE) {
equip = COOLING;

// if too hot, then

io_out(ioCoolingOn, TRUE); // turn on cooler
}
break;

case COOLING:
if (newTemp < desiredTemp) { // if too cold
equip = OFF; // turn off cooler
io_out(ioCoolingOn, FALSE);
}
break;
}
}

///////////////////////////////////////////////////////
// Reset task -- Set the repeating timer to 300 seconds

when (reset) {
tmCheckHeatOrCool = 300; // 5 minutes, repeating
}

Example 2: Simple Light Dimmer Interface

The following example shows Neuron C code for a simple light dimmer. The
example uses two I/O objects, a triac control circuit to control the lamp brightness

and a quadrature input to select the light level (see Figure 3 on page 34). For the

triac output object, a value of 1 is maximum brightness, and a value of 320 is
minimum brightness (OFF) when the line frequency is 60 Hz. The initial value

on power-up is full OFF (65535).
The io_update_occurs event is used in a when clause. An implicit call to io_in( )
occurs when this event is called. The program can then access the measured

Advertising