beautypg.com

Echelon NodeBuilder FX/PL Examples User Manual

Page 40

background image

32

Using the NodeBuilder FX/PL Example

}

priority when (io_changes(ioWheel)) {

if (fblockNormalNotLockedOut( Wheel::global_index)) {

if

(Wheel::cpWhGain.divisor)

{

// No division by zero. Use gain factor and send new

// incremental value to heartbeat/throttle handler

WheelIncrValue(muldivs(input_value,

Wheel::cpWhGain.multiplier,

Wheel::cpWhGain.divisor));

}

}
}

The Cp2Tick() function converts a SNVT_elapsed_tm value into a tick count (a tick occurs
each WHEEL_HBCORE milliseconds). It uses the seconds, milliseconds, and minutes fields of the
SNVT_elapsed_tm value but ignores the hours and days fields. The function is only used in
conjunction with heartbeat and throttle intervals, which typically do not have values as large as an
hour, and therefore this partial implementation is used for performance reasons.

A priority when-task is used due to the nature of this physical input, which is to provide an
incremental reading. You should normally avoid the use of priority statements except for critical
processing. This when-task is critical since this function must not miss any hardware events as
they occur.

23. Open the wheel.h file from the Source Files folder, and then add the following declarations for

heartbeat/throttle handling:

#ifndef USE_QUADRATURE
#error "You must enable the use of quadrature input in the gizmo4.h header
file!"
#endif

#define WHEEL_HBCORE

100L

// heartbeat/throttle timer ticks

//with

100ms

period


mtimer repeating WheelTimer = WHEEL_HBCORE;

long lWheelValue = 0L;

// last known real value,

//see

the

.nc

file

for

details

on

//

heartbeat/throttle

implementation

long lWheelPhysical = 0L; // same as lWheelValue,
//

but

limited

to

data

coming

from

//

physical

sensor.

See

.nc

file

for

//

details

on

override

and

rmv_override

unsigned long ulMinSendT = 0L;

// number of WHEEL_HBCORE ticks

//

expired

on

cpMinSendT

unsigned long ulMaxSendT = 0L;

// number of WHEEL_HBCORE ticks

//

expired

on

cpMaxSendT


// forward declaration:
void WheelIncrValue (long Value);

24. Open the wheel.nc file from the Source Files folder and add the following function to handle

the network variable throttle:

void WheelIncrValue (long Value) {

// maintain internal mirror of most recent value - remember the

// quadrature input provides incremental data. We cannot lose

// a single signal update.

lWheelValue += Value;


// also maintain a copy of the last known value coming from the

// physical sensor (as opposed to override values). This data

// is used when leaving override mode, see director function

// for more details.

lWheelPhysical = lWheelValue;