Category Archives: digital

How to Send Email to SMTP Server

Simple mail transfer protocol (SMTP) is the email protocol for sending information. We can take advantage of this ability to email from our data logged from the PLC. Shift reports on productivity can be automatically emailed to recipients. Faults or errors detected by the PLC can be emailed directly to individuals for correction.

We will use visual basic 6 (VB6) to send an email message to the SMTP Google Gmail server. Using this method we can use HTML code to format our messages. Attachments can also be added to the email message. In this example I have added the ACC icon file.

The first step is to add a reference to Microsoft CDO for Windows 2000 Library.  Project -> References

Make a simple form:

This will have one command button on it labeled “Send Mail”

The code for the command button will be as follows:
Private Sub Command1_Click()

Call SendEmail
End Sub

Add the following Sub SendEmail code to the project :
‘Sample code that is used to send emails from any SMPT server using CDO in Visual Basic 6.0.

‘Added a reference to the project by navigating to Project -> references and adding Microsoft CDO for windows 2000 Library.
Sub SendEmail()
On Error Resume Next ‘ Set up error checking
Set cdoMsg = CreateObject(“CDO.Message”)
Set cdoConf = CreateObject(“CDO.Configuration”)
Set cdoFields = cdoConf.Fields
‘ Send one copy with Google SMTP server (with autentication)
schema = “http://schemas.microsoft.com/cdo/configuration/”
cdoFields.Item(schema & “sendusing”) = 2
cdoFields.Item(schema & “smtpserver”) = “smtp.gmail.com”
cdoFields.Item(schema & “smtpserverport”) = 465
cdoFields.Item(schema & “smtpauthenticate”) = 1
cdoFields.Item(schema & “sendusername”) = “gclshortt@gmail.com”
cdoFields.Item(schema & “sendpassword”) = “password”
cdoFields.Item(schema & “smtpusessl”) = 1
cdoFields.Update
With cdoMsg
    .To = “gshortt@domtech.net”
    .From = “gclshortt@gmail.com”
    .Subject = “Send email to gmail”
    ‘ Body of message can be any HTML code
    .HTMLBody = “Test message using CDO in vb6 to Gmail smtp”
    ‘ Add any attachments to the message
    .AddAttachment “c:\AccDo.ico”
    Set .Configuration = cdoConf
    ‘ Send the message
    .Send
End With
‘Check for errors and display message
If Err.Number = 0 Then
      MsgBox “Email Send Successfully”, , “Email”
Else
      MsgBox “Email Error” & Err.Number, , “Email”
End If
Set cdoMsg = Nothing
Set cdoConf = Nothing
Set cdoFields = Nothing
End Sub

When you run the program you will get one of the following messages depending if the email was correctly sent or not.

Here is the message that arrives to the recipient:

Simple mail transfer protocol is an easy way to share information from the PLC data collected.
You can download the following VB6 sample code here.

Watch on YouTube : How to Send Email to SMTP Server
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.

Who Else Wants to Learn About On Off and PID Control?

Process control can be a bit intimidating. We will try and break down both On/Off and PID control in a fun way. This is a simple analogy without any math.

On/Off control can be used effectively with temperature control. Everyone’s house usually has a temperature controller that uses an On/Off control. When the temperature is below the set value (SV) the output switches on. The output will remain on heating the house until the present value (PV) is above the set value. At this point the output will then go off. The house will constantly be doing this in a cyclic way. This means that the temperature of the house will vary a few degrees.

We can plot this out like the sign wave above. The set point is at the middle. By the time the output is turned off the thermo mass continues to heat the house, before starting to cool down. The same is true when the output is turned back on. It will cool down a little more then start to heat up again. This is called hunting. We can not get exactly on the set point value and stay there.

Lets look at another way to explain:

You are in a car and can only use full gas or full brake. Racing toward the stop sign at full gas, you use full brake at the stop sign line. Naturally you go passed the stop sign and eventually come to a full stop. Putting the car in reverse, you again use full gas back toward the stop sign line. When you hit the line you apply full brake. Missing the mark again.  This is like On/Off control action.

If we wanted to control the method a little closer then we could program in a hysteresis. (Dead band) This is just a range in which nothing would happen. It would take into consideration the amount that we went over the line in both directions.

If we need to hit the stop sign target a little more accurately then we can now introduce another control method.

PID is a time based control logic. It will look at a control period (CP) and determine what to do for the next. In a temperature control application the control period would be 20 seconds. In a servo valve application, it can be 1 second. Lets look at each of the control methods in the PID with respect to our car analogy.

Proportional Control (P) – This will increase in amount based upon the error. The closer we get to the set point, the control period will be on for a longer period of time. (Reference to the output percentage  of control period time.)

In our example the car can be seen applying the brakes proportionally longer and longer times before the stop sign line is reached. If it goes over the stop sign line the car will apply the brakes even longer depending on the amount over the line. This is proportional control.

Integral (I) – Using just proportional control would always leave us below the set point. We need a method to reset us to the actual set point. This is where integration comes into play. It is interesting to note that PI control is one the most commonly used in the industry.

The car above is travelling along the road, following the dashed lines. If we used just proportional control we would find ourselves riding in the ditch. The integral control will move us into our lane and keep us close to the dash line.

Derivative (D) – This mode of control will look at rate of change and adapt our control to get us back to set point. Remember that everything is based upon a control period which is time. PI rely on the fact that everything remains constant in your control. D will take into account the differences over time.

In our car analogy the derivative function of the control will continually adjust as we move up the hill and down the other side. It will not do much as we drive along the straight road way.

We have looked at a very basic analogy of control logic without all of the details of math. This can aid in understanding what your process is doing and methods to correct. Further information can be obtained by the following references:

PID without a PhD By Tim Wescott
Understanding PID in 4 minutes
PID Control – A brief introduction
PID Controllers Explained

Nice project using PID:
Desktop Line Following Robot

Watch on YouTube : Who Else Wants to Learn About On / Off and PID Control?
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 Make a One Shot in the PLC

A one shot in the PLC will turn an output on for one scan. This is used to trigger events that should only happen once. An example of this would be to increment a value in memory. If a one shot is not used, then every scan of the PLC will increment the value.

One shots are known by several other names. Differential Up (DIFU), Differential Down (DIFD), One Shot Relay (OSR), Powerflow Modifier, Leading edge contact, Trailing edge contact, etc. This all relates to the programmable controller that you are programming.

Lets take a look at programming a one shot using bit logic only. We will program both a leading edge one shot and a trailing edge one shot bit. This program will work in all PLCs.
Note: The white background in the increment (INC) instruction just indicates the reset for the animation.

Leading edge one shot bit: This will turn on a bit for one scan when the input condition makes a transition from 0 to 1. (Off to on)
When input X0 turns on C0 is turned on for one scan. This is because it is in series with the C1 lead work bit. The next rung will latch this on and not unlatch it until the input condition X0 turns off. C0 will only be on for one scan when X0 turns on.

Trailing edge one shot bit: This will turn on a bit for one scan when the input condition makes a transition from 1 to 0. (On to off)
When input X0 turns off C2 is turned on for one scan. This is because it is in series with C3 trail work bit. The next rung will latch this on and not unlatch it until the input condition X0 turns off.

The Do-more PLC has several different ways to do the leading and trailing edge one shots. Here are a couple:

The leading or trailing edge contact instruction will allow logic flow for one scan from a transition. (On to off / Off to on)

The leading and trailing edge Powerflow Modifier is placed before the output. It will turn multiple input signals into a one shot for the output.

Watch on YouTube : How to Make a One Shot in the 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.

Creating a Flip Flop Circuit in the PLC

A flip flop curcuit in a PLC usually has one input and two outputs. When the input is activated, the two outputs latch on/off opposite to each other alternately.  Basically it is used to toggle (latch) an output on and off with just one input. In the PLC it is a single input that will toggle an output on and off each time the input signal is activated.

Here is an example of a hard wired flip flop circuit using relays.

The PLC program will be a little different than the relays because of the way in which the PLC scans. Scanning takes place from left to right, top to bottom. The output conditions from the logic are available to the next rung as the logic is solved. Outputs and inputs are read usually only once at the end of the scan. Remember to think of the outputs in the PLC as make before break. This is the opposite of the relay logic presented above which is break before make.

Lets look at the logic. This is programmed using the Do-More Programming Software which comes with a simulator. This full programming package is free of charge and can be downloaded here.

The input is on a leading edge instruction. (One Scan) If output 2 is on then it will set output 1. If output 2 is not on then it will reset output 1. The third line of code will determine the state of output 2 based upon output 1.

You may be asking yourself why do we not just use the conditions from output 1 to control output 1.  This is because if we substituted output 1 for the conditions on the input then the output 1 would never turn on/off. The output conditions are available for the next line of PLC code. This would allow the output to be set and reset within the scan without being updated. Using output 2 is the only way in which this logic would work.

Here is an automated picture to show the input toggling on / off and the outputs flip flopping.

Note: An emergency condition can be added to the set or reset rungs to automatically control the output either way.

Watch on YouTube : Creating a Flip Flop Circuit in the 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.

Building a PLC Program That You Can Be Proud Of – Part 4

In part 1 we looked at writing PLC programs to control a traffic light using discrete bits and then using timed sequencing using indirect addressing. Part 2 used indirect addressing for inputs as well as output to control the sequence of pneumatic (air) cylinders in the program. Part 3 returned to the traffic light application and expand our program significantly. We looked at the sequence of operation using Input, output and mask tables. Part 4 will now continue with the programming of the logic in the PLC.

Let’s look at the sequence that we are controlling:
Note that I have colour coded the outputs that will be on in the sequence. This makes it easier to read how the lights will behave. All bits without ‘1’ are assumed to be ‘0’. The pedestrian walk signals flash before they change to the do not walk signals.

The weekend sequence looks like this. We have overlap of the red signal lights. The arrows are not used.

The weekday off peak times sequence looks like this. We have an advanced flashing green light for the north and west traffic.

The weekday peak times sequence is as follows. The turn arrows have been added for the north/south and west/east directions.

It is important to note that the sequencing and information contained in these charts must be understood fully before programming can begin. Take the time to review and understand the following tables. Here is a copy of the excel table complete with the inputs, mask and outputs.

This method of programming can have vast number of applications. Here are some of the advantages of using this method:

  • Modification of the program without extensive rewriting
  • Integration with a Human Machine Interface (HMI) to control, modify and/or troubleshoot
  • Ability to sequence forward and backward
  • Easily understood logic to follow. Looking at he pointers can the on compare instruction will quickly tell you what sensor is not being made.
Troubleshooting this method of programming is easily done. Compare the bits in the input pointed word to the actual bits form the input in binary format. The difference is the input/output that is not working.

The program is basically broken down into three sections:

  • Inputs – Setting bits in the input channel based upon actual and internal conditions.
  • Control  – Control of the pointers, mask and setting the output channel.
  • Outputs – Using the output channel to activate the actual and internal actions required.

 Inputs:

The program is all controlled by one on-delay timer. This sets the minimum time between each step.

Control:

This section of the control will tell the PLC what to do when the unit is first powered on. It resets the pointers and moves the initial output setting to the output word. You will see that since we have three different sequences running, there are three different reset rungs in parallel. The table input pointer is compared to the last value +1 of the sequence running.

The mask calculation is next. This is used to ignore the inputs that we do not want to see or may not know the status during the execution of the program.  

You will notice that the first three sequences are all the same. On this step we then determine if the pointers need to be changed for the other two. The first is for weekday off peak times.  

This is for the weekday peak times.  

We now compare the actual inputs after the mask with the input table word. If they are equal then move the output table word to the output channel and increment the pointers to the next step.  

Outputs:

The actual outputs are set using the output word bits. You will note that the flashing green lights are done when both green outputs are not on. This way will give me the greatest flexibility when developing different sequences. The do not walk signal is not part of the sequence but is controlled when the flashing walk or walk is not on.

The program will not change much for completely different sequences.

This program and the data tables can be downloaded here. Note that in order to run this program you must call up the input, mask and output tables and write them to the simulator or PLC.

In Part 5 will will make a Game of Simon by learning all about bit manipulation and sequencers.

Watch on YouTube : Building a PLC Program that You can be Proud Of – Ultimate Traffic Light Control

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.

Building a PLC Program That You Can Be Proud Of – Part 3

In part 1 we looked at writing PLC programs to control a traffic light using discrete bits and then using timed sequencing using indirect addressing. Part 2 used indirect addressing for inputs as well as output to control the sequence of pneumatic (air) cylinders in the program. We will now return to the traffic light application and expand our program significantly.

Let’s build on the traffic light sequencing used in part one with inputs for pedestrian and car detection. We will also throw in the time of day so that during weekday peak hours an advanced arrow will be used. Advanced green (flashing) will be used when the traffic is detected in the turning lane during the off peak hours.

Programming using this method of sequencing requires allot of time up front before we start the actual PLC program. However this method makes the program easier to understand, troubleshoot and modify in the future.

Remember that the PLC programmer must know everything about the machine and operation before programming.

If we just start writing code, then we will constantly be correcting and modifying based on trial and error. I use a spreadsheet program to plot out the inputs, outputs and mask tables. We will go into the details of this below.

Lets look at the inputs:

We set up the input table in words V0 to V499. Each bit in the table will be compared to the signals coming the actual signals wired or programmed in the PLC.
Bit 0 is the time input which will control the entire program interval. Next we have the Car Detection signals on Bits 1 to 4. The pedestrian signals are pushbuttons coming from Bits 5 and 6. The left turn signals are located in Bits 7 to 10.  The real time clock functions will come from Bits 12 to 15.

Lets look at the outputs:

The output table will be in words V1000 to V1499. The input word will be compared to the actual inputs and the corresponding output channel will be moved to the actual outputs. All of the output bits control lights. You will notice that there is a green light for each direction. This will give us the greatest flexibility when writing our PLC program. Pedestrian signals have a flashing output bit and just an output bit. There will be only one output but this bit will determine if it is flashing or not.

Masking Inputs:

The masking table will be in words V500 to V999. The masking bits will correspond directly to the input table bits. Using the mask will allow us to ignore the status of certain bits when using the compare instruction and setting the outputs.

The Mask table will be used by using an ‘AND’ word instruction. If the mask bit is on for the input then it will be used in the compare instruction. If the mask bit is off for the input then the value is always off using the compare.
Example:
1 ‘AND’ 1 = 1
1 ‘AND’ 0 = 0
0’AND’ 1 = 0
0 ‘AND’ 0 = 0

Once we have this all laid out in the spreadsheet, we can start filling out our sequence of events. Fill in the events based upon the time frame from input bit 0. I usually start by thinking about what happens when power is applied to the unit the first time. This exercise can be a struggle because you must know exactly what you want the sequence to be in order to fill out the table.

We will continue this next time by writing the code to do what our tables want. A review of the numbering systems can be found on this post. A copy of the spreadsheet can be obtained at the following link: PLC Traffic Sequence

Part 4 will continue with the programming of the logic in the 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 PLC Outputs 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 outputs, Discrete and analog. Discrete outputs are either ‘ON’ or ‘OFF’; 1 or 0. You can think of them as a single light bulb. Analog outputs have a range to them. They are outputs that usually will control proportional valves, drive speeds, etc. They usually have one of the following signals that are outputted from the PLC: 4-20mA, 0-10VDC, 1-5VDC.

Discrete Outputs

The above diagram has three outputs. A coil, light and motor. The Ladder outputs Y0, Y1 and Y2 control the outputs respectfully. You will notice that when the Ladder output turns on, the corresponding output card bit LED turns on. This then will energise the output hardwired to the device.

The outputs are turned on or off at the end of every PLC Scan. The PLC logic is solved left to right, top to bottom in most PLCs. Physical outputs are not set / reset until an I/O refresh is performed at the end of every scan. This means that if I have a scan of 1msec, then the maximum time it will take to turn on/off the output is 1msec.

PLCs will sometimes have the ability to update the I/O in the middle of a scan. Please refer to your PLC manufacturers manual for this instruction. This can be used for updating the I/O quickly or controlling stepper drives for motors by giving them a pulse train output from the discrete PLC output. A pulse train is just a quick series of on/off states of the output.

Analog Outputs

An analog output converts a digital value to a voltage or current level that can be used to control (vary) physical outputs. In the example above we are controlling the speed of the motor. Words in the PLC will control the analog value.
Example:
4 – 20 mA current Output – 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

Previous Post:
How PLC Inputs Work

Watch on YouTube : How PLC Outputs Work

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 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 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.