Plc fdb programming

 PLC FDB (Function Data Block) is a programming language used in programmable logic controllers (PLCs) to create reusable blocks of code that can be called from other programs. FDBs are essentially subroutines or functions that allow programmers to write code more efficiently and reduce redundancy.


FDBs are made up of inputs, outputs, and internal memory locations. Inputs are data points that are fed into the function block from other programs or sensors, while outputs are data points that are sent out of the function block to other programs or actuators. Internal memory locations are used to store temporary values or calculations within the function block.


Here is an example of an FDB written in the Siemens TIA Portal software:


css

Copy code

FUNCTION_BLOCK MyFunctionBlock

VAR_INPUT

   Input1 : INT;

   Input2 : REAL;

END_VAR

VAR_OUTPUT

   Output1 : BOOL;

   Output2 : DINT;

END_VAR

VAR

   TempVal : REAL;

END_VAR

BEGIN

   // Perform some calculations

   TempVal := Input1 * Input2;


   // Set output values

   IF TempVal > 100 THEN

      Output1 := TRUE;

   ELSE

      Output1 := FALSE;

   END_IF


   Output2 := INT_TO_DINT(TempVal);

END_FUNCTION_BLOCK

In this example, the FDB is called MyFunctionBlock and has two inputs (Input1 and Input2) and two outputs (Output1 and Output2). The internal variable TempVal is used to store the result of a calculation, which is then used to set the output values.


The calculation performed in this FDB is TempVal := Input1 * Input2, which multiplies Input1 by Input2 and stores the result in TempVal.


The output values are then set based on the value of TempVal. If TempVal is greater than 100, Output1 is set to TRUE. Otherwise, Output1 is set to FALSE. Output2 is set to the integer value of TempVal, converted using the INT_TO_DINT function.


This FDB could be called from another program by passing in values for Input1 and Input2 and receiving the values of Output1 and Output2 as a result

Comments

Popular Posts