Using 3606 NVRAM

Feature

Value

Description

Total Size of NvRam

2048 bytes

Size of the 3606 NvRam. This area is split into parts for normal parameters and fast parameters.

Size of fast parameters

256 bytes

Size of the fast parameters which are saved in one saving to NvRam. It is recommended to include in this group all parameters which are necessary to save with the fast cycle (machine hours,...).

Size of normal parameters

1792 bytes

Normal parameters are parameters which are not saved very often. These are, for example, different configuration parameters.

NvRam init overhead to cycle time

15 ms

Calling the function NvRam_3606_Init causes  about 15ms overhead to cycle time.

NvRam save overhead to cycle time

4 ms

Calling the function NvRam_3606_Save causes  about 5ms overhead to cycle time.

Undervoltage protection

No

The handling function for NvRam doesn't contain internal undervoltage protection, which means that it is  recommended to check that the supply voltage is above the low limit before calling NvRam save.

Time until save of the fast parameters is completed

10 ms

Time which is needed from the start of the fast parameters saving until it is completed.

Time until save of the parameters is completed

40 ms

Time which is needed from the start of the normal parameters saving until it is completed.

 

Usage of NvRam in 3606

The 3606 control unit offers 2 kbyte NvRam which is used to save parameters. This area is divided into two areas, fast parameters and normal parameters. Fast parameters are used for data which is wanted to save with the fast saving cycle (like machine hours, states, etc.). Normal parameters are used for parameters which are saved more seldom.

 

Library 3606int contains two data arrays through which data is accessed from/to NvRam (G_3606_FastParamsData and G_3606_ParameterImage).  For fast parameters it is also possible to define variables directly by using %M addresses (%MB10004 ... %MB10254).

 

Saving an initializing of the nvram data causes a small increase in the PLCopen application cycle. This increase is about 4ms for saving of the fast and normal parameters (NvRam_3606_Save) and 10-15 ms for init of the nvramdata (NvRam_3606_Init).

 

Even if the saving of the data from RAM to NvRam is fast, it is recommended to somehow trigger saving and not use continous saving.

 

Before saving it is recommended to check the supply voltage level. If the supply voltage is close to low limit (may depend of the control unit version), it is no recommended to trigger the saving of the parameters to NvRam NvRam_3606_Save.

 

The block diagram below describes usage of the NvRam parameters. In the initialization phase the data is copied from NvRam to corresponding data buffers in RAM. Before copying, the validity of the saved data in NvRam is checked and if there are errors, the data in RAM is set to 0.

 

Fast parameters

Fast parameters are accessed through %MB area. Area %NB10000 – 12288 is reserved for the use of the fast parameters.

Fast parameter structure contains CRC and a keyword field which are checked in NvRam_3606_Init function. If the keyword and CRC doesn't match with the  saved values, the keyword is changed to the one given as input to NvRam_3606_Init and the entire user data area is reset.

 

Below is a description from the template definition for fast parameters.

 

G_3606_FastParamsSave:BOOL:=FALSE; (* Flag to start saving of the fast parameters. *)

 

 

 

(*

User should define own fast parameters for this M-area 12004 - 12255.

Below is three example parameters. It is not possible to change address of the parameters

once they are started to use. It is basically possible to replace already used parameter

with new one.

 

For example :

 

Before ...

G_3606_UserParam1 AT %MB10004:BYTE; (* Example for the usage of the fast parameters.*)

G_3606_UserParam2 AT %MB10005:BYTE; (* Example for the usage of the fast parameters.*)

 

Replaced ...

G_3606_UserParamChanged AT %MB10004:WORD; (* Example for the usage of the fast parameters.*)

 

But now this parameter gets values from old parameters  G_3606_UserParam1 and G_3606_UserParam2

*)

 

 

 

 

G_3606_FastParamsKeyword AT %MB10000:DWORD; (* Keyword which can be used to check that data and codesys project matches. *)

 

(* User defined parameters starts *)

G_3606_UserParam1 AT %MB10004:BYTE; (* Example for the usage of the fast parameters.*)

G_3606_UserParam2 AT %MB10005:BYTE; (* Example for the usage of the fast parameters.*)

(* User defined parameters end. *)

 

G_3606_FastParams_CRC AT %MB10255:BYTE; (* CRC which is used to check data when load from NVRAM. *)

 

 

 

 

The user can freely add their own fast parameters to memory area %MB10004 - %MB10254. After the PLCopen application is taken into use it is not possible to change the place for parameters.

 

Normal parameters

Normal parameters are offered as data array G_3606_ParameterImage in 3606int.lib. Through this array data is saved to NvRam and read from NvRam. The programmer can freely use this data array to save their own parameters. Only the first two and last two bytes are reserved for internal use.

 

Data healthy is checked with the header and footer tags in data array. These tags are increased by one in every saving. These values are again checked in the init phase and if they differ, all the data is set to 0.

Code example

Definitions:

 

(* Fast parameters *)

G_3606_FastParamsKeyword AT %MB10000:DWORD;

G_3606_FastParamArray AT %MB10004: ARRAY [1..251] OF BYTE := 251(0);

G_3606_FastParams_CRC AT %MB10255:BYTE;

G_3606_FastParamsError:INT;

G_3606_ParamsError:INT;

 

 

(* Normal parameters*)

params:POINTER TO MyNvRamData;

 

cycleTime: TIME;

oldCycleTime: TIME;

maxCycleTime: TIME;

i: WORD;

 

bInitNVramData: BOOL := TRUE;   (* In start, call init once to copy nvram data to application. *)

bSaveFastParam: BOOL;

bSaveParam: BOOL;

 

 

(* structure *)

TYPE MyNvRamData :

  (* This structure defines parameter data for normal parameters. *)

  (* Change data. NOTE!!!! It is possible to add struct members in the end but not in the middle, because structure is saved as one data area to nvram*)

  STRUCT

    ParString:STRING;

    ParWord:WORD;

    ParDword:DWORD;

  END_STRUCT

END_TYPE

 

 

Init:

 

 

 

 

Code:

 

(* Measure maximum cycle time *)

cycleTime := TIME()- oldCycleTime;

oldCycleTime := TIME();

 

IF cycleTime > maxCycleTime THEN

    maxCycleTime := cycleTime;

END_IF

 

(* Read data from nvram *)

IF bInitNVramData THEN

    bInitNVramData := FALSE;

    params:= ADR(G_3606_ParameterImage[3]); (* Set user data to point parameter image. *)

 

    (* reads data from nvRam *)

    NvRam_3606_Init(

    i_Enable:= TRUE,

    i_KeyWordFastParams:= 16#12345678,

    i_SizeOfParams:= G_3606_PARAM_SIZE,

    i_SizeOfFastParams:= G_3606_FAST_PARAM_SIZE,

    o_ErrorParams =>G_3606_ParamsError,

    o_ErrorFastParams => G_3606_FastParamsError);

END_IF

 

(* Call PRG to finish possible commands. *)

NvRam_3606_Save(

    o_ErrorParams=> G_3606_ParamsError,

    o_ErrorFastParams=>G_3606_FastParamsError);

NvRam_3606_Init(

    o_ErrorParams=> G_3606_ParamsError,

    o_ErrorFastParams=>G_3606_FastParamsError);

 

IF bSaveParam AND NOT NvRam_3606_Save.o_Busy AND NvRam_3606_Init.o_InitDone THEN

    (* If flag is set and no other operation going on --> copy parameter data to nvram *)

    bSaveParam := FALSE;

 

    (* Change data. NOTE!!!! It is possible to add struct members in the end but not in the middle, because structure is saved as one data area to nvram*)

    params^.ParString := 'Hello world';

    params^.ParWord := params^.ParWord + 1;

    params^.ParDword := params^.ParDWord + 1000;

 

    (* In parameter image first 2 bytes and last 2 bytes are used for tag to secure that saving is always went trough.*)

 

    (* Start saving of parameter data *)  

    NvRam_3606_Save(

    i_SaveParamsStart:= TRUE,

    i_SaveFastParamsStart:= FALSE,

    i_TimeOutValue:= T#200ms,

    i_SizeOfParams:= G_3606_PARAM_SIZE,

    i_SizeOfFastParams:= G_3606_FAST_PARAM_SIZE,

    o_ErrorParams=> G_3606_ParamsError,

    o_ErrorFastParams=>G_3606_FastParamsError);

END_IF

 

IF bSaveFastParam AND NOT NvRam_3606_Save.o_Busy AND NvRam_3606_Init.o_InitDone THENbSaveFastParam := FALSE;

    (* If flag is set and no other operation going on --> copy fast parameter data to nvram *)

    bSaveFastParam := FALSE;

    

    (* Add fast parameter array by one *)

    FOR i:= 1 TO 251 DO

        G_3606_FastParamArray[i] := G_3606_FastParamArray[i] + 1;

    END_FOR

 

    (* Start saving of parameter data *)  

    NvRam_3606_Save(

        i_SaveParamsStart:= FALSE,

        i_SaveFastParamsStart:= TRUE,

        i_TimeOutValue:= T#200ms,

        i_SizeOfParams:= G_3606_PARAM_SIZE,

        i_SizeOfFastParams:= G_3606_FAST_PARAM_SIZE,

        o_ErrorParams=> G_3606_ParamsError,

        o_ErrorFastParams=>G_3606_FastParamsError);

END_IF

 

 

 

 

 

Source file Topic000655.htm

Last updated 21-Feb-2025