Programming a PLC: Working Principle and How to Write Ladder Diagrams With GX Developer.

dvrvsimi
11 min readApr 2, 2023

--

Hello there and welcome to the second part of this 3-part series!
*drum rolls and applauses*

If you’re reading this immediately after the first part, I suggest you take a quick recess before starting this one because it promises to be packed! If you’re new here, you should check the first article here before you begin.

Brief recap

Part I was a beginner’s guide to PLCs and their anatomy. It started with an introduction to the meaning of a PLC, we also learned about its types based on certain classifications and wrapped it all up by discussing its major units and their respective components concerning a reference PLC- the FX 20MR, the working principle of a PLC was also briefly discussed to give a little insight to this part(Part II).

How a PLC works.

It is worth mentioning that although every unit in the PLC requires codependency among each other for optimum functionality, the Processing and Programming units are the backbone of the PLC.

The Power unit is usually referred to as the active unit and is often regarded as the most important part but a powered and nonfunctional tool is as good as useless.

This article would generally be focused on the “backbones” because they make the PLC useful, we would continue learning based on a conclusion that power and other necessary factors are constantly available unless stated otherwise.

The diagram above shows the complete workflow of a PLC but we would need to talk a little about pin configuration to fully understand how the I/O unit communicates with the Processing Unit. Most sensors use a 3-pin configuration, these 3 pins include GND (ground), VCC (voltage common collector), and SIG (signal). Note that the SNG pin is also denoted as the DOUT or AOT (Data Out or Analog Out) pin on sensors and DIN or AIN(Data In Analog In) on output devices.

A 4-pin configuration is usually found on devices that need more thermal capacity on the GND pin, the fourth pin is called an NC (no-connect) pin, it has no internal connection and no external function.

Also, remember that there is no standard way to design which pin comes first, this is why it is important to check the markings on the sensor or look up the configuration sheets online while connecting. Read what engineers are saying about their preferences on this forum.

A photosensor with a 3-pin configuration and a 4-pin DHT11 sensor that has been modified to 3-pin

VCC is where the power enters the sensor, the GND is like every other ground terminal has zero voltage, and allows current flow back into the loop, while the SIG pin is for communication between the sensor and the microcontroller.

Things to note:

  • All SIG pins are connected to either the input side(X0 to X13) or the output side (Y0 to Y7) depending on if it is a DOUT or DIN pin.
  • All VCC pins draw power from the 0V DC *output regardless of whether it is a controller or a controlled device.
  • Naturally, all GND pins are connected to the 24V DC *input.
    *Remember that both output and input above are defined with respect to the Power Unit and it’s best not to confuse them, Refer to the “Power Unit” section in part 1 for clarification.

The image below gives a more detailed explanation of its wiring, see that C4 and C5 serve Y4, Y5 and Y6, Y7 respectfully, this compensates for the lack of enough C points without jeopardizing the function and keeping it compact at the same time.

How a PLC works (Cont’d).

The “NC contact” that terminates at their corresponding C points (C0 to C5) are also connected at 0V, they are critical because a PLC controls the state of the output devices (either ON or OFF state), and the relay connects a C point to its corresponding Y point depending on the instructions given to it (C0 to Y0, C1 to Y1, etc.)

Most relays are usually NC (normally closed)by default and not NO (normally opened), this means that it allows for current flow in its normal state, normally opened is the exact opposite. Read more about the working principle of a relay here.

Now that we know what goes where, it’s time to talk about what decides what.

Ladder Logic

Remember that PLC programming language exists in 2 forms; Textual and Graphical form and the most widely accepted is the graphic form. For the sake of our reference PLC, we would be learning about Ladder Logic, a type of graphic form(also known as Ladder Diagram).

Ladder logic is much more visual than most programming languages so people often find it much easier to learn. It is a method to document the design and construction of relay racks as used in manufacturing and process control.

Each device in the relay rack would be represented by a symbol on the ladder diagram with connections between those devices, these symbols exist in wide varieties and denote different states. It would be a hassle to draw these symbols ourselves, this is why there are software programs that make our work easier.

Installing Gx Developer.

MELSOFT’s (Mitsubishi Electronic’s Software) GX Works was built to write ladder diagrams and is compatible with our reference PLC. If you intend to use GX Works for your company, you can go over to their site and signup to become an MEAU user, it comes with cool benefits and you can select the packages you want to download but for students or any other person intending for personal use, I recommend plc4me because the download steps are very easy to follow.

GX Works3 is the latest version but GX Works2 works just fine so I suggest you download the latter for the cause of this learning.

MELSOFT official site
plc4me site

Note: installing and running the GX Works requires quite a lot of memory so it is advisable to close other installation instances before installation. Installation may take a while but you should take all the time you need, it’s about to get bumpy!

The GX Works2 is an all-inclusive software that supports all engineering aspects, including system design, programming, debugging, and maintenance. However, we would be using the GX Developer, which would now be called GxD henceforth. The interfaces are pretty similar and you do not have to switch but the GxD is more optimized for low-end computers. It also supports the MELSEC instruction list (IL), MELSEC ladder diagram (LD), and MELSEC sequential function chart (SFC) languages, you can switch back and forth between IL and LD at will while you are working but we are only interested in LD.

Launching GxD from GX Works

To open GxD from GX Works2, you can follow these steps:

  1. Open GX Works2.
  2. Click on “Tools” in the menu bar.
  3. Click on “GX Developer”.
  4. GX Developer will now open.

The major functions of the GxD include:

  • Program writing.
  • Reading and writing from/to the PLC.
  • Monitoring.
  • Debugging.
  • Diagnosing.

Getting Started with GxD.

When you launch your Developer for the first time, you should see an interface like the one below and like every other conventional software, you can always toggle on/off the sections you want to see. I keep the status bar, toolbar, and project data list in view while ‘Elapsed time’ is rarely toggled on.

From the image above:

  • 1. Edit Screen: the interface where the ladder diagram is written.
  • 2. Project data list: shows a directory of all the information about any new project you create, information on this list may include the project name, comment, project parameters, etc.
  • 3. Status bar: indicates all the information about the GxD at a given instance.
  • 4. Toolbar.
  • 5. Menu bar.

You can also edit the preference of your toolbar by clicking on View > Toolbar…
You would see a popup menu containing a checklist of all the sections, most sections are irrelevant for this course since we are strictly learning about ladder diagrams.

Uncheck *Comment, Device memory, SFC(sequential function chart), SFC symbol, ST(structured text).

*Comment and Device memory are optional.

The Customize button allows you to rearrange the order of these sections while Initialization lets you restore arrangements to default settings. Learning by doing is better, feel free to see what happens when you tweak a few things.

Opening a New Project

To open a new project:

  • Hover over the menu bar at the top left corner of the screen
  • Go to Project > New project or use the shortcut Ctrl + N, you should see a popup menu like the one below.
  • Under the dropdown of ‘PLC type’, select ‘FX1N(C)’ because our reference PLC is an FX1N-20MR. The GX Developer supports Q Process, Q, L, FX Series, and legacy controllers A and AnS Series but always remember to check your PLC type so you don’t run into errors.
  • ‘Ladder’ is usually selected by default as the ‘Program type’, ensure not to select other options.
  • Tick ‘Setup project name’.
  • Specify the project path and project name.
  • Proceed to click OK.
  • Click ‘Yes’ when prompted to create a project with that name.
  • Finally, click ‘Yes’ or ‘No’ depending on if you want to save the project or not.

Notice that most of the grey buttons in the toolbar section have become active, also note the changes in the project data list and the status bar. Let’s write some ladder diagrams!

Writing your first Ladder Diagram!

To easily understand LDs, think of them as a visual representation of boolean conditions. Remember NC and NO? It would be helpful to think of NC as ON/TRUE/1 and NO as OFF/FALSE/0.

A Scenario…
You are employed to improve the automation process in a cutting factory, several workers have lost their fingers/hands to the cutter because the blade motor is controlled by a latching switch, this means that at constant power supply, the motor would continue to receive power if the switch remains ON.

This system is not only wasteful but also bound to cause several casualties. A good fix would be to replace the latching switch with a non-latching switch but you can make it safer.

Think of a way to ensure that putting the switch in an ON position does not start the motor except the working area is clear. Do you see what the boolean condition should look like? Can you tell which devices are input/output devices?

Basically, ON the motor if and only if the switch(normally open) AND the proximity sensor(normally open) are ON, OFF the motor otherwise. It’s okay if you didn’t get it, you can read about logic operators here. Do not forget that normally open proximity sensor would give an ON output when the target(hand) enters the sensing zone.

Getting familiar with LD symbols.

There are various LD symbols and they are either used to denote an input or an output end

LD symbols with their corresponding shortcuts. sF5 simply means Shift + F5, c is Ctrl and a is Alt.
imaage source: https://www.allaboutcircuits.com/textbook/digital/chpt-4/contact-normal-state-make-break-sequence/

Hovering over each button would show you their names, F5 and F6 are NO and NC inputs, let us use F5 with F7 to create the scenario of the cutting machine above.

Creating LD for the Factory Scenario.

  • Make sure the cursor(blue box) is at the initial position.
  • Click F5, you should see the prompt below.
  • Enter the point you want to use, X0 signifies that the input device should be connected at X0 on the PLC.
  • Press enter or click ‘OK’.
  • Notice how the area turns grey, this is because we have not converted the LD. Think of it as that asterisk that shows when your Word document is unsaved.
  • Commenting is a good practice in any programming space, press Ctrl + F5 to add a comment block.
  • Hover over the Project data list and click on Device comment > COMMENT.
  • Ensure that you add the comment to the input point you defined, i.e do not add comments to X11 if there is no LD connection there because it would not reflect on the program. SWITCH- -NO simply means normally open switch, you can comment whatever you want.
  • Go back to the Edit screen by clicking MAIN.
  • Move to the next empty space beside X0.
  • Press F5 and repeat the same steps to add the proximity sensor, remember that you have to specify a different input point (any other point apart from X0) and be sure to remember that our reference PLC has only 13 points. Your diagram should look similar to this.
  • With your blue box highlighting the next empty space, click F7 instead and enter any output point you wish to connect your output device to.

Converting LD and Writing to PLC.

To convert your LD:

  • Press F4 or
  • Go to the menu bar and click Convert > Convert
Notice the absence of all the grey areas

Writing to PLC simply means sending your LD to the Processing unit, ensure that you picked the correct COM port when setting up the connection. Open your device manager and check which port is connected to your PLC. When your connection is right;

  • Click Online
  • Click Write to PLC…
  • Tick all the project parts you would like to write, writing ‘MAIN’ is necessary.
  • Ensure that the RUN-STOP switch on your PLC is on STOP to prevent any data loss.
  • Click ‘Execute’
  • You can disconnect the USB RS232 cable from your computer.

There are endless possibilities while creating LDs. Connecting the above inputs in parallel would mean that either of the inputs can turn on the motor, this is known as the OR operator (return ON if one or more inputs are ON, return OFF otherwise).

My Gift to You.

Do not worry about learning without a PLC, you can learn with a simulator! I am sharing a personal curation of important stuff including PLC training software that allows for LD simulation.

Care Package inbound.

Care Package has arrived!

After tapping on the link, go back by one directory, tap on the 3 dots, and download the whole folder (you might want to check the .txt file first). This resource should be more than enough help for you as a beginner looking to get serious with industrial automation.

It’s a wrap!

We have come to the conclusion of this part! it’s highly likely that the last part would be a video instead because completing a part in one month is almost impossible for me due to my academic commitments. This series does not cover up to half of what you can know about PLCs but it’s enough to get you started. I can’t wait to see you do wonders in the world of automation.

You can send your feedback and other suggestions via mail or reach me on twitter

Until the next and last part, Sayonara!

--

--

dvrvsimi
dvrvsimi

Written by dvrvsimi

Biomedical Engineering | ML/AI | Technical Writing | Innovation | Cats | #Web3

No responses yet