Using functions or events – Echelon I/O Model Reference for Smart Transceivers and Neuron Chips User Manual
Page 35
I/O Model Reference
25
Using Functions or Events
To determine whether an input value is new, you can use the io_in( ) function
with the input_is_new variable or you can use the io_update_occurs event with
the input_value variable. Which method you choose depends on the specific I/O
model and the specific task that the program is designed to perform.
The I/O event mechanism tends to be the simpler method, where the Neuron
scheduler decides when to perform the I/O functions. However, when you are
combining multiple events in a single block of logic, you might need to call the
io_in( ) function explicitly, combined with the input_is_new variable.
The two examples shown in Table 10 demonstrate different ways to accomplish
the same goal.
Table 10. Comparing io_update_occurs and io_in()
io_update_occurs with input_value
IO_5 input pulsecount ioPulsecount;
when (io_update_occurs(ioPulsecount)) {
if (input_value > 2) {
. . .
}
}
io_in( ) with input_is_new
stimer delayTimer;
IO_5 input pulsecount ioPulsecount;
when (timer_expires(delayTimer)) {
. . .
if ((io_in(ioPulsecount) > 2) && input_is_new) {
. . .
}
}
Important: If you combine explicit calls to the io_in( ) function with when clauses
that contain I/O events, synchronization problems can result. For example, if a
when clause evaluates to TRUE near the end of an I/O sampling period, the
io_in( ) call might not be executed until the following period, and the value
obtained could be misleading.
when (io_update_occurs(ioPulsecount)) {
. . .
z = input_value; // don’t use io_in(ioPulsecount) here
. . .
}