Timer object – Echelon Neuron C User Manual

Page 178

Advertising
background image

158

Timer Declarations

Timer Object

A timer object is declared using one of the following:

mtimer [repeating]

timer-name

[

=initial-value

];

stimer [repeating]

timer-name

[

=initial-value

];

mtimer

Indicates a millisecond timer.

stimer

Indicates a second timer.

repeating

An option for the timer to restart itself automatically

upon expiration. With this option, accurate timing

intervals can be maintained even if the application cannot
respond immediately to an expiration event.

timer-name

A user-supplied name for the timer. Assigning a value to
this name starts the timer for the specified length of time.

Assigning a value of zero to this name turns the timer off.

The value of a timer object is an unsigned long (0..65535);
however, the maximum value assigned to a millisecond

timer cannot exceed 64000. A timer that is running or

has expired can be restarted by assigning a new value to
this object. The timer object can be evaluated while the

timer is running, and it indicates the time remaining. Up

to 15 timer objects can be declared in an application.

initial-value

An optional initial value to be loaded into the timer on

power-up or reset. Zero is loaded if no initial-value is

supplied (and therefore the timer is off).

When a timer expires, the timer_expires event becomes TRUE. The

timer_expires event returns to FALSE after the timer_expires expression is read,
or when the timer is set to zero.
Example:

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

when (timer_expires(led timer))
{
toggle_led();
led_timer = 2; // restart timer with value of 2 sec
}

The timers_off( ) function can be used to turn off all application timers – for

example, before an application goes offline. See Chapter 2,

Focusing on a Single

Device,

of the

Neuron C Programmer's Guide

for a discussion of timer accuracy.


Advertising