Switch debouncing in PLC software

When a switch or a pushbutton has to be connected to a digital circuit it is often (almost always) a nasty thing, because its unwanted behaviour.

It is a common practice to connect a button or a switch to a digital system (to a microcontroller, to a PLC, or to a PC). The simplest way to do it is shown in the picture below:


Connecting a pushbutton to a microcontroller

If we measure the voltage at the input of the microcontroller with an oscilloscope, it would show the following:


Contact bouncing phenomena

The problem is obvious. There isn’t a simple, clean low to high transition. If the microcontroller is fast enough, it senses this switch on event as if there were several pushbutton pressings.

The ultimate solution for this problem is to use a button with a change-over contact and a R-S flip-flop. This completely avoids the contact bouncing phenomena.


RS flip-flop debouncing

Unfortunately this solution has two major problems:

1. It is very hard to find a pushbutton with change-over contacts (almost impossible).

2. A separate R-S flip-flop hardware needed, which costs money and needs extra printed circuit board space.

By the way, nobody uses this (theoretically) perfect solution, nowadays it it handled by other techniques in the microcontroller’s software. There are man types of software solutions publised on the internet. These mainly use a time delay to detect if the contact is ON. If it is ON for a given time (let’s say 10 ms), the bouncing is over and the contact is stable.

If one could find a switch or pushbutton with a change-over contact, the R-S flip-flop function can be easily implemented in the software, but it would still use two inputs of the chip, and I/O is simply too valueable for this purpose.


Software RS flip-flop based debouncing

Now let’s focus on a real world example based on a PLC system. There is a control room, where the pesonnel can watch the entire technology, and can make some action to it. This action takes place through a control panel, where some buttons, switches and signalization lamps can be found.

These “human-machine interfaces” are connected to the PLC through a cable. This cable has many wires in parallel.


PLC and human-machine interface connection

Let’s assume that pressing a button initiates an action. By pressing again, it initiates the same action again. So we need an exact information of that given switch, whether it is open or closed.

In this case (using a PLC system as mentioned above) the PLC’s software has to handle the contact bouncing phenomena.

We could use simply an on-delay timer for this purpose, and usually this is the common way used in pratice.


Debouncing in sotfware with a single ON delay timer

But in case this control panel has an emergency OFF switch (the well known, big, red, mushroom type pushbutton) the following situation can occur:

The emergency OFF switch is a normally closed one, which lets the current flow through itself in normal cases. If pressed it directly cuts off the current from other devices, but it also signals its “pressed” state to the PLC (through its another contact). Let’s say that the interconnect cable between the PLC and the control panel is long enough, and through this cable there are also some relays driven.

When one of these relays are operated, a relatively big energy impulse is injected to the cabel by the PLC. Since the cable is pretty long, there will be some capacitive coupling between the cable’s wires. This coupling will affect the emergency OFF button’s wire as well. In an unfortunate case the affection is detected by the PLC (as if the button is pressed) so it will make some (unwanted) action to the process (probably stops it).

So at the end, the contact bouncing is to be checked in case of OFF to ON state AND in case of ON to OFF state.

Here is a simple solution for this problem:


There are simper ways to do this, but this clearly shows the principle and the physical background behind.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s