Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Reader Background


This section assumes the reader is experienced with the tools (LonMaker, NodeBuilder, etc.) and mechanisms needed program a Neuron processor from Echelon. What follows is an example that illustrates how to send and receive information through the NIM-6 inter-processor link.


Example: Schema Setup




The figure above shows a LonTalk Input Operator linked to a NIM-6 module and transmitting a floating point value. The information flow from an analog input (Ain1) through a variable (fResTemp) to the Input Operator with a Link Key of 'Temp'. This information is to be transferred to the Neuron.
Note that both the data Type and Neuron Link Key settings are critical for the transfer to take place. The setting in the associated operator must match the settings in the Neuron C code.

Neuron Setup and Programming Overview


NodeBuilder


When setting up a project in Echelon's NodeBuilder tool, follow these general steps:

  1. Select a project name
  2. Set Transceiver type to TP/FT-10
  3. Use the calculator function when setting the program ID. Below are the suggested values to start with:
    1. Manufacturer: Enter Number as 0
    2. Select Category, Device Class, and Usage as per your application. If you are not sure, use Industrial, Industrial (130.00), and Industrial.
    3. Select Channel type as TP/FT-10
    4. Use Model Number of 02
  4. Choose the NIM6 as the device template. If the NIM6 is not in the list, select none for now and follow the directions in the next paragraph.
  5. Finish new project creation



If you need to add the NIM6 as a template, right click on the User Templates in the Hardware Templates folder and select insert copy. Select the 'NIM6.NbHwt' file*. Right click on your device in the device templates folder, select settings, and choose the NIM6 for both the development and release hardware templates.

It is suggested that all the Fairmount Automation LonTalk files* are stored in the same directory as your *.nc source.

To add the Chameleon NIM-6 library file to your project, right click on the libraries folder in the device and select insert. Choose a custom library and select 'ChameleonAPILib.lib' file*.

To adding the Chameleon NIM-6 source files to your project, right click on the Source files directory and add both the 'ChameleonAPIlib.h' and 'fawhencode.nc' files*.

Required Additions to the Neuron C (.nc) Source Code


Your Neuron C source code will need to have the following modifications / additions to talk with the NIM-6 main processor through the inter-processor link:

  • Suggest starting with the 'FADemoApp.nc' file* as a template for your Neuron program.
  • Make sure the following is added: #include "ChameleonAPIlib.h"
  • Define input and output variables and strings for each User structures to link to Chameleon. For example:
    • far FAVarBlock OutputOperatorTableNamexx;
    • far FAVarBlock InputOperatorTableNamexx;
  • Define the inter-processor communications bus:
    • IO_0 parallel slave p_bus;
  • The 'void LinkVars() function' sets the template of data to send to the Chameleon main processor (Up) or receive from the Chameleon main processor (Down):
    • ChameleonLinkVariableUp call
    • ChameleonLinkVariableDown call
  • Include / modify the 'when(reset)' section of code with the following:
    • Initialize the interprocessor API with ChameleonInit(); call
    • Setup the variables to communicate with LinkVars(); call
    • Sync the latest information to the Chameleon processor with CHAMELEONREQUESTUPLOAD(); call
  • Whenever the communication variables associated with the 'Up' direction need to be updated, then you must call CHAMELEONREQUESTUPLOAD();
  • Need to define a global boolean bReceivedUpdate=FALSE;
  • Insert #include 'fawhencode.nc' in the body of the source. This code will respond to the interprocessor bus activity

Include a 'when(bReceivedUpdate == TRUE)' function and in this function copy the variables from the 'Down' link (i.e. from the Chameleon main processor to the Neuron) and reset bReceivedUpdate to false.
*Note: All of the configuration, library, and example files referenced in this section are available for download at the Fairmount Automation software library website.

Example: Neuron C Code




The Neuron C code for this data transfer follows:

////////////////////////////////////////////////////////////////////
// Example Neuron C Application shell demonstrating Chameleon API
// Copyright 2005, Fairmount Automation Inc.
// All rights reserved
////////////////////////////////////////////////////////////////////
#pragma num_alias_table_entries 10
////////////////////////////////////////////////////////////////////
// Header Files
////////////////////////////////////////////////////////////////////
#include <string.h>
#include <mem.h>
#include "ChameleonAPIlib.h"
#include <float.h>
#include <s32.h>
#include <string.h>
////////////////////////////////////////////////////////////////////
// Network Variable Declarations
////////////////////////////////////////////////////////////////////
#pragma enable_sd_nv_names
#pragma set_node_sd_string "Sample Neuron/NIM application program"
// Input variables
network input boolean RemEstop;
network output boolean LocalEstop;
network output float_type Temp;
network output float_type State;
network output float_type Speed;
network output float_type SetPt;

////////////////////////////////////////////////////////////////////
// Chameleon Linked Variable Declarations
////////////////////////////////////////////////////////////////////
far char pKeysdi[PDG:1][PDG:15]={"RemEStop"};
far char pKeysdo[PDG:1][PDG:15]={"LocalEStop"};
far char pKeysao[PDG:4][PDG:15]={"Temp", "State", "Speed", "SetPt"};
boolean FA_DigitalIn;
boolean FA_DigitalOut;
float_type FA_AnalogOut[PDG:4];
////////////////////////////////////////////////////////////////////
// user structures to link to Chameleon
////////////////////////////////////////////////////////////////////
far FAVarBlock OutputOperatorTable[PDG:5];
far FAVarBlock InputOperatorTable[PDG:1];
////////////////////////////////////////////////////////////////////
// Timer Declarations
////////////////////////////////////////////////////////////////////
mtimer repeating looptimer=1000;
// timer optimer;

IO_0 parallel slave p_bus; // slave A mode
booleanbReceivedUpdate=FALSE;
void LinkVars()
{
int i,j;
for (i=0;i<1;i++){
ChameleonLinkVariableUp(&InputOperatorTable[PDG:i], &pKeysdi[PDG:i][PDG:0], FA_DigitalIn);
}
for (i=0;i<1;i++){
ChameleonLinkVariableDown(&OutputOperatorTable[PDG:i], &pKeysdo[PDG:i][PDG:0], FA_DigitalOut);
}
for (i=0,j=15;i<4;i+,j+){
ChameleonLinkVariableDown(&OutputOperatorTable[PDG:j], &pKeysao[PDG:i][PDG:0], FA_AnalogOut[PDG:i]);
}
}
////////////////////////////////////////////////////////////////////
// Initialize application in the reset task
////////////////////////////////////////////////////////////////////
when (reset)
{
int i;
i=0;
// initialize the API
ChameleonInit();
// link the chameleon variables
LinkVars();
// request an upload to synchronize the variable table
CHAMELEONREQUESTUPLOAD();
}

////////////////////////////////////////////////////////////////////
// Post any updates of network variables up to Chameleon
////////////////////////////////////////////////////////////////////
when (nv_update_occurs)
{
// copy var
FA_DigitalIn = RemEstop;
// schedule a data upload to the module
CHAMELEONREQUESTUPLOAD();
}

////////////////////////////////////////////////////////////////////
// handle processing for any variable update from Chameleon
////////////////////////////////////////////////////////////////////
when (bReceivedUpdate == TRUE)
{
// copy the values from Chameleon to the network variables
if (OutputOperatorTable[PDG:0].bUpdated)
LocalEstop = FA_DigitalOut;
if (OutputOperatorTable[PDG:1].bUpdated)
Temp = FA_AnalogOut[PDG:0];
if (OutputOperatorTable[PDG:2].bUpdated)
State = FA_AnalogOut[PDG:1];
if (OutputOperatorTable[PDG:3].bUpdated)
Speed = FA_AnalogOut[PDG:2];
if (OutputOperatorTable[PDG:4].bUpdated)
SetPt = FA_AnalogOut[PDG:3];
bReceivedUpdate = FALSE;// clear update flag
}

LonTalk Operators

  • No labels