How PLC Inputs Work

This post is a further follow up from my original ‘Here’s a Quick Way to Understand PLC Inputs and Outputs’. There are basically two different kinds of PLC inputs, Discrete and analog. Discrete inputs are either ‘ON’ or ‘OFF’; 1 or 0. You can think of them as a single switch. Analog inputs have a range to them. They are inputs that usually will sense pressure, temperature, height, weight, etc.  They usually have one of the following signals that are inputted into the PLC: 4-20mA, 0-10VDC, 1-5VDC.

Discrete Inputs

The above diagram has two inputs. A normally open (NO)  and a normally closed (NC). When we talk about normally open and close, think of the condition of the input if no one touches anything. A normally open contact will not turn on the input to the PLC card in its ‘normal’ state. The normally closed contact will turn on the input to the PLC card in its ‘normal’ state.

Normally Open Input
The NO contact when activated will complete a circuit and turn on the PLC input. Ladder logic will then turn on if you use a normally open (Examine On) input in your program. See above diagram.

Normally Closed Input
The NC contact when activated will break a circuit and turn off the PLC input. Ladder logic will then turn off if you use a normally open (Examine On) input in your program. See above diagram.

As you can see with the diagram above this can get tricky to determine the on/off condition of the input. PLC logic can convert any signal by using normally closed (Examine Off) inputs in the program. In the field, I usually look at the PLC input lights, and wiring diagrams to determine the current state of the input. This is before diving into the program to troubleshoot.

Here is a link to wiring up discrete 3-wire sensors in the field. Here’s a Quick Way to Wire NPN and PNP devices

Analog Inputs

An analog input converts a voltage or current level into a digital value that can be stored and processed in the PLC. They use words to determine the signal coming from the device.
Example:
4 – 20 mA current Input – 8 bit resolution
4 mA = 00000000 base 2 = 00 base 16
20 mA = 11111111 base 2 = FF base 16
For a review of numbering systems, follow the link below:
What Everybody Ought to Know About PLC (Programmable Logic Controller) Numbering Systems

In the industrial environment noise from variable frequency drives, improper grounding, etc. can interfere with your analog input. The following post will show a quick method to reduce this noise.
The Secret Of Getting Rid Of Noise On Your Analog Signal

Here are some additional posts that you might find helpful.
How to make a Start / Stop / Jog circuit in a PLC
The Secret of Using Timers
The Secret of Using Counters

Watch on YouTube : How PLC Inputs Work

Watch on YouTube : Wiring (Testing) Analog PLC Input Click

Watch on YouTube : Wiring (Testing) Analog PLC Input Omron CP1H

Watch on YouTube : Wiring Contact (Discrete) PLC Inputs

Watch on YouTube : Wiring PNP Sensor to PLC

Watch on YouTube : Wiring NPN Sensor to PLC

If you have any questions or need further information please contact me.
Thank you,
Garry



If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLC’s are not difficult to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimal, Hexadecimal, ASCII and Floating Point.

To get this free article, subscribe to my free email newsletter.


Use the information to inform other people how numbering systems work. Sign up now.

The ‘Robust Data Logging for Free’ eBook is also available as a free download. The link is included when you subscribe to ACC Automation.

How you can learn PLC Programming without spending a dime!

I have been writing PLC programs for over 20 years. I often get asked what is the best way to lean PLC programming. Programming in the way I was taught in college was with the Motorola 6809. (Yes, I know that I am dating myself) This was microprocessor programming, but it was the best way to sometimes explain the methods behind PLC programming. Manufacturers of PLCs had allot of proprietary software that were not even related in their appearance and methods of programming. Today we have a few standards that have changed the look and feel of the programming software packages so each manufacturer is similar. The following is the best recommendation that I have for beginners to start to learn PLC programming today.

The first place to start in order to learn PLC programming is the free publication by Kevin Collins. This PDF will teach you PLC programming without just telling you what a PLC is and how it functions. He also includes some test questions along the way in order for you to retain and understand the important points that he is making.

PLC Programming for Industrial Automation
by Kevin Collins
(Note: This book is now for sale on Amazon.)
https://www.amazon.com/Programming-Industrial-Automation-Kevin-Collins/dp/1846855985
Topics covered include:

  • PLC Basics
  • Ladder Programming
  • Conditional Logic
  • Ladder Diagrams
  • Normally closed contacts
  • Outputs and latches
  • Internal relays
  • Timers
  • The Pulse Generator
  • Counters
  • Sequential Programming Introduction
  • Evolution of the Sequential Function Chart
  • Programming using the Sequential Function Chart
  • Entering the SFC program into the PLC
  • Modifying an SFC Program
  • Selective Branching
  • Parallel Branching

After learning the basics from the above manual, practice. Create programs yourself and test what you have learned. You can accomplish this by using simulators. Allot of the programming software will have simulators. The simulator will mimic the PLC hardware so you can test your programs before installing in the field. Traditionally I have not been a fan of simulators, but recently Automation Direct has introduced a simulator with their Do-More PLC. It is the Do-More Designer Software. This software simulator includes the entire instruction set (Not Just Bit Logic) as well as communication protocols. It can be downloaded and installed for free from the above link.

The next step I recommend is then to advance into some of the advanced instructions. An understanding of the numbering systems in the PLC will be a benefit. Math, PID, register manipulation and conversion instructions are just a few of the advanced programming you can learn. All of these and more instruction information can be obtained from reviewing the documentation from the PLC manual that you are programming. Once again all of these instructions are included in the Do-More Designer Software.

Program structure is the next topic. Allot of programmers would stop here and can do well with developing software, however there is much more that you can lean.  Sequencers give programmers the methods to change logic on the fly and allow troubleshooting the system easier. This method of programming can benefit you greatly and reduce the development time of your logic.

The last step that I recommend learning is the sharing of information. I am meaning the information that you program through an HMI and/or SCADA package. This refers to understanding of the ways in which information can be gathered from the PLC and displayed in different ways. Here are a couple of previous articles that have been written on this subject:

How to Implement the Omron PLC Host Link Protocol 

Robust PLC Data Logger

As you can see, there is allot of information available to you to begin and lean PLC programming without spending a dime!  Remember that PLCs are similar to computers, (Moore’s Law) they increase in size and ability. Systems are expanding and changing everyday. Happy programming.

Do you know of additional tips or methods to share?

Watch on YouTube : How you can learn PLC Programming without spending a dime!

If you have any questions or need further information please contact me.
Thank you,
Garry



If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLC’s are not difficult to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimal, Hexadecimal, ASCII and Floating Point.

To get this free article, subscribe to my free email newsletter.


Use the information to inform other people how numbering systems work. Sign up now.

The ‘Robust Data Logging for Free’ eBook is also available as a free download. The link is included when you subscribe to ACC Automation.

How to Troubleshoot a PLC

Your control system does not work. Where do you start? Lets walk through a series of questions in order to determine where the problem lies.

Is this a new installation or previous installation that was running fine? Determine if system has been running well in the past and has currently stop working correctly. This is the indication that the problem relies inside the system.

Is there anything that has happened outside of the system? Has there been a lightening strike, blown drives on other systems, etc.  This can point to the original cause of the malfunction.

What is the system doing now and what should it be doing? Gather all of the information you can from every resource you can.

  • Supervisors  – machine, location, time of error, other happenings in the plant, etc
  • Operators – What is it currently doing? What should it be doing? What do you think is wrong?
Operators of the equipment are your key resource in finding, correcting and ensuring the error does not happen again. They know the equipment from an operational point of view which can assist you greatly in troubleshooting.

PLC fatal and non-fatal errors:
If the machine is still running partially then this is an indication of a non-fatal error. Cannot run at all is usually a fatal error.

Take a look at the PLC indicator lights on the CPU. Refer to the operation manual for the PLC for troubleshooting specific lights on the CPU. The following are general tips:

If no lights are on then the possible cause is a power supply. This is usually the most common of errors on a PLC system. Mean time before failure (MTBF) is rated on the lowest rating of components which is usually the power supply.

If the run light is on and an error light flashing this usually indicates internal errors such as batteries, scan time, etc. It is usually not the reason for the lack of operation.

If the run light is on and no other errors are seen on the CPU we can put the PLC program on the bottom of the list of items that could be the cause.

Check the input cards of the PLC. You should see the individual sensors lighting up the inputs. If not then check the power supply to the input card / cards.

Ask the operator what is happening and what is suppose to happen. Try to follow the sequence of events in the PLC to determine either and input or output device not working.
Some items to watch:

If this is a new PLC program that you are doing start with a logic flow diagram. This will determine the procedure to start programming.
Every program can be done in several ways. The best method is the most documented one.

Documentation is the mark of a good program.

Some trouble with new programs can be racing conditions. This is usually a case of not understanding how the PLC scans logic. In general the PLC will scan from left to right, top to bottom. The output bits / words are available to the inputs of the next rung of logic. (Modicon PLC’s will scan differently.) Actual outputs and inputs are not read until the end of the scan of the PLC. Racing conditions happen when the output is set on multiple rungs, but will not get actually set until the end of the scan. Think of it as the last action will always win. So if this happens move the logic to the end of the program and see if it works. Then go back and see where the output was also set.  Cross reference guides are ideal for this purpose. (Refer to your programming software on how to get cross references.)

We have discussed just a few troubleshooting techniques. Hopefully now you know how to start looking for the errors on your  system. Let me know how you make  out.

Watch on YouTube : How to Troubleshoot a PLC

Do you know of additional tips or methods to share?

If you have any questions or need further information please contact me.
Thank you,
Garry



If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLC’s are not difficult to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimal, Hexadecimal, ASCII and Floating Point.

To get this free article, subscribe to my free email newsletter.


Use the information to inform other people how numbering systems work. Sign up now.

The ‘Robust Data Logging for Free’ eBook is also available as a free download. The link is included when you subscribe to ACC Automation.

How to Implement the Omron PLC Host Link Protocol

Hostlink communication protocol is a method developed by Omron for communication to PLC’s and other equipment. This ASCII based protocol is used over RS232 or RS422/RS485. It is a many to one implementation which means that you can communicate with up to 32 devices back to a master. (1:N) This communication on the industrial floor can control PLC’s, Temperature Controllers, Panel Meters, etc.

Our look at this protocol will include the wiring, setting of RS232 port settings, protocol format and  writing a VB6 program to read information from the PLC. I will also point you links to then store this information into a database and share over an intranet/internet. Lets get started.

Wiring of the communication ports will depend on the equipment purchased. If communicating over 15 meters, it is recommended to switch to RS422 or RS485 connection. However I have seen RS232 runs of 50 meters without an issue. It will depend on your implementation and electrical noise in the plant.

The above diagram is the basic communication needed for RS232C. Note that the shield of the communication wire is connected only to one side. This ensures that any noise induced in the communication is filtered to one end.

Settings for RS232C communications are set in a number of ways. Older Omron C**K PLC were set through a series of dip switches. Current Omron SMR1/CPM1 PLC’s are set though data memory locations.
Note: Most of the time, you need to cycle the power or switch to program / run mode for the setting to be activated.

I generally tend to leave everything at the default settings: 9600 bps, Even parity, 7 data bits, 1 stop bit. The default host link unit number is 00. (32 max. – 00 – 31)

Protocol Format
Each piece of equipment will have a list of parameters that can be read and written using the HostLink protocol. This can be found in the programming manual of the device. Here are the areas in the CPM1/CPM1A/CPM2A/CPM2C/SRM1(-V2) from the programming manual.

Lets take a look at the command to read the DM area. All of the commands and responses will be in an ASCII format.

The command format begins with a ‘@‘ sign followed by the Node / Unit number that you wish to communicate. Header code is the command in which you with to execute. (RD) This header code will determine the next series of information. In our case the next four digits will be the beginning word followed by the next four digits to indicate the number of words. The next part of the command is the FCS (checksum) calculation. The comparison to this at each end will ensure that the command/response is correct. FCS is a 8 bit data converted into two ASCII characters. The 8 bits are a result of an Exclusive OR performed on the data from the beginning to the end of the text in the frame. In our case this would be performed on the following:

"@00RD00000010"

The last part of the command is the terminator. This is an ‘*’ followed by the character for the carriage return. (CHR$(13))

The response format begins with a ‘@’ sign followed by the Node / Unit number that you are communicating to. The header code is next (RD) followed by the End Code. The end code is a two digit ASCII code that indicates the message response / errors when executing the action. A normal code of ’00’ indicates that everything is fine. See the operation manual for the entire list of end codes for your equipment. The next part of the response depends on the header code executed. In our case it would contain the data requested. The last two parts of the response is the FCS and terminator just like the command format.

The above shows the timing of the command and responses.

Visual Basic VB6 (Example)
Now lets look at an example of reading the first 10 words from the DM area  of an Omron PLC.

The first step is the design the form. You can see that we have our ten DM area words set out to populate with values. We also have a T$ for transmit. This will show what we are sending to the PLC. The RXD$ will show what the response will be from the PLC.

The MSComm is used to communicate through the serial ports of the computer. The following is the settings for the communication port.

Here is the VB6 code for the program:
When the form loads the Date/Time will get updated and Timer1 is enabled. This timer controls the interval in which the commands get executed. (Set to 1 second)

Private Sub Form_Load()
 Label2.Caption = Format(Date, "YYYY/MM/DD") + "    " + Format(Time, "HH:MM:SS")
 Timer1.Enabled = True
 End Sub

The following code will open the communication port, set the command format, send the command through the port, receive the response through the port and display the information. It will then close the communication port.

Private Sub Timer1_Timer()
 Timer1.Enabled = False
 MSComm1.PortOpen = True
 Label2.Caption = Format(Date, "YYYY/MM/DD") + "    " + Format(Time, "HH:MM:SS")
'Check DM AREA DM0000 to DM0009 data update
 T$ = "@00RD00000010"
 charreturn = 51
 GoSub FCS
 GoSub communicate
'Show Transmit information
 Label24.Caption = Buffer
 'Show Returned information
 Label26.Caption = rxd$
If Mid(rxd$, 6, 2) = "00" And (Len(rxd$)) >= charreturn Then
 Label4.Caption = Mid(rxd$, 8, 4)
 Label6.Caption = Mid(rxd$, 12, 4)
 Label8.Caption = Mid(rxd$, 16, 4)
 Label10.Caption = Mid(rxd$, 20, 4)
 Label12.Caption = Mid(rxd$, 24, 4)
 Label14.Caption = Mid(rxd$, 28, 4)
 Label16.Caption = Mid(rxd$, 32, 4)
 Label18.Caption = Mid(rxd$, 36, 4)
 Label20.Caption = Mid(rxd$, 40, 4)
 Label22.Caption = Mid(rxd$, 44, 4)
 End If
 Timer1.Enabled = True
 MSComm1.PortOpen = False
 Exit Sub

The following is the subroutine to communicate. Timer2 is the amount of time to wait before expecting an answer on the communication port. Once the command has been sent a maximum of two seconds is waited for an response. If no response nothing is returned. When the response is obtained, the FCS is checked and if correct the information is returned.

communicate:
 rxd$ = ""
 Buffer = T$ + FCS$ + "*" + Chr$(13)
 MSComm1.Output = Buffer
 Timer2.Enabled = True
 Do
 DoEvents
 Loop Until Timer2.Enabled = False
 If Time > #11:59:50 PM# Then
 timeout = #12:00:02 AM#
 Else
 timeout = DateAdd("s", 2, Time)
 End If
 MSComm1.InputLen = 0
 Do
 If timeout <= Time Then GoTo timeoutcom
 DoEvents
 Loop Until MSComm1.InBufferCount >= charreturn
 rxd$ = MSComm1.Input
 fcs_rxd$ = Left((Right(rxd$, 4)), 2)
 If Left(rxd$, 1) = "@" Then
 T$ = Mid(rxd$, 1, (Len(rxd$) - 4))
 ElseIf Mid(rxd$, 2, 1) = "@" Then
 T$ = Mid(rxd$, 2, (Len(rxd$) - 5))
 rxd$ = Mid(rxd$, 2, (Len(rxd$) - 1))
 End If
 GoSub FCS
 If FCS <> fcs_rxd$ Then
 rxd$ = ""
 End If
 clearbuffer$ = MSComm1.Input
 Return

This is the FCS (checksum) calculation routine.

FCS:
 L = Len(T$)
 A = 0
 For J = 1 To L
 TJ$ = Mid$(T$, J, 1)
 A = Asc(TJ$) Xor A
 Next J
 FCS$ = Hex$(A)
 If Len(FCS$) = 1 Then FCS$ = "0" + FCS$
 Return

This is the routine that will execute if the response is not received within the time period expected.

timeoutcom:
 clearbuffer$ = MSComm1.Input
 rxd$ = ""
 Return
End Sub

Timer2 was used as a delay before looking for a response after sending the command.

Private Sub Timer2_Timer()
 Timer2.Enabled = False
 End Sub

Here is the code running:

Helpful Tips/Links:
– When troubleshooting serial communications it is sometimes helpful to use HyperTerminal. This program will send and receive information in/out of the serial ports.
HostLink Command Generator
HostLink Command Format

Watch on YouTube : How to Implement the Omron PLC Host Link Protocol

If you have any questions, need further information or would like a copy of this program please contact me.
Thank you,
Garry



If you’re like most of my readers, you’re committed to learning about technology. Numbering systems used in PLC’s are not difficult to learn and understand. We will walk through the numbering systems used in PLCs. This includes Bits, Decimal, Hexadecimal, ASCII and Floating Point.

To get this free article, subscribe to my free email newsletter.


Use the information to inform other people how numbering systems work. Sign up now.

The ‘Robust Data Logging for Free’ eBook is also available as a free download. The link is included when you subscribe to ACC Automation.