Supported platforms: CODESYS 3.5 SAFETY
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 safety control unit application has two types of parameters:
Fast parameters
CANopen OD parameters (defined in MultiTool Creator)
The CANopen OD parameters are divided into non-safety and safety parameters depending on their usage.
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 safety control unit OD parameters from a 6000 series unit: |
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:
|
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; |
|
|
When OD parameters (non-safety/safety) are defined in MultiTool Creator, the OD variables are generated to a CAN specific
global variable list (e.g. G_CAN1_PAR). Non-safety parameters (Variable Type is Parameter) are accessed directly using this non-safety variable list.
If the OD index Variable Type is SafetyParameter, its CRC is validated during the application's initialization.
If the safety parameter CRC is valid, the parameter values are copied to a safe global variable list (e.g. G_CAN1_SPAR).
Safe application code shall access safety parameters using the safe GVL (e.g. G_CAN1_SPAR). |
Safe application shall check that the safety parameter CRC validation is OK using the variable G_SystemFlags_Safe.S_SafeOperationEnable |
Copying parameter values to safety parameters is done only once at initialization, so changes in safety parameter's non-safety OD variables do not automatically affect the safety parameters. |
Safety parameters are restricted to exist only in one CAN bus at a time. |
When a CANopen OD parameter is defined as a safety parameter, the safety adjustment sequence is required when adjusting through CAN bus. Safety parameter adjustment is only disabled from the SDO server's side until authentication is enabled. This does not affect the application code. |
CANopen OD parameters are saved from a CODESYS application using the CANopenODSave library.
All non-safety and safety parameters are in the same parameter image so OD saving is not different for safety and non-safety parameters. |
If an application code needs to change a safety parameter OD index value from the CODESYS application, then it also needs to handle safety parameter CRC updating (see the example in How to calibrate a joystick). Otherwise, CRC check will fail after boot-up. |
CANopenODSave is a non-safety library so parameter saving is always used through non-safety context (called from non-safety Main PRG). |
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); |
NVMem (PRG)
Parameters library
ParametersSave (FB)
Source file topic100473.htm
Last updated 19-Dec-2024