Examples, The timer_expires event – Echelon Neuron C User Manual

Page 38

Advertising
background image

26

Focusing on a Single Device

initial-value

An optional initial value to be loaded into the timer on

power-up or reset. Zero is loaded by the Neuron firmware (in other
words, the timer is turned off) if no explicit initial-value is supplied.

Examples

An example of declaring a timer object and assigning a value to it is shown below:

// start timer with value of 5 sec
stimer led_timer = 5;

An example of turning a timer off is shown below:

stimer led_timer;
when (some-event)
{
led_timer = 0;
}

An example of evaluating the value of a running timer is shown below:

stimer repeating led_timer;
when (some-event)
{
time_remaining = led_timer;
...
}

Note: When setting and examining timers in the NodeBuilder debugger, certain

inaccuracies could occur. When a timer is set during program execution and is

examined while the program is halted (includes single stepping and breakpoints),
the timer value can be as much as 200 milliseconds larger than the actual time

until expiration. No such inaccuracy exists on a timer that is allowed to run

without a debugger halt.

The timer_expires Event

The timer_expires event becomes TRUE when a timer expires. The syntax of this

event is the following:

timer_expires [(

timer-name

)]

timer-name

Specifies a specific timer to check.

If

timer-name

is not included, the event is an unqualified timer_expires event.

An

unqualified event

expression is one that omits the optional qualifier syntax

that limits the objects to which the event applies.
A timer event is unique because it can be cleared only by checking for specific
(qualified) timer expiration events. Other events can be cleared by checking for

either the qualified or unqualified events. For example, the following when

clause checks for the expiration of the led_timer, so the timer_expires event for
that timer is cleared to FALSE.
Examples:

stimer led_timer;
when (timer_expires(led_timer))
{
io_out(io_led, OFF); // Turn off the LED

Advertising