beautypg.com

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

Page 31

background image

I/O Model Reference

21

#define ON 1
#define OFF 0

IO_0 output bit ioRelay;
// or IO_0 output bit ioRelay = ON;

The second (commented out) declaration in the example above uses an

initializer

,

which tells the system that following a reset, the ioRelay object output value
should initially be set to 1. The default initial value is 0.
Now you can control the state of ioRelay by using the io_out( ) function:

if (flowTotal > 500) {
io_out(ioRelay, ON);
}

The io_out() function takes a valid C expression for its argument. If the type of

the expression matches the type of the output-value argument (which in turn is a
function of the I/O model in use), you can also control the relay with direct logic:

io_out(ioRelay, flowTotal > 500);

input_is_new Variable

For all timer/counter input models, the built-in input_is_new variable is set to

TRUE whenever the io_in( ) call returns an updated value. This variable is also
set for implicit calls (see

I/O Events

on page 22 for information about implicit

io_in( ) calls). The data type of the input_is_new variable is an unsigned short.

The frequency with which updates occur depends on the I/O model.

Note that the input_is_new variable is cleared after a related timer/counter

interrupt executes; see the

Neuron C Programmer’s Guide

for more information

about timer/counter interrupts and their relation to I/O functions and I/O

(timer/counter) events.
Example: This example uses one of the timer/counter I/O devices. Assume that
the IO7 pin is attached to an optical flow meter that presents a number of pulses

proportional to the volume of a fluid. The total volume in gallons needs to be

determined. This example uses a Series 3100 Smart Transceiver with a 10 MHz
input clock.
The pulsecount input model counts input edges and latches the count

approximately every 0.8388608 (specifically, every 2

23

/10

7

seconds). If you were

to use the io_in( ) function for this I/O object, you would always read the

currently latched

value. If you are summing the total flow, you need to qualify

this operation. Use the input_is_new variable, which is set to TRUE following an
io_in( ) function only if a

new

measurement is made, or in this case, every

0.8388608 seconds.

IO_7 input pulsecount ioFlowSensor;
// 451 pulses/gallon
long totalVolume, tempVolume;

...

{
tempVolume = io_in(ioFlowSensor);
if (input_is_new) {
totalVolume += tempVolume;