F302_BTAN

BCD type tangent operation

The function calculates the tangent of BCD code angular data (input s) and stores the result (output d) as a BCD value in an array with three elements.

Parameters

Input

s (WORD)

Area where angle data is stored

Output

d (ARRAY [0..2] of WORD)

Result stored in 3 words

Remarks

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 yields a result in the range of -57.2900 to 57.2900. The result is returned as follows:

ARRAY[0]

preceding sign (0 when input is +, 1 when input is -)

ARRAY[1]

whole number before the decimal point (0 or 1)

ARRAY[2]

numbers after the decimal point with 4 significant figures as a BCD value (16#0000 to 16#9999).

Error flags

sys_bIsOperationErrorHold (turns to TRUE and remains TRUE)
  • if s is not a BCD value

  • if s is not between 0° and 360°.

sys_bIsOperationErrorNonHold (turns to TRUE for one scan)
  • if s is not a BCD value

  • if s is not between 0° and 360°.

sys_bIsEqual (turns to TRUE and remains TRUE)

if the result is 0.

sys_bIsCarry (turns to TRUE for one scan)

if the result is overflowed.

Example

POU header

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: ARRAY [0..2] OF WORD:=[2(0),16#5000];
			(*corresponds to 0.5*)
		output_value: WORD:=0;
			(*result after a 0->1 leading
edge from start: 16#30
corresponds to 30°*)
	END_VAR

In this example, the input variable input_value is declared. However, you can write a constant (e.g. 16#89 for 89°) directly at the input contact of the function.

LD body

When the variable start is set to TRUE, the function is carried out. The input_value was initialized with the value 16#89 (89°) in the POU header. The result is written to the ARRAY output_value. Here in the first element of the ARRAY, the output_value = 16# (+ sign). In the second element, 16#57 represents the number before the decimal point, and 16#2899 comes after the decimal point in the third element.

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 14 ;
        NETWORK_BODY
B(B_VARIN,,output,6,1,8,3,);
B(B_VARIN,,input_value,6,2,8,4,);
B(B_VAROUT,,output_value,17,2,19,4,);
B(B_F,F302_BTAN,,8,0,17,4,,?DEN?D@'s'?AENO?Cd);
B(B_COMMENT,,output_value undefinedø^if input_valueø^90° or 270°,25,0,37,3,);
B(B_COMMENT,,output_value[0] = 1ø^if input_valueø^between 91° and 179° orø^between 271° and 359°,25,3,37,7,);
L(1,0,1,14);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

ST body

IF start THEN         
    F302_BTAN(input_value, output_value);
END_IF;

IL body

Modified on: 2019-01-24Feedback on this pagePanasonic hotline