Custom modules - timer reference
The timer and timer_ext sections aren't part of the
MatPLC library proper; if you want them, you have to explicitly link to
them. They can be found in the mat/lib/logic directory.
Timers are basically floats, with the additional feature that they can be
enabled to increase at a rate of one per second. They are also
fixed-precision, storing time as an exact number of microseconds.
Note that most of the functions listed below are actually macros; they
modify the value of timer directly.
- The timer type.
- Set to zero and
disable. The timer is now zeroed and stopped.
- Set to zero and
enable. The timer is now zeroed and running.
- Enable the timer.
This will make the value increase at a rate of one per second.
- Disable the timer.
This will make it keep whatever value it has at the moment without
- Add a number
to the timer, effectively winding it forward. This works whether it's
enabled or disabled. Use negative values to decrease the timer (wind it
- Set to a particular
value. This works whether it's enabled or disabled. However, to avoid
loss of precision, prefer to use
- Get the current
value of the timer. This works whether it's enabled or disabled.
int plc_timer_done(timer, preset)
- Check whether
timer is at least
preset seconds. This works whether it's
enabled or disabled.
This is very similar to the above, with two differences: all the
functions/macros end with _ext, and they all take an extra
argument which they use as the current time instead of obtaining it from
the operating system. The extra argument should be of type
timeval, as used by the
gettimeofday(2) system call.
One might use timer_ext if one runs in a conventional scan and
doesn't want timers to expire mid-loop. To achieve this, call
gettimeofday(2) once at the start of the loop and then use
that time as the last argument to all the timer_ext calls.
$Date: 2005/12/08 09:24:46 $