BCD type sine operation
The function calculates the sine 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#30;
(*corresponds to 30°*)
output_value: ARRAY [0..2] OF WORD:=[3(0)];
(*result after a 0->1 leading
edge from start:
[0,0,5000]*)
input_181_to_359: BOOL:=FALSE;
input_90_or_270: BOOL:=FALSE;
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 90° is assigned to the variable input_value. When the variable start is set to TRUE, the function F300_BSIN is carried out. It stores the result in the variable output_value. If the input_value is between 181° and 359°, output_value has a minus sign. The function WORD_TO_BOOL sets the variable input_181_to_359 to TRUE. With an input_value of 90° or 270°, the output_value is 1, which represents the value before the decimal point. If this is the case, then WORD_TO_BOOL sets the value of the variable input_90_or_270 to TRUE.
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#90,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 := 4 ;
NETWORK_BODY
B(B_F,F300_BSIN,,10,0,19,4,,?DEN?D@'s'?AENO?Cd);
B(B_VARIN,,input_value,8,2,10,4,);
B(B_VAROUT,,output_value,19,2,21,4,);
B(B_VARIN,,output,8,1,10,3,);
L(1,0,1,4);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 3 ;
NETWORK_BODY
B(B_VARIN,,output_value[0],8,1,10,3,);
B(B_F,WORD_TO_BOOL,,10,0,21,3,,?Da_Word?C);
B(B_VAROUT,,input_181_to_359,21,1,23,3,);
L(1,0,1,3);
END_NETWORK_BODY
END_NET_WORK
NET_WORK
NETWORK_TYPE := NWTYPELD ;
NETWORK_LABEL := ;
NETWORK_TITLE := ;
NETWORK_HEIGHT := 3 ;
NETWORK_BODY
B(B_VARIN,,output_value[1],8,1,10,3,);
B(B_F,WORD_TO_BOOL,,10,0,21,3,,?Da_Word?C);
B(B_VAROUT,,input_90_or_270,21,1,23,3,);
L(1,0,1,3);
END_NETWORK_BODY
END_NET_WORK
END_BODY
input_value:=16#90;
IF start THEN
F300_BSIN( input_value, output_value );
END_IF;
input_181_to_359:=WORD_TO_BOOL(output_value[0]);
input_90_or_270:=WORD_TO_BOOL(output_value[1]);