Supported platforms: CODESYS 3.5

 

How to use & save parameters in a Control Unit

This section describes how to use and save parameters from CODESYS application code.

The guide is made assuming that MultiTool Creator code template is used.

 

A control unit application has two types of parameters:

 

MultiTool Creator code template automatically includes NVMemory (PRG) which handles non-volatile memory operations using SSeriesHardware library's NVMem (PRG).

 

All memory areas use the ParameterHandler library for handling the images between RAM and NVRAM. Parameter handler also checks the image integrity.

 

It is NOT recommended to save parameters in every program cycle. Especially OD parameter saving can be time consuming (depends on amount of parameters).

 

CANopen OD parameter saving can also be done from the CAN bus with SDO protocol but it is not covered by this example.

 

Refer to the following for adjusting and saving control unit OD parameters from a 6000 series unit:

 

Fast parameters

MultiTool Creator code template generates FastParameters STRUCT into the UserCode folder. Fast parameters are defined directly to FastParameters structure in CODESYS.

 

It is recommended to add new variables to the end of the structure.

Variable data types should not be changed in existing systems, to maintain integrity of the image.

 

Application default values are used when:

  • NVRAM is empty (new unit)

  • Both primary and backup memory area is corrupted.

 

 

Parameter values are accessed by the global variable G_Common.FastParameters. Saving is triggered by writing TRUE in the global variable G_Common.SaveFastParameters. The code template automatically resets the save flag.

 

Definitions:

 

TYPE FastParameters :

STRUCT

FastParameter1: BYTE;

FastParameter2: WORD;

FastParameter3: DWORD;

END_STRUCT

END_TYPE

 

 

Definitions:

 

VAR

local_var:BYTE;

trigger:BOOL;

trigger_old:BOOL;

END_VAR

 

 

Code:

 

G_Common.FastParameters.FastParameter1 := local_var;

IF trigger AND NOT trigger_old THEN

G_Common.SaveFastParameters := TRUE;

END_IF

trigger_old:=trigger;

 

 

CANopen OD parameters

When OD parameters are defined in MultiTool Creator, the OD variables are generated to a CAN specific

global variable list (e.g. G_CAN1_PAR).

 

CANopen OD parameters are saved from a CODESYS application using the CANopenODSave library.

 

The following code saves all OD parameters in CAN1.

 

Definitions:

 

odSaveResult: EPEC_ODSAVE.SaveODErrors;

 

Code:

 

(*save parameters to nvram*)

G_CANopen_CAN1.SaveAll.Callback(o_Error => odSaveResult);

See also

 

Source file topic1003061.htm

Last updated 13-Jun-2024