Multiprog: The One – Shot

This tutorial is going to introduce a little about how the ordering of your program affects the way it is interpreted. Once this is explained, we are going to go on to introduce the One-Shot structure, which uses the fact that parallel components aren't calculated at exactly the same time in order to work.

When your PLC program is run, the order of execution is as follows : Read inputs, Execute program, Write to outputs. Simple enough – The PLC will look at all the input cards, run through the program ONCE, then write to all of the output cards. However, this is done quickly enough that it looks like the entire program is running at once. Most of the time, this is a reasonable thing to assume. However there are small edge cases (Such as if you have more than one contact for the same variable) where something that looks logically impossible is happening – This is generally known as a Race Hazard, which, if not detected, can cause all manner of problems in a piece of code. The reason for this is because ladder is read from top to bottom, each line being read from left to right (In the same way we read text).

Image 5.1 Latch(Above) One-Shot (Below)

For Example, the bottom rung in image 5.1 is what is known as a one-shot. Logically, Q should never be true. As at any point when A is true, T would become true, and Q is (A AND (Not T)). However, due to the way that PLC programs are read, the line with Q, is calculated before the line with T, meaning for one cycle only, Q is true, before T becomes true, and Q is false again.

Image 5.2 Timelapse of how a oneshot works, Where one Column of dots = one PLC Tick. (Values of variables at moment of calculation)

Image 5.2 Shows A timelapse of how this works in practice, as you can see, there is a blip of One cycle where Q is high, before going low again, once Not T catches up due to it being checked before the T contact is set by the program, meaning it lags one cycle behind.

The fact that this construct will pulse once, and only once, until A becomes false again, is a rather useful property, which is often used with a latch, or a set / reset contact. The eagle-eyed among you will have noticed the ‘S’ In the center of the Q contact. This means it is a set contact – It will set the variable to true, until the variable is reset. These act differently to regular contacts, as they don't constantly set the variable to a value – instead, when a set contact becomes true, the variable becomes “set” and stays true until reset, even if the set contact goes false again. The inverse applies for a reset contact, if a reset contact becomes true, the variable will become false until set again.

If a set / reset contact is false, it has no effect on the state of the variable. This means you can have multiple set and reset contacts in a program with no negative effects – as long as only one becomes true at a time. The advantage of this over using a latch, is that the set and reset contacts can be spread around over the program with no ill effects. However it is often simpler and more intuitive to use a latch with a regular contact as opposed to multiple set / reset contacts. Learning the appropriate time to use each type is a useful skill to develop.

Image 5.3 Set and Reset Contacts

Now you know about program execution order, set / reset contacts, oneshots, and race hazards – the next step is to become familiar with function blocks. Tutorial six will go into detail on using these, with a specific focus on timers and some interesting things that can be done with them.

Joel Duncan

Read more posts by this author.

Subscribe to Bubble Automation Blog

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!