BCD type cosine operation
The function calculates the cosine of BCD code angular data (input s) and stores the result (output d) as a BCD value in an array with three elements.
Input
16-bit area where angle data is stored
Output
Result stored in 3 words
BCD values for input s lie in the area from 0° to 360° (16#0 to 16#360) in 1° steps. With this output d can yield a result in the range of -1.0000 to 1.0000. The result is returned as follows:
preceding sign (0 when input is +, 1 when input is -)
whole number before the decimal point (0 or 1)
numbers after the decimal point with 4 significant figures as a BCD value (16#0000 to 16#9999).
if s is not a BCD value
if s is not between 0° and 360°.
if s is not a BCD value
if s is not between 0° and 360°.
if the result is 0.
if the result is overflowed.
All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.
VAR
start: BOOL:=FALSE;
(*activates the function*)
input_value: WORD:=16#60;
(*corresponds to 60°*)
output_value: ARRAY [0..2] OF WORD:=[3(0)];
(*result after a 0->1 leading
edge from start:
[0,1,7321]*)
END_VAR
In this example, the input variable input_value is declared. However, you can write a constant (e.g. 16#45 for 45°) directly at the input contact of the function.
In the body, the value 16#45° is assigned to the variable input_value. When the variable start is set to TRUE, the function is carried out. The result at output d is output_value[0] = 0, output_value[1] = 0, output_value[2] = 7071.
BODY
WORKSPACE
NETWORK_LIST_TYPE := NWTYPELD ;
ACTIVE_NETWORK := 0 ;
END_WORKSPACE
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 3 ;
NETWORK_BODY
B(B_VARIN,,16#45,8,0,10,2,);
B(B_VAROUT,,input_value,10,0,12,2,);
L(1,0,1,3);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 6 ;
NETWORK_BODY
B(B_VARIN,,output,7,1,9,3,);
B(B_VARIN,,input_value,7,2,9,4,);
B(B_VAROUT,,output_value,18,2,20,4,);
B(B_F,F301_BCOS,,9,0,18,4,,?DEN?D@'s'?AENO?Cd);
B(B_COMMENT,,output_value[0] = 1ø^if input_valueø^between 91° and 269°,26,0,38,3,);
B(B_COMMENT,,output_value[1] = 1ø^if input_valueø^0° or 180°,26,3,38,6,);
L(1,0,1,6);
END_NETWORK_BODY
END_NET_WORK
END_BODY
input_value:=16#45;
IF start THEN
F301_BCOS( input_value, output_value );
END_IF;