Tips for good PLC programming

Advices for making good PLC programs, easy to debug, easy to understand, and safe to run.

  • Before you start coding you need to have a clear and documented idea of what the machine should do. Make a state machine sequential flowchart, list of the inputs, list of the outputs, list of the parameters that are used modifiable, list of the alarms.
  • Use a “state machine” program structure.
  • Divide the program in “pages” you call from the main “page” in the following order: read inputs, execute state machine, write outputs. This way you have a scan cycle that makes sense.
  • Control the outputs only in one place in the program, with direct output write (not use set or reset for outputs). If your output depends on several conditions, put them in OR /AND in the branch. This way you can quickly see who is controlling the output state.
  • Reset condition should always be placed in a branch preceding the set condition. This is particularly important for faults bits. You don’t want a fault to be discovered and then reset right after without the rest of the program to notice.
  • Never use loops. You might forget something that keeps you program in the loop forever, not executing the rest.
  • Put a condition for execution of a division than could potentially end up as a division for zero. You can do A/B only if B!=0. This is to avoid the PLC to go into the “division for zero” error and stop execution.
  • Put limits to the values inserted from the operator in configuration screens.You never know a type mistake.
  • “Download” means sending from PC to PLC
  • Use field buses (like Modbus on RS485) rather than discrete input/outputs to interact with advanced external devices (multimeters, sensors, a motor inverters). It is more safe and cheap than to use hard wired digital input/outputs.
  • Name the file with the version. Mixer_v1, Mixer_v2, Mixer_v3. For small changes call it Mixer_v2A, Mixer_v2B etc. Keep a file called _history.txt where you take a brief not of what you changed in each version.
  • Print the whole ladder program in pdf. (you never know if in 10 year your plc programming software will open and old program).

 

Any other good practice I could add to the list? drop me an email

 

Potrebbe interessarti: