Echelon NodeBuilder FX/PL Examples User Manual

Page 27

Advertising
background image

NodeBuilder FX/PL Examples Guide

19

8. Repeat steps 3 and 4, but rename the nviAnalog network variable to nviAnalogOutput.

9. Right-click

the

AnalogInput functional block’s Implementation-specific CPs folder and select

Add CP from the shortcut menu. The Add Configuration Property dialog opens.

10. Add an implementation-specific SCPTupdateRate configuration property. Name the new

configuration property cpUpdateRate. Set Static CP for this configuration property; this will
cause a single configuration property to be added that applies to all functional blocks in the
AnalogInput functional block array. Set Initial Value to 5. This configuration property will be
used to specify how often each AnalogInput functional block will read the analog-to-digital
converter (ADC) hardware inputs.

Setting the InitialValue field to 5 will cause the value of this configuration property to be set to 5
when the application is loaded into the device. The value of "5" is the unscaled value,
representing 500ms or 0.5s.

11. Click OK.

12. Click Generate and Close.

13. Open the AnalogOutput.nc file from the Source File folder and add the following code in bold to

the FBC_WHEN_RESET else-if statement in the AnalogOutputDirector() function:

else if ((TFblock_command)iCommand == FBC_WHEN_RESET)

// init output signals to 0

GizmoWriteAnalog(0,

0L);

GizmoWriteAnalog(1,

0L);

//

get

going:

setLockedOutBit(uFblockIndex,

FALSE);

This code causes the analog output signals to be set to 0 when the device is reset. You could add a
default value implementation specific configuration property for a more flexible solution then a
hard-coded 0V output after power-up and reset. This has not been implemented in this step
because you already implemented such a configuration property in Step 3: Adding Digital I/O.

14. Still in the AnalogOutput.nc file, add the following code in bold to the

AnalogOutputprocessNV()

function:

void AnalogOutputprocessNV(void)
{

signed long slOutputValue;

slOutputValue = nviAnalogOutput[deviceState.nvArrayIndex];

slOutputValue /= 20L;

GizmoWriteAnalog(deviceState.nvArrayIndex,

abs(slOutputValue));

}

This code computes the output value. The SNVT_lev_percent network variable type has a valid
range of -163.84% to 163.83% in steps of 0.005%. The value expected by the
GizmoWriteAnalog()

function, however, has a value range of 0.0 to 100.0% in steps of

0.1%.

The slOutputValue variable has the correct value but is still a signed variable, and could have the
correct absolute value but the incorrect sign. This example uses the abs() function to ignore the
sign.

15. Open the AnalogInput.nc file from the Source Files folder. Add the following declarations in

bold at the top of the file:

#ifndef _AnalogInput_NC_
#define _AnalogInput_NC_

#include "common.h"
#include "AnalogInput.h"

Advertising