brands · South Africa
GX Works3 Function Blocks: Instances, State and Worked Tests
Learn GX Works3 function blocks with clear instance ownership, label classes, reset rules, negative-value tests and practical Mitsubishi PLC course checks.

GX Works3 function blocks let you reuse a definition while keeping state for particular instances. For a learner, the decisive question is not simply whether a block compiles: it is whether each machine object owns the intended memory, receives the intended inputs and follows a tested reset policy. A beautifully named block can still produce the wrong answer if two independent channels share an instance.
This guide covers a practical learning route for Mitsubishi Electric users in South Africa. It separates documented GX Works3 and FX5 concepts from a deliberately small classroom exercise. It does not claim that a browser learning environment opens native Mitsubishi projects or reproduces every controller instruction. Start with the Mitsubishi PLC training overview if you still need to choose a platform or course.
What is an FB, and how is it different from a function?
A function block has a reusable definition and instantiated data. The definition describes the behaviour; an instance gives that behaviour a particular identity and state. Two temperature channels can therefore use the same design while remembering different histories. An ordinary calculation that only transforms its current arguments may be better expressed as a function. The function versus function-block comparison develops that design choice with other examples.
Mitsubishi's FX5 Program Design manual, section 3.3 documents these interface classes: VAR_INPUT, VAR_OUTPUT, VAR_OUTPUT_RETAIN and VAR_IN_OUT. It lists VAR, VAR_CONSTANT and VAR_RETAIN for internal variables. Instances can be declared through global or local labels. Different instances have separate internal variables; repeated use of the same instance shares those variables. These are FX5 documentation statements, not a substitute for checking the manual for another CPU family.
Do not equate memory between calls with guaranteed retention through every restart, download or power interruption. Those are different requirements. A course should make the learner state which event is being tested and what the configured controller is expected to do. The phrase “the FB remembers” is too vague to serve as a commissioning requirement.
A grounded GX Works3 workflow
The GX Works3 Operating Manual, section 10.1 describes creating FB data through the New Data screen, registering labels, creating the body and inserting a call into a sequence programme. Its navigation paths include FB/FUN → file → FB → Local Label and the corresponding ProgramBody. It also distinguishes macro and subroutine types. Available choices depend on the target.
The same section warns that EN control settings affect behaviour: using MC/MCR can reset outputs and current timer values when the FB is not executed; without that mechanism, current values are retained in the described case. Consequently, “a disabled block always freezes everything” is not a reliable universal rule. Record the actual properties and consult the applicable CPU manual before testing enable behaviour.
Use the documented workflow as a starting point, then write down your installed software version and exact controller selection. A screenshot of one editor does not establish every language option for every FB type. Avoid copying another vendor's contact mnemonics, temporary-variable declarations or address syntax into a Mitsubishi tutorial merely because the concepts look similar. If your project uses labels, explain their mapping separately from the reusable algorithm.
A useful first submission contains the FB definition, its declared interface, two clearly named instances and the calling programme. It also contains the intended execution order. An isolated block screenshot omits the very information needed to diagnose shared-state and call-order mistakes.

Define the contract before writing ladder or Structured Text
The following running-maximum exercise is fictional and deliberately independent of a particular GX Works3 release. It is a learning specification, not a ready-to-download native project. Its purpose is to expose instance ownership, negative-number initialization and reset priority without needing a motor, network or analogue module.
Each instance tracks the greatest accepted sample since its last reset. Inputs are Reset, SampleValid and Sample. For this exercise, Sample must be an integer from minus 100 through 100 inclusive when SampleValid is true. Outputs are HasSample and Maximum. Maximum is meaningful only when HasSample is true. An implementation may store zero while HasSample is false, but that zero does not represent an accepted measurement.
The rules are:
- Reset has priority. A call with Reset true clears HasSample and stores zero, even if a valid sample arrives in that same call.
- With Reset false, an accepted first sample sets Maximum to that sample and HasSample to true.
- A later accepted sample changes Maximum only when it is larger than the stored value.
- Invalid or absent samples leave the existing pair unchanged.
- Each independent channel owns a separate instance. The calling order is recorded, even when the instances do not interact.
These choices are not universal process requirements. For example, a different application might accept a sample in the reset call. It would need a different specification and expected results. The useful habit is to make the choice explicit before arguing about which rung should appear first.
Why initializing the maximum to zero is insufficient
Suppose the first three accepted values are minus 12, minus 8 and minus 15. The correct running maxima are minus 12, minus 8 and minus 8. A naive implementation that starts at zero and only accepts larger values reports zero for all three calls. Zero looks tidy on a screen, but no zero was measured.
HasSample solves a semantic problem, not just a display problem. It distinguishes “we have no accepted observation” from “the maximum accepted observation equals zero.” Without that distinction, an operator or downstream calculation cannot tell an empty history from a real result. Compare this with the data-quality questions in the GOT2000 screen-design guide.
A second mistake is to reject negative values because the author only tested positive samples. Our declared range includes them. A third is to silently convert a decimal such as 12.5 to an integer. The exercise rejects that input; a different rounding policy would need to be written and tested. Use the PLC data-conversion reference when you need to separate storage type, conversion and engineering meaning.
The exercise has no units because it is testing an algorithm. If you turn it into a temperature or pressure example, add units, scaling and sensor-quality rules before presenting it as that measurement application. A correct integer maximum does not establish a correct analogue measurement chain.
Work through two independent instances
Create conceptual instances ChannelA and ChannelB. Both begin with HasSample false and stored Maximum zero. Feed A the values minus 12, minus 8 and minus 15. Feed B the values 20, 18 and 25. All six samples are valid and no reset occurs. Call A and then B in each round.
| Round | A sample | A result | B sample | B result |
|---|---|---|---|---|
| 1 | -12 | HasSample true; Maximum -12 | 20 | HasSample true; Maximum 20 |
| 2 | -8 | HasSample true; Maximum -8 | 18 | HasSample true; Maximum 20 |
| 3 | -15 | HasSample true; Maximum -8 | 25 | HasSample true; Maximum 25 |
The same definition supports different histories. Changing B's input does not change A's maximum. That independence is the property you want to demonstrate, rather than merely pointing to two block graphics on the screen.
Now deliberately route both channels through one conceptual instance called Shared. After A's first call its maximum is minus 12. After B's first call it becomes 20. A's next sample, minus 8, cannot exceed that shared 20, so the result observed after A's call is 20. B's history has contaminated the answer intended for A.
Do not rely on an invented rule that the compiler must reject every repeated instance call. The documented shared-memory behaviour is precisely why the calling arrangement deserves review. A syntactically valid project can represent the wrong ownership design. Record observations immediately after each call; a watch taken only at the end of the cycle may conceal the intermediate mistake.

Test reset priority and missing samples
Continue from A's maximum of minus 8. First call A with Reset true, SampleValid true and Sample 50. The specified result is HasSample false with stored Maximum zero. The sample is not accepted because reset wins. On the following call, use Reset false and a valid sample of minus 30. The result becomes HasSample true and Maximum minus 30.
This catches two common defects. If the reset and sample-processing branches run independently, the first call may immediately replace the cleared state with 50. If the programmer clears only Maximum while leaving HasSample true, the later negative sample may never become the maximum. Checking only the displayed number after reset misses that second fault.
Next present an invalid sample whose numeric field contains 90. With SampleValid false, the result remains minus 30. Then present an accepted sample of zero: the result becomes zero with HasSample still true. The two cases show why a numeric field alone cannot decide whether data should influence state.
For the classroom model, an absent sample, 101, minus 101 and 12.5 are also invalid and leave the state unchanged. Both endpoints, minus 100 and 100, are valid. The model deliberately has no diagnostic counter or alarm output; adding either would change the interface and require extra expected results. Do not report those unimplemented features as part of the successful test.
Express the algorithm without pretending it is a native project
The pseudocode below describes the exercise. The labels and syntax are illustrative; declare suitable native types and implement the logic in the chosen GX Works3 editor before treating it as a controller test.
on an explicit call to one instance:
if Reset:
HasSample = false
Maximum = 0
else if SampleValid and Sample is an integer in [-100, 100]:
if not HasSample:
Maximum = Sample
HasSample = true
else if Sample > Maximum:
Maximum = Sample
There is intentionally no else branch that wipes out a previously accepted maximum. An invalid new sample should not erase a useful earlier result under this contract. Likewise, equal accepted values preserve the same maximum. If your implementation also stores a timestamp or sample count, equality may affect those other fields; the current exercise makes no such claim.
An explicit call is the unit of this model. It does not model a particular native EN property, timer behaviour or task interruption. When moving into GX Works3, test those separately using the actual block configuration. This separation keeps a useful paper exercise from becoming misleading vendor advice.
Review the code by tracing each branch against a sentence in the contract. A branch with no requirement may be accidental functionality. A requirement with no branch or test may be an omission. This is more productive than counting rungs or assuming that a shorter solution is automatically easier to maintain.

A practical course assessment for South African learners
If you are comparing Mitsubishi PLC courses in Johannesburg, Pretoria, Cape Town, Durban, Bloemfontein or Gqeberha, ask for a learner task that includes two instances and a deliberate fault. The venue name alone says nothing about whether the course teaches reusable stateful logic. Ask which CPU family, GX Works3 version and licensed learning setup the class actually uses.
A suitable assessment can begin with the running-maximum contract and give each learner different sample sequences. Require the learner to predict the results before opening the editor. Then ask them to implement the block, demonstrate independence, introduce a shared-instance mistake and explain the evidence that revealed it. Changing one sample should require reasoning, not copying the instructor's watch values.
For beginners, the South African PLC course requirements guide helps identify preparation needs. Boolean logic, comparisons, label types and a clear understanding of programme execution are useful foundations. Someone who can reproduce a diagram may still need help explaining the difference between a definition, an instance and a call site.
For working technicians, request a separate discussion of the employer's installed platform and change procedures. A classroom exercise does not establish permission to download to a production controller. Nor does it prove competence with a particular machine's electrical design, safety functions or network. Those are concrete scope questions for the course and workplace, rather than reasons to inflate a basic FB lesson into a complete engineering qualification.
What to record when debugging an FB
Start with identity: project revision, CPU selection, software version, definition name, instance name and call location. Then record the input values at the call and the relevant state immediately before and after it. “The maximum is wrong” becomes much easier to investigate when the trace shows that another call changed the same instance earlier in the cycle.
Check initialization and reset separately. A deliberate reset is not necessarily equivalent to a controller restart, and reopening a monitor is not a reset at all. If a test begins with old state, state that fact. Repeating a sequence without restoring its starting conditions can produce a different correct result and look like an intermittent bug.
For conditional execution, identify whether the call was executed, which enable mechanism was used and where the observed output came from. Do not describe an old displayed value as proof that the function block ran. A downstream assignment or another writer can complicate the observation; review the programme structure before changing the calculation.
Keep the PLC troubleshooting guide nearby for a broader evidence sequence. In this exercise, start with ownership and accepted inputs before investigating hardware that the model does not contain. That order saves time and keeps a software-history problem from being mislabelled as an analogue sensor fault.

Questions learners ask about GX Works3 function blocks
Can two machines use the same function-block definition?
Yes, reuse is the purpose of the definition. Give independently remembered machine states their intended instances, then test independence. Two drawings that reference one instance do not create two independent histories. If shared state is intentional, describe the ownership and call order explicitly so that another programmer can understand it.
Why does my FB keep an old value?
First determine whether that value is supposed to persist under the requirement. Then check whether the relevant call executed, whether a sample was accepted and whether another call used the same instance. Examine the actual enable and retention settings before treating the behaviour as a software defect. In the running-maximum exercise, a smaller valid sample correctly leaves the old maximum unchanged.
Does VAR automatically mean power-failure retention?
Do not make that assumption. Memory during repeated calls, configured retention and behaviour during restart or download are separate questions. Specify the exact event and validate the selected controller's documented behaviour. An ordinary online observation does not test what happens after a power interruption.
Can I learn the algorithm before buying Mitsubishi hardware?
You can practise the contract, trace tables, Boolean conditions and state ownership without a physical controller. Native project creation, instruction support, CPU configuration and hardware interaction need suitable Mitsubishi tools and equipment. This site is commercially connected with PLC Simulation Software; its Structured Text learning resources can support general reasoning, but do not establish native GX Works3 project compatibility.
Is a successful compile enough for an assessment?
No. Compilation can identify certain syntax and type problems, but it cannot infer your intended ownership contract from an ambiguous design. Demonstrate negative first samples, independent instances, shared-state contamination, reset priority and invalid-input handling. Include the expected answer and the observed answer for each case, including failures you corrected.
Should I choose a GX Works3 course or a general PLC course first?
Choose according to the task you need to perform. General logic study can prepare you for state and testing concepts. A GX Works3 course should additionally cover the actual editor, target configuration and native workflow you need. Compare the complete learning scope and access costs using the South African PLC course price guide, rather than assuming a longer course title guarantees more individual practice.
Build a small, defensible portfolio submission
Submit the written contract, interface description, instance map and test table together. Include the all-negative sequence because it exposes a defect that a positive-only demonstration misses. Include the shared-instance experiment because it shows you understand why separate instances matter. Mark illustrative pseudocode, native simulator observations and any hardware observations distinctly.
For a revision exercise, change reset policy so that a valid sample is accepted in the same call as reset. Predict which expected results change, implement the new policy and rerun the affected cases. Keep both requirement versions. This demonstrates that testing follows an agreed behaviour, rather than rewarding a fixed output regardless of the current specification.
The PLC programme testing resources offer a relevant next step for systematic practice. Training departments can use the training-centre evaluation guide to compare learner access and assessment requirements. Neither link turns this exercise into an accredited qualification or a verified native Mitsubishi implementation.
A strong final explanation is concise: each independent channel owns its state; a first negative value is accepted; reset priority is explicit; invalid samples preserve the previous accepted result; and the submitted evidence identifies where those claims were tested. Those are useful skills to carry into larger reusable blocks, long after the first editor walkthrough is forgotten.
