10.14 MATH FUNCTIONS
These functions use values in memory, and store the results back in memory (Note: these functions do not use variables like normal programming languages.)
Math functions are quite similar. The following example adds the integer and floating point number and puts the results in `F8:36'.
Basic PLC-5 math functions include,
ADD(value,value,destination) - add two values
SUB(value,value,destination) - subtract
MUL(value,value,destination) - multiply
DIV(value,value,destination) - divide
NEG(value,destination) - reverse sign from positive/negative
CLR(value) - clear the memory location
Consider the example below,
As an exercise, try the calculation below with ladder logic,
Some intermediate math functions include,
CPT(destination,expression) - does a calculation
ACS(value,destination) - inverse cosine
COS(value,destination) - cosine
ASN(value,destination) - inverse sine
SIN(value,destination) - sine
ATN(value,destination) - inverse tangent
TAN(value,destination) - tangent
XPY(value,value,destination) - X to the power of Y
LN(value,destination) - natural log
LOG(value,destination) - base 10 log
SQR(value,destination) - square root
Examples of some of these functions are given below.
For practice implement the following function,
Some functions are well suited to statistics.
AVE(start value,destination,control,length) - average of values
STD(start value,destination,control,length) - standard deviation of values
SRT(start value,control,length) - sort a list of values
Examples of these functions are given below.
There are also functions for basic data conversion.
TOD(value,destination) - convert from BCD to binary
FRD(value,destination) - convert from binary to BCD
DEG(value,destination) - convert from radians to degrees
RAD(value,destination) - convert from degrees to radians
Examples of these functions are given below.