Help - Search - Members - Calendar
Full Version: memory allocation on CoDeSys or TwinCAT
Forums.MrPLC.com > PLCs and Supporting Devices > CoDeSys
tAotomation
hallo to everybody,
I would like to know how CoDeSys/TwinCAT systems allocates memory. When I declare VAR_CONF, for example STRUCT, it's possible that this STRUCT overwrites some other variables? How variables are addressed? By simbol or by address. I need to declare STRUCTs like a DB (DATA BLOCK) as on Siemens PLCs, is it possible??

Thanks.

PS: sorry for my bad english.
Marco8037
Hello,

I will try to help you, but since I am new on twincat, you can perhaps get better replies.

I have never used VAR_CONF, but you can define a struct on Data types.

For example:

On data types, do the following code:

TYPE TABLE_1 :
STRUCT
ON_OFF: ARRAY [1..4] OF BOOL; (*ON_OFF button*)
Set_pieces: ARRAY [1..4] OF UINT; (*Setting number of pieces*)
Act_pieces: ARRAY [1..4] OF UINT; (*Actual number of pieces*)
END_STRUCT
END_TYPE


The struct you have defined is not a data memory area. By the way it not a variable and there is no memory to be allocated.

However, after defining the structure, you can declare a variable of STRUCT type you have created.

For example:

On your programme (On you POU), make the following declarations:

VAR
Open_BUTTON: BOOL; (*Standard type*)
Close_BUTTON: BOOL; (*Standard type*)
value: UINT; (*Standard type*)
My_table: TABLE_1; (*"My_table" is now a variable of type "TABLE_1". "TABLE_1" is the struct type that you have created*)
END_VAR

You can now use on your programme the following adresses, for example:

My_table.ON_OFF[1] (*This is the name wich this variable is adressed*)
My_table.ON_OFF[2]
My_table.ON_OFF[3]
My_table.ON_OFF[4]

My_table.Set_pieces[1]
My_table.Set_pieces[2]
My_table.Set_pieces[3]
My_table.Set_pieces[4]

My_table.Act_pieces[1]
My_table.Act_pieces[2]
My_table.Act_pieces[3]
My_table.Act_pieces[4]

You can also adress the variables by the following way:

My_table.ON_OFF (*This name represents the 4 different variables of the array of BOOL*)
My_table.Set_pieces (*This name represents the 4 different variables of the array of UINT*)
My_table.Act_pieces (*This name represents the 4 different variables of the array of UINT*)

About declaring a STRUCT as DATA_BLOCK, like in siemens, I don't know what does it mean, since I am not expert in siemens.
Is it simmilar to something possible to do in Omron?

I hope this can help.
SteveMaves
QUOTE (tAotomation @ Apr 27 2009, 06:30 AM) *
hallo to everybody,
I would like to know how CoDeSys/TwinCAT systems allocates memory. When I declare VAR_CONF, for example STRUCT, it's possible that this STRUCT overwrites some other variables? How variables are addressed? By simbol or by address. I need to declare STRUCTs like a DB (DATA BLOCK) as on Siemens PLCs, is it possible??

Thanks.

PS: sorry for my bad english.


By default, TwinCAT handles all variable addressing for you, you do not need to worry about one variable "stepping on" another.

TwinCAT does allow you to specify a particular memory location, like this...
sHMIOperatorID AT %MW0: WORD;
Once you have begun to address variables by memory locations, you must excercise caution, as the compiler will give you no warnings.

For details about the Struct, see the previous reply
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.