Challenge - 5 Problems
Function Block Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediateOutput of a simple function block call
What is the output of the following function block execution?
PLC Programming
FUNCTION_BLOCK FB_Add VAR_INPUT A : INT; B : INT; END_VAR VAR_OUTPUT Sum : INT; END_VAR Sum := A + B; END_FUNCTION_BLOCK PROGRAM PLC_PRG VAR fbAddInstance : FB_Add; result : INT; END_VAR fbAddInstance(A := 3, B := 4); result := fbAddInstance.Sum;
Attempts:
2 left
💡 Hint
Remember that the function block calculates Sum as A + B.
✗ Incorrect
The function block FB_Add adds inputs A and B and stores the result in Sum. Calling fbAddInstance with A=3 and B=4 sets Sum to 7.
📝 Syntax
intermediateIdentify the syntax error in function block definition
Which option contains the correct syntax for defining a function block with one input and one output?
Attempts:
2 left
💡 Hint
Check for missing semicolons and assignment operator correctness.
✗ Incorrect
Option A correctly uses semicolons after variable declarations and uses ':=' for assignment. Other options miss semicolons or use '=' which is invalid for assignment.
🔧 Debug
advancedFind the runtime error in this function block usage
What runtime error will occur when executing this program?
PLC Programming
FUNCTION_BLOCK FB_Divide VAR_INPUT Numerator : INT; Denominator : INT; END_VAR VAR_OUTPUT Result : REAL; END_VAR IF Denominator = 0 THEN Result := -1.0; (* error code for division by zero *) ELSE Result := Numerator / Denominator; END_IF END_FUNCTION_BLOCK PROGRAM PLC_PRG VAR fbDiv : FB_Divide; output : REAL; END_VAR fbDiv(Numerator := 10, Denominator := 0); output := fbDiv.Result;
Attempts:
2 left
💡 Hint
Check how the function block handles zero denominator.
✗ Incorrect
The function block checks if Denominator is zero and sets Result to -1.0 to indicate error, avoiding division by zero runtime error.
🚀 Application
advancedDetermine the final output after multiple function block calls
Given the function block and program below, what is the value of 'finalResult' after execution?
PLC Programming
FUNCTION_BLOCK FB_Accumulator VAR_INPUT AddValue : INT; END_VAR VAR_OUTPUT Total : INT := 0; END_VAR Total := Total + AddValue; END_FUNCTION_BLOCK PROGRAM PLC_PRG VAR acc : FB_Accumulator; finalResult : INT; END_VAR acc(AddValue := 5); acc(AddValue := 3); acc(AddValue := 2); finalResult := acc.Total;
Attempts:
2 left
💡 Hint
Consider how the Total variable is initialized and updated each call.
✗ Incorrect
The Total variable is initialized to 0 once and then updated by adding AddValue each call, so after three calls Total = 5 + 3 + 2 = 10.
🧠 Conceptual
expertUnderstanding persistent state in function blocks
Which statement correctly explains how to maintain state across multiple calls of a function block in PLC programming?
Attempts:
2 left
💡 Hint
Think about where persistent data is stored inside a function block.
✗ Incorrect
Variables declared inside VAR (also called VAR or VAR_IN_OUT) inside a function block instance retain their values between calls, allowing the function block to maintain state.
