×

Subscribe to newsletter

subscribe to our weekly newsletter to get notified with latest story and article Subscribe now!




PLC BLOG | codesys data type
Share on Facebook Share On Twitter Share on LinkedIn Share on Whatsapp


codesys data type

data type store value in memory space, each data type have reserved space of memory. When you define data types to a identifier, so data type reserved space for your identifier and show how values are interpreted to identifier. Each data types have lower limit and upper limit. if value above or below the data type limit than value not stored in the memory space so carefully assign data type when you make a program. in codesys plc you can use standard data types or user-defined data types. Identifier is assigned to a data type which dictates how much memory space will be reserved and what type of values it stores. for example "var1"

how to Declare Variables

data type plays an important role. you can declare variable following method.
  • declare your variable in POU.
  • DUT, GVL or NVL editor.
  • I/O mapping configuration of an I/O device object.
  • by using dialog box auto declare.

dialog box auto declare

    Syntax for the variable declaration in POUs or global variable lists
    name_of_identifier : name of the data type ;
  • var1:bool; where name_of_identifier is var1 and bool is data type
  • var2:int; where name_of_identifier is var1 and int is data type.
  • other example: motor_on: BOOL; push_button_off: BOOL; overload: BOOL; limit_switch: BOOL;
  • declaration of constant value
  • var_1:STRING(5):='admin';
    value_1:INT:=10;

variable declaration using AT keyword

    the AT keyword assigns a project variable to a specific input address, output address or memory address of the controller that is configured in the device tree. You can also define the assignment of variables to an address in the I/O Mapping dialog box of the device in the controller configuration. This declaration allows you to give an informative name to the address. You can make any necessary changes for the input or output signals at just one location, for example in the declaration.
    identifier AT address: data type;
  • for example
  • lowswitch AT %i0.0: BOOL;
    setpoint1 AT %i2: UINT;

  • If you assign a variable to an address, please note the following:
    • You cannot write to variables that are placed at inputs because this will cause compile errors.
    • You can perform AT declarations only for local and global variables, not for input/output variables of POUs.
    • AT declarations cannot be used in persistent variable lists.
    • If you use AT declarations for structure or function block components, then all instances use the same memory.


codesys Rules for identifiers of variables

  • An identifier must not contain spaces or special characters.
  • CODESYS ignores uppercase/lowercase. VAR1 and var1 indicate the same variable.
  • CODESYS recognizes underscores. For example, A_BCD and AB_CD are treated as two different identifiers
  • The length of an identifier is unlimited.
  • Multiple consecutive underscores are not permitted.
  • An identifier is not permitted to be identical to a keyword (for example, variable type).


codesys BOOL data type

bool data type have only two values either 0 or 1, 0 refers false and 1 refers true. Memory space for bool is 8 bit. bool data type used in NO, NC, coil, Boolean operator(and, or, xor, nand, nor), two states switch, push button, zss, switching devices, status of motor, sensor etc, output of comparison, timer.

BOOL data type

    in above logic for simple motor starter all contact and output coil is bool data type. push button is only two states either on or off similarly limit switch have also two states either limit switch operated or not operated if operated than value 1 otherwise value 0 so you can see bool used for true false, on or off, 0 or 1.


codesys Integer Data Types

integer data types store integer value in memory within range. when you make program so carefully assign data type integer because integer date type only store numeric value without decimal. integer data type allowed value like 8 , -98, 3422, 124 etc but not allowed value like 8.234, 9.1, -6.34. each integer data type have different range of value. BYTE, WORD, DWORD, LWORD, SINT, USINT, INT, UINT, DINT, UDINT, LINT, ULINT are all integer data types. Numeric values can be binary, octal, decimal, and hexadecimal numbers.

    in following logic 10 divided by 3 as you know result is 3.333333... but when you define division output as integer data than output is only 3 not 3.333 so its clear that integer not stored float value or real value.

BOOL data type

how to declare integer values in codesys

you can write decimal value directly. but if your value is not decimal than you can use "#" sign, before the # sign declare base of value 2 for binary, 8 for octal, 16 for hexadecimal. for example
  • decimal value : 16
  • binary number : 2#1101_0111
  • 8#34 octal number
  • 16#BCF hexadecimal
  • dint#16#cd hexadecimal with DINT data type.

integer data type used to store analog value without decimal like position, temperature, etc. Each of the different number types covers a different range of values. Following are integer data type


data type byte

byte store value within range from 0 to 255, and memory space of byte is 8 bit. considered example of byte both input and output is byte data type.

data type byte

data type word

word store value within range from 0 to 65535 and memory space is 16 bit. value below 0 and above 65535 is not allowed.

data type word

data type dword

dword range of dword is 0 to 4294967295 and memory space is 32 bit.

data type dword

data type SINT

SINT signed integer you can store positive as well as negative value within range of -128 to 127 and memory space is 8 bit.

data type USINT

usint unsigned integer you can store only positive value range fir usint is 0 to 255 and memory space is 8 bit.

data type SINT

data type INT

int range for int is -32768 to -32767 and memory space is 16 bit you can store positive and negative value with in range.

data type INT

data type UINT

UINT unsigned integer value 0 to 65535 and memory space is 16 bit you can store only positive value but not above 65535.

data type DINT

DINT double integer you can store positive and negative value within range of -2147483648 to 2147483647 and memory space is 32bit.

Data type UDINT

UDINT unsigned double integer range of value 0 to 4294967295 and memory space is 32 Bit.

data type DINT

codesys data type REAL/LREAL

REAL and LREAL store floating point (with decimal) value like 10.111, 112.98333. Floating point used in temperature sensor, pid, set point, actual position etc these value gives the good precision because They are required to represent rational numbers. for example by using REAL or LREAL data type you can show temperature value like 12.3333 °C, 1.003483 m, 4.989999 psi.
  • REAL is 32 bits and range from 1.175494351e-38 to 3.402823466e+38
  • LREAL 64 bits and range from 2.2250738585072014e-308 to 1.7976931348623158e+308.
  • 32 bits of memory space is reserved for REAL and 64 bits for LREAL.

codesys data type REAL/LREAL

codesys data type STRING

string data type store character , size declare determines how much memory space should be reserved, size(range) of string is 0 to 255. you can declare string like var_1:STRING(5):='admin';
var_string: STRING[4];
in parentheses or brackets you can declare size of string by default 80 character. for example var_string: STRING[4]; so this store only 4 character. The string length basically is not limited in CoDeSys, but string functions only can process strings of 1 to 255 characters.

codesys data type STRING

codesys data type Time

for value like time , date, date and time you can use different time data types like Time, TIME_OF_DAY, DATE, DATE_AND_TIME. These are handled internally like DWORD. so the range and memory space for time is same as DWORD. 0 to 4294967295 and memory space is 32 bit.


codesys data type time

time data type store time. time value always start with t or T with "#" sign, so time will be same as T# d:h:m:ms where d stands for days values, h stands for hour, m stands for minute, and ms stand for millisecond. Always made up of an initial "t" or "T" (or "time" or "TIME" spelled out) and a number sign "#".Please note that the time entries must be order of d:h:m:ms according to length, but you are not required to include all time increments. Maximum value: 49d17h2m47s295ms (4194967295 ms).
    example of time
  • Time1:=t#13s; time2:=T#13s; time3:=T#13ms; time4:=T#4d:3h; time5:t#9d; time5:t#9d:30ms;
  • tIME1 := t#63m67s; because limit of minute and second is exceeded
    time2:12s; because # sign missing.
    TIME1 := t#4ms13d; because order incorrect.


codesys data type : DATE

data type date store date in memory space. You can then enter any date with format Year-Month-Day. Possible values: 1970-00-00 to 2106-02-06.beginning with a "d#", "D#", "DATE#" or "date#".
    Examples of dates:
  • DATE#1996-05-06
  • d#1972-03-29

data type DATE

codesys data type : TIME_OF_DAY

data type TIME_OF_DAY store times of the day. Begin with "tod#", "TOD#", "TIME_OF_DAY#" or "time_of_day#" followed by a time with the format: Hour:Minute:Second. Seconds can be entered as real numbers or you can enter fractions of a second. Possible values: 00:00:00 to 23:59:59.999.
    Examples:
  • TIME_OF_DAY#15:36:30.123
  • tod#00:00:00

data type TIME_OF_DAY

codesys data type : DATE_AND_TIME

data type DATE_AND_TIME store combination of date and the time of day, data type date_and_time begin with "dt#", "DT#", "DATE_AND_TIME#" or "date_and_time#". Place a hyphen after the date followed by the time. Possible values declaration: 1970-00-00-00:00:00 to 2106-02-06-06:28:15.
    Examples:
  • DATE_AND_TIME#1996-05-06-15:36:30
  • dt#1972-03-29-00:00:00

data type DATE_AND_TIME
 
Share on Facebook Share On Twitter Share on LinkedIn Share on Whatsapp


Suggested Post


 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

comment