Monday, February 7, 2011

Understanding Array Concept


Array:  a numerically indexed sequence of elements of the dame data type. An array tag occupies a continguous section of memory in the controller with each element in sequence. Array can have one, two or three dimensions.
Element : a single position within an array.
The elements in the array occupy memory in order. The array always start at 0 and extend to the numberof elements minus 1
an array in the tag windows is shown in the following graphic

An array must be created with the following rules in the mind:
  • An array can have up to three dimensions unless it is a part of a structure, where then it can have only  one dimensions.
  • An array can be of one data type only. Array support the following data type:
o   Any pre-defined data type except axis data type, Message, or motion_group.
o   A user-defined data type.
Note:
Data of the same type is not automatically grouped in memory. To store all timers together, create of timer tags.

Array Storage
Array can have up to three dimentions and store data in the following manner:
 

Note:
 A tag uses a DINT (32 bits) even if it is smaller (8 bits). To converse data, put 32 bits, four SINTs, or two INTs  into an array.

Array Addressing
In array, the following can be addressed:
  •  A numeric element (Fixed)
  • A variable element
  •   A numeric bit
  •  A variable bit
Numeric element addressing
To access a specifiec array element (e.g.,one DINT in array of DINTs), uses the following addres format:
  Array name[Element Number]
       PartData[3]

 Note:
This reference is fixed because the element value of 3 will not change


Variable Element Addressing
to change the array element that your logic referenge, use atag or expresion to point to the element, using the following address format:
Array name[tag or expression]
                Part[seralnumber]
                Part[serialnumber*5]
                Parrt[pos1-pos2]
You can use an mathematical operators in an expression to specify an array element
Note:
Important: any array value that you enter must be within the boundaries of the specified array. Instraction that  view arrays as a collection of element generate a major fault if a value exceeds its corresponding dimension.
Numeric bit addressing.
A bit within one element of an array can be addressed using the following address format:
Arrayname[element number].Bit
                Part[1].2
Mix_Timer[5].Dn
Variable Bit addressing
To dinamically change the valueof a bit, use the following address format:
Arrayname[element numbert].[tag or expression]
                Part[serialmunber].[position1-position2]
Array addressing summary
The following tabel present a summary of the array address types, formats, and example:

Type Format Example
Numeric Element ArrayName[ElementNumber] Part[5]
Variable Element ArrayName[Tag]

ArrayName[Expression]
Station[Position]

Station[position*5]
Numeric bit ArrayName[Element].bit Part[5].15
Variable Bit ArrayName[ElementNumber].[Tag]

ArrayName[ElementNumber].[Expression]
Parrt[indexAND7].[Myindex]

Part[indexAND7].[Myindex+32]

No comments:

Post a Comment