×

Subscribe to newsletter

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




PLC BLOG | codesys Arithmetic instruction
Share on Facebook Share On Twitter Share on LinkedIn Share on Whatsapp


codesys Arithmetic instruction

Arithmetic instruction such as Addition, Subtraction, Multiplication, Division, in these instruction generally have two input variable and one output variable. in addition block you can append input more than two. data type permitted in Arithmetic instruction BYTE, WORD, DWORD, LWORD, SINT, USINT, INT, UINT, DINT, UDINT, LINT, ULINT, REAL, LREAL, TIME, TIME_OF_DAY (TOD), DATE, DATE_AND_TIME(DT).
  • both input is same data type except these TOD+TIME = TOD, DT+TIME = DT.
  • you can also decalre constant value in input.


Addition ADD

this block is used for adding variables input, when EN input set to true, this block add input variables and store the result into output variable. output coil set to true when operation is complete.

codesys add Arithmetic instruction

    in this example value1 and value2 as INT data type and EN input ADD_in as bool data type. when ADD_in true signal both inputs variable value1 and value2 are added and stored in output_add (int type). output = value1 + value2.output set to true when operation addition done. if you want to add more input wright click on block and click append input.

codesys add append

Subtraction SUB

This block is used for subtracting one variables to another variable. when En is set to true Value1 is subtracted by value2 and store the result in output variable. output true if block subtraction done. Note: negative TIME values are undefined.

codesys Arithmetic Subtraction instruction

Multiplication MUL

This block is used for Multiplication of one variables to another variable. when En is set to true Value1 is Multiplied by value2 and store the result in output variable. output true if block Multiplication done.You can extend the MUL operator to additional function block inputs by append input . The number of additional function block inputs is limited.

codesys Arithmetic Multiplication instruction

Division DIV

This block is used for Division of one variables to another variable. when En is set to true Value1 is divided by value2 and store the result in output variable. output true if block Division done. to avoid a division by 0 define functions in your project with the names CheckDivByte, CheckDivWord, CheckDivDWord and CheckDivReal, you can use them to check the value of the divisor if you use the operator DIV.

codesys Arithmetic Division instruction

example of Arithmetic instruction

this example show if divisor is equal to 0 than divison (DIV) block EN input set to false and no divisonal operation done. otherwise division block perform divide value1 to value2 and store result to output.


 
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