beautypg.com

Echelon I/O Model Reference for Smart Transceivers and Neuron Chips User Manual

Page 37

background image

I/O Model Reference

27

}

when (io_update_occurs(inOntime)) {
io_select(inPeriod, 3);
}

When a new clock is set for an I/O object using the io_select( ) function, this clock

remains in effect until a new value is explicitly set. The next io_select( ) call for
the same I/O object resets the clock to the value specified in the I/O object

declaration if there is no clock argument in the io_select( ) call. If your

application specifies an alternate clock value, it must call the io_set_clock( )
function within the reset task and after each call to the io_select() function.
If an input measurement is attempted using io_in( ) or a when clause on an I/O
object that has not been selected with the io_select( ) function, a data value of

overrange

(65535) is returned, and the input_is_new variable and

io_update_occurs event remain FALSE.

Following a call to the io_select( ) function and after resetting the Neuron Chip or

Smart Transceiver, the first measurement taken for the newly selected I/O object

is discarded to clear out any incomplete measurements (unless the function
io_preserve_input( ) is called before the io_in( ) call). The io_update_occurs event

actually occurs when the second measurement is read. Rely on either an

io_update_occurs event or use the input_is_new variable to verify that an actual
measurement has been made following a call to io_select( ).
Example 1: The following example shows the use of the io_select( ) function with

the multiplexed timer/counter circuit. For multiplexed I/O objects, the last I/O
object declared in the program is the first to take effect after a reset.

// I/O Definitions
IO_5 input period mux clock (2) ioPeriod2;
IO_4 input period mux clock (2) ioPeriod1;

static long variable1, variable2;

// The following occurs only when ioPeriod1 is selected
when (io_update_occurs(ioPeriod1)) {
variable1 = input_value;
// select next I/O object
io_select(ioPeriod2);
}

// The following occurs only when ioPeriod2 is selected
when (io_update_occurs(ioPeriod2)) {
variable2 = input_value;
// select next I/O object
io_select(ioPeriod1);
}

Example 2: In the following example, the timer/counter is multiplexed between
an ontime measurement on pin IO5 and a period measurement on pin IO6.

Because the ontime input can cover a large range of values, this example uses a

form of “auto-ranging.” The clock value switches between 4 and 2 if the input
measurement value extends beyond certain values. A variable is used when

reselecting the ontime object because its clock can be one of the two values.

unsigned long slope1Raw, cycleAValue;