Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 37 ยท Safety and Troubleshooting

PLC Commissioning and Good Programming Practice

Learn how to commission and maintain PLC programs: scan cycle pitfalls, structure, naming, scaling, testing with simulation, FAT and SAT, version control, with runnable C stand-ins.

Writing a PLC program is only half of the job. The program must start up on a real machine, survive years of operation and be understood by technicians who never met the author. Commissioning is the process of bringing the system to life and proving it works. Good practice is everything you do beforehand to make that process short and the result maintainable.

No PLC runtime is available on this site, so rules are shown read-only and the runnable programs are C stand-ins that model the pitfalls and a test harness.

The scan cycle and its traps

Remember the cycle: read inputs, execute the program, write outputs. Several classic bugs follow from it:

  • Double coil / multiple writes. Writing the same output bit in two places means only the last write in the scan wins. Write every bit in exactly one place.
  • Order of execution. Logic reads values computed earlier in the same scan, so moving a block changes behavior by one scan.
  • Scan-time dependence. A loop that works at 5 ms may fail at 50 ms. Do not rely on scan count for timing; use timers.
  • Long loops. A FOR loop over thousands of elements can exceed the watchdog. Spread work over several scans.
  • Edges and first scan. Check initialization (see edge detection).

This model shows the double-coil bug:

C C stand-in: the double coil problem

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Structure and naming

  • Break the program into blocks. One function block per device type (motor, valve, PID loop) and one per machine section. Reuse the same tested block many times.
  • Standard interface. Each block takes commands (Start, Stop, Reset) and returns states (Running, Fault).
  • Meaningful names. Conveyor1_RunCmd, not M0.3. Use a naming convention for prefixes and units, and comments for the "why".
  • Constants instead of magic numbers. Name limits and presets so they are visible and changeable.
  • Modes. Plan Manual, Automatic and Fault modes from the start. Manual should still respect interlocks.
  • Separate configuration from logic. Recipes, limits and presets live in data blocks that an HMI can edit, not in code.
  • Scaling once. Convert raw analog inputs to engineering units in a single input-conditioning block; see HMI scaling.

Testing before the machine exists

You can test logic without hardware. A simulation replaces I/O by variables that a script drives, and checks expected outputs. Many vendors provide simulators; the idea is the same as this C test harness, which runs a motor block through scenarios and checks the results automatically.

C C stand-in: a motor block and an automatic test harness

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Run it after every change. A catalog of such scenarios catches regressions the way unit tests do in other languages.

FAT, SAT and commissioning steps

  • FAT (Factory Acceptance Test): the machine is tested at the builder's site against a written test plan, usually with simulated or partial process.
  • SAT (Site Acceptance Test): the same on the customer's site with real process, utilities and operators.
  • Commissioning checklist:
    1. Power-off checks: wiring against drawings, insulation, earthing, supply voltages.
    2. I/O check ("point to point"): activate every sensor and actuator and confirm the right bit and the right device.
    3. Network check: all devices online with correct names and addresses.
    4. Individual device tests in manual mode: motor direction, valve travel, sensor scaling.
    5. Safety function validation, witnessed and signed.
    6. Sequence tests in automatic mode, empty first, then with product.
    7. Fault and recovery tests: pull the plug on a sensor, block a cylinder, interrupt power.
    8. Performance runs and acceptance.

Scaling and range checks are exactly where commissioning finds problems. This tiny test prints the scaled result across the input range so you can check the end points against the datasheet:

C C stand-in: check scaling end points and clamping

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with scanf or fgets), it gets the next line from this box.

Documentation and change control

  • Keep drawings, I/O lists, network plans and the function description current.
  • Use version control for source (text export formats work best) or at least dated backups with change notes.
  • Store a backup offline, and know how to restore it onto a replacement CPU.
  • Protect the program with passwords and know who holds them; log online changes.
  • Write a short operations note for maintenance: modes, alarms, what each fault means, how to restart.

When faults still occur, see troubleshooting methods. Now put it all together in a first full project: a traffic light controller.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why is writing the same output bit in two different rungs a problem?

    Each scan executes the program in order; a later write overwrites an earlier one, producing confusing behavior.
  2. 2. What is the main purpose of the SAT?

    The Site Acceptance Test proves that the installed system works in its real environment.
  3. 3. Which is a good habit?

    Single-point scaling and named constants make the program consistent and easy to change.
  4. 4. What do automated test scenarios give you?

    Re-running a catalog of scenarios after every edit shows quickly if a change broke existing behavior.

Summary

  • Know the scan-cycle traps: double coils, execution order, scan-time dependence and long loops.
  • Build with reusable blocks, clear names, constants, modes and one scaling point.
  • Test logic by simulation before the hardware exists; follow a FAT, SAT and commissioning checklist.
  • Keep drawings, backups and change records current.
  • The C programs are stand-ins illustrating pitfalls and testing.

Next: Project: Traffic Light Controller