Bird
Raised Fist0
PLC Programmingscripting~20 mins

Function block instances in PLC Programming - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Function Block Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of multiple function block instances
Consider a PLC program where two instances of a function block Counter are used. Each instance counts independently. What will be the output values of Counter1.CV and Counter2.CV after the following code runs?
PLC Programming
FUNCTION_BLOCK Counter
VAR
  CV : INT := 0; // Current value
END_VAR
METHOD Increment
  CV := CV + 1;
END_METHOD
END_FUNCTION_BLOCK

PROGRAM PLC_PRG
VAR
  Counter1 : Counter;
  Counter2 : Counter;
END_VAR

Counter1.Increment();
Counter1.Increment();
Counter2.Increment();
ACounter1.CV = 1, Counter2.CV = 0
BCounter1.CV = 2, Counter2.CV = 1
CCounter1.CV = 2, Counter2.CV = 2
DCounter1.CV = 1, Counter2.CV = 1
Attempts:
2 left
💡 Hint
Each function block instance maintains its own state independently.
🧠 Conceptual
intermediate
1:30remaining
Understanding instance data in function blocks
Why do function block instances in PLC programming maintain separate data for each instance?
ABecause each instance has its own memory area to store variables, allowing independent operation.
BBecause function blocks do not have variables.
CBecause all instances share the same data to save memory.
DBecause instances are only copies of the code without data.
Attempts:
2 left
💡 Hint
Think about how multiple devices or sensors might be controlled independently.
🔧 Debug
advanced
2:00remaining
Identify the error in function block instance usage
What error will occur when running this PLC code snippet?
PLC Programming
FUNCTION_BLOCK Timer
VAR
  TimeElapsed : TIME := T#0s;
END_VAR
METHOD Start
  TimeElapsed := TimeElapsed + T#1s;
END_METHOD
END_FUNCTION_BLOCK

PROGRAM PLC_PRG
VAR
  Timer1 : Timer;
END_VAR

Timer1.Start();
Timer2.Start();
ASyntax error: Missing semicolon after Timer1.Start()
BRuntime error: Null reference to Timer2
CNo error, both timers start correctly
DCompilation error: 'Timer2' is not declared
Attempts:
2 left
💡 Hint
Check variable declarations before usage.
🚀 Application
advanced
2:30remaining
Using multiple function block instances for independent control
You want to control two independent motors using the same function block MotorControl. Which code snippet correctly creates two independent instances and starts both motors?
A
VAR
  Motor1 : MotorControl;
END_VAR
Motor1.Start();
Motor2.Start();
B
VAR
  Motor : MotorControl;
END_VAR
Motor.Start();
Motor.Start();
C
VAR
  Motor1, Motor2 : MotorControl;
END_VAR
Motor1.Start();
Motor2.Start();
D
VAR
  Motor1, Motor2 : MotorControl;
END_VAR
Motor1.Start();
Motor1.Start();
Attempts:
2 left
💡 Hint
Each motor needs its own instance to operate independently.
📝 Syntax
expert
2:30remaining
Correct syntax for declaring and using function block instances
Which option shows the correct syntax to declare two instances of a function block FB_Process and call their Execute method?
A
VAR
  Proc1 : FB_Process;
  Proc2 : FB_Process;
END_VAR
Proc1.Execute();
Proc2.Execute();
B
VAR
  Proc1 : FB_Process();
  Proc2 : FB_Process();
END_VAR
Proc1.Execute();
Proc2.Execute();
C
VAR
  Proc1, Proc2 : FB_Process();
END_VAR
Proc1.Execute();
Proc2.Execute();
D
VAR
  Proc1, Proc2 : FB_Process;
END_VAR
Proc1.Execute();
Proc2.Execute();
Attempts:
2 left
💡 Hint
Function block instances are declared without parentheses.

Practice

(1/5)
1. What is the main purpose of using function block instances in PLC programming?
easy
A. To reuse code with separate memory for each instance
B. To write code that runs only once
C. To combine multiple programs into one file
D. To create global variables accessible everywhere

Solution

  1. Step 1: Understand function block instances

    Function block instances allow you to reuse the same code but keep data separate for each instance.
  2. Step 2: Compare options

    Only To reuse code with separate memory for each instance correctly describes this purpose. Other options describe unrelated concepts.
  3. Final Answer:

    To reuse code with separate memory for each instance -> Option A
  4. Quick Check:

    Function block instances = separate memory reuse [OK]
Hint: Think: same code, different data for each instance [OK]
Common Mistakes:
  • Confusing instances with global variables
  • Thinking instances run only once
  • Mixing instances with program files
2. Which of the following is the correct syntax to declare two separate instances of a function block named TimerFB in IEC 61131-3 style?
easy
A. Timer1 -> TimerFB; Timer2 -> TimerFB;
B. Timer1 : TimerFB; Timer2 : TimerFB;
C. Timer1 = TimerFB(); Timer2 = TimerFB();
D. Timer1 : TimerFB() Timer2 : TimerFB()

Solution

  1. Step 1: Recall IEC 61131-3 instance declaration

    Instances are declared with name : FunctionBlockName; syntax.
  2. Step 2: Check options

    Timer1 : TimerFB; Timer2 : TimerFB; uses correct syntax with semicolons. Others use invalid or incorrect syntax.
  3. Final Answer:

    Timer1 : TimerFB; Timer2 : TimerFB; -> Option B
  4. Quick Check:

    Instance declaration uses colon and semicolon [OK]
Hint: Use colon and semicolon to declare instances [OK]
Common Mistakes:
  • Using equal sign instead of colon
  • Omitting semicolons
  • Adding parentheses after function block name
3. Given the following code snippet in a PLC program:
Timer1 : TimerFB;
Timer2 : TimerFB;

Timer1(IN := TRUE);
Timer2(IN := FALSE);

// After one cycle, what is the state of Timer1.Q and Timer2.Q?
medium
A. Timer1.Q = TRUE, Timer2.Q = FALSE
B. Timer1.Q = FALSE, Timer2.Q = TRUE
C. Timer1.Q = TRUE, Timer2.Q = TRUE
D. Timer1.Q = FALSE, Timer2.Q = FALSE

Solution

  1. Step 1: Understand instance independence

    Timer1 and Timer2 are separate instances with their own inputs and outputs.
  2. Step 2: Analyze input signals

    Timer1.IN is TRUE, so Timer1.Q will become TRUE after timing. Timer2.IN is FALSE, so Timer2.Q remains FALSE.
  3. Final Answer:

    Timer1.Q = TRUE, Timer2.Q = FALSE -> Option A
  4. Quick Check:

    Separate instances keep outputs independent [OK]
Hint: Each instance acts independently with its own inputs [OK]
Common Mistakes:
  • Assuming outputs share state between instances
  • Confusing input signals for both instances
  • Ignoring instance separation
4. Identify the error in this function block instance declaration:
Timer1 : TimerFB
Timer2 : TimerFB;
medium
A. Incorrect function block name
B. Extra semicolon after Timer2 declaration
C. Using colon instead of equal sign
D. Missing semicolon after Timer1 declaration

Solution

  1. Step 1: Check syntax for instance declarations

    Each instance declaration must end with a semicolon.
  2. Step 2: Locate the missing semicolon

    Timer1 declaration lacks a semicolon at the end, causing syntax error.
  3. Final Answer:

    Missing semicolon after Timer1 declaration -> Option D
  4. Quick Check:

    Each declaration ends with semicolon [OK]
Hint: Always end instance declarations with semicolon [OK]
Common Mistakes:
  • Omitting semicolon after each instance
  • Confusing colon with equal sign
  • Assuming semicolon is optional
5. You want to control three independent motors using the same function block MotorControlFB. Which approach correctly uses function block instances to achieve this?
hard
A. Create three copies of MotorControlFB code with different names
B. Declare one instance MotorControlFB and call it three times with different inputs
C. Declare three instances: Motor1, Motor2, Motor3 of MotorControlFB and call each separately
D. Use global variables inside MotorControlFB to handle all three motors

Solution

  1. Step 1: Understand instance independence for multiple devices

    Each motor needs its own instance to keep control data separate.
  2. Step 2: Evaluate options

    Declare three instances: Motor1, Motor2, Motor3 of MotorControlFB and call each separately declares three separate instances, allowing independent control. Declare one instance MotorControlFB and call it three times with different inputs reuses one instance incorrectly. Use global variables inside MotorControlFB to handle all three motors uses globals, which mixes data. Create three copies of MotorControlFB code with different names duplicates code, which is inefficient.
  3. Final Answer:

    Declare three instances: Motor1, Motor2, Motor3 of MotorControlFB and call each separately -> Option C
  4. Quick Check:

    Multiple devices = multiple instances [OK]
Hint: One instance per device keeps data separate [OK]
Common Mistakes:
  • Trying to reuse one instance for multiple devices
  • Using global variables inside function block
  • Copy-pasting code instead of using instances
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard