We will look at a PLC programming example of delaying the start of 7 motors. Each motor will be on a switch that the operator can select at any time. The motor outputs should have a 5-second delay between the outputs coming on.
This question originally came from PLCTalk.net. An original solution to the problem came from Peter Steinhoff. His solution is what we will be presenting. It is simple and straight forward.
We will continue the series by looking at a sequencer controlling seven cylinders that can be taught. The cylinders can be operator programmed from the AdvancedHMI screen. You will be able to select what cylinders to activate at each step and program in 500 steps. Our PLC will be the Do-More from Automation Direct.
Here is a quick review of the programming series so far. If you are new to the site, we recommend reviewing the other parts in the series first.
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 and 4 we returned to the traffic light application and expand our program significantly. We looked at the sequence of operation using Input, output and mask tables.
In part 5 we used the AdvancedHMI software to create the game of Simon. A round in the game consists of the device lighting up one or more buttons in a random order, after which the player must reproduce that order by pressing the buttons. As the game progresses, the number of buttons to be pressed increases.
We will be using AdvancedHMI to communicate Modbus TCP to the Automation Direct Do-More Designer Software Simulator. The following is the sequence of operation: Watch on YouTube: Running the Cylinder Sequence (PLC / HMI)
Note: All of the programs used are provided free of charge and are an excellent way to learn PLC / HMI programming.
The following table is the Modbus TCP memory map to the Do-More PLC:
Coil/Register Numbers
Data Addresses
Type
Do-More PLC
Table Name
00001-09999
0000 to 270E
Read-Write
MC1 to MC1023
Discrete Output Coils
10001-19999
0000 to 270E
Read-Only
MI1 to MI1023
Discrete Input Contacts
30001-39999
0000 to 270E
Read-Only
MIR1 to MIR2047
Analog Input Registers
40001-49999
0000 to 270E
Read-Write
MHR1 to MHR2047
Analog Output Holding Registers
Here are the inputs and outputs we will be using for our program:
Device
Data Addresses
Type
Do-More PLC
Description
Start Pushbutton
00011
Input
MC11
Stop Pushbutton
00012
Input
MC12
Jog Pushbutton
00013
Input
MC13
Reset Pushbutton
00014
Input
MC14
Run/ Jog Selector
00008 / 00015
Input/ Output
MC8 / MC15
MC8 is the value and MC15 is the click
Light Stack
00010 / 00009 / 00008
Output
MC10 / MC9 / MC8
Red / Green / Amber
Set Pushbutton
00071
Input
MC71
Jog / Teach Selector
00070
Input
MC70
MC70 on is teach mode
Sequence Step (Panel Meter)
40001
Output
MHR1
Current step in the sequence
Inputs Actual
40002
Input
MHR2
Show the actual inputs in binary format
Output Sequence
40003
Output
MHR3
Show the actual outputs in a binary format
Input Sequence
40004
Input
MHR4
Show the input sequence bits in a binary format
Cylinder 1 to 7 – value
00001 to 00007
Output
MC1 to MC7
Determine if cylinder is on/off
Cylinder 1 to 7 – set (click)
00041 to 00047
Input
MC41 to MC47
Set the cylinder button
Cylinder 1 to 7 – retract indicators
00021 to 00027
Input
MC21 to MC27
Indicate cylinder has retracted
Cylinder 1 to 7 – extend indicators
00031 to 00037
Input
MC31 to MC37
Indicate cylinder has extended
Cylinder 1 to 7 – extend / retract error indicators
00050 to 00063
Output
MC50 to MC63
Indicate cylinder input error when jogging
The first thing we will do is design the HMI. We have three main areas on the screen. Basic Controls, Cylinder Visualization, and the Sequence Step/Teach area. Please refer to the above reference chart for the inputs and outputs programmed on the screen.
Basic Controls:
This area will allow us to see what mode we are in via the stack light. Red – Stop
Yellow – Jog / Teach Mode – Troubleshooting
Green – Run
Cylinder Visualization:
Each cylinder will have indication lights to determine the status of the cylinder. (Extended / Retracted)
The cylinder will also have red indication lights to reflect the differences between the current sequence and the next sequence step. This is visible when we are in jog mode.
Sequence Step/Teach:
When in jog or teach mode the sequence step is visible, which indicates the current step that we are on. The inputs and outputs are displayed as a binary value which represents the actual inputs and outputs. This is valuable when troubleshooting and finding errors in the system. The set button is visible when in teach mode. When pushed the outputs and inputs are set for that step and the sequence will then increment.
The following is the code for each of the words that the DataScribers are reading. This includes the code to change the word into a 16-bit binary value.
PrivateSub DataSubscriber1_DataChanged(sender AsObject, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber1.DataChanged
'Label1.Text = Hex(DataSubscriber1.Value)Dim i AsInteger = DataSubscriber1.Value
Label1.Text = Convert.ToString(i, 2).PadLeft(16, "0") '16 bits
EndSub
PrivateSub DataSubscriber2_DataChanged(sender AsObject, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber2.DataChanged
'Label2.Text = Hex(DataSubscriber2.Value)
Dim i AsInteger = DataSubscriber2.Value
Label2.Text = Convert.ToString(i, 2).PadLeft(16, "0") '16 bits
EndSub
PrivateSub DataSubscriber3_DataChanged(sender AsObject, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber3.DataChanged
Dim i AsInteger = DataSubscriber3.Value
Label3.Text = Convert.ToString(i, 2).PadLeft(16, "0") '16 bits
EndSub
We will now look at the PLC ladder program. The program is broken down into several parts as follows:
ACC Automation
This is the main start / stop circuit of the program.
If we are in run mode the green light will be on. (MC9)
If we are not in jog mode (MC8) this circuit will be functional.
If we are not run mode (MC9) or in jog mode (MC8) then the stop mode is active.
This will turn on the red light. (MC10)
Run / Jog – Toggle Circuit
Flip Flop circuit to set the jog function
Move the outputs to the physical outputs when we go to run mode.
Indirect Addresses for the Program
V0 – Input pointer – 100 – 499
V1 – Output pointer – 500 – 999
V2 – Input pointer last step in the sequence
V3 – Output pointer last step in the sequence
V10 – Inputs to the sequencer
V20 – Outputs from the sequencer
Jog Mode – Jog Pushbutton
Reset the sequencer pointers. This will happen automatically in run mode or by hitting the reset button in jog or stop mode.
Teach Function
This first rung will activate the values so we can manually turn them off/on with the HMI screen.
This will reset the pointers when going into teach mode.
This will set the teach point and increment to the next step.
Show the current step of the sequence.
Note: 0 is the first step
Set the inputs for cylinders.
The actual physical input points would be inserted here.
HMI inputs from the cylinders have a 500ms delay to simulate the movement of the actual cylinder.
Set the actual inputs/sequencer inputs/sequencer outputs so we can monitor this on the HMI.
Set the outputs for cylinders.
This will set the physical output points Y1 to Y7.
This will also set the HMI cylinders MC1 to MC7 (00001 to 00007)
Diagnostic Bits for indicating the difference for the inputs to the PLC. This will show up as a red indication light on the cyclinder represented on the HMI.
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.
Now You Can Have Robust Data Logging for Free – Part 12
HTML and Scripting Languages
We have the following accomplished:
PLC program
Visual Basic Program
Data collected in a Database
IIS web service established
ASP Script Written
Let’s take a closer look at the ASP Script ( AccRL.asp) that was written in part 11:
The <html> is at the start of the file and the </head> is at the end of the file. These tags all have to have a start and end. The ‘/’ indicates the end of the tag.
The <head> is used to place the information for the web page. The refresh will load the page after 300 seconds (5 minutes). This way the information will always be the latest. The title is used to label the page. This is the information at the top of the browser. The SHORTCUT ICON is used for the icon at the top of the browser near the page address.
ActiveX Data Objects (ADO) is used to access databases from your web pages. ADOVBS.inc is a file that has all of the ADO constants defined. Be sure to add this file in your root web application directory. <!– #include virtual=”/adovbs.inc” –>
The <% and %> symbols indicate the start and finish of VBScript in the page. We dimension our variables for StartTime and EndTime. These will be used to determine how long our script took to execute.
<% Dim StartTime, EndTime StartTime = Timer
We dimension the variables that are used for the connection to the database file.
Dim OBJdbConnection Dim rs1 Dim objCmd
We set up the connection to the database and determine what information we need to retrieve.
Set OBJdbConnection = Server.CreateObject(“ADODB.Connection”) OBJdbConnection.Open “Provider=Microsoft.ACE.OLEDB.12.0;DATA SOURCE=C:\AccRL\data\AccRL.accdb;Persist Security Info=False;” set rs1 = Server.CreateObject(“ADODB.recordset”) with rs1 .CursorType = adOpenForwardOnly .LockType = adLockReadOnly .CursorLocation = adUseServer .ActiveConnection = OBJdbConnection .Source = “SELECT * FROM Minute_Log;” end with
Using getrows will allow us to execute the Select command and retrieve all of the information in one pass from the database. This is the quickest method to get the information out quickly.
rs1.Open arraytime = rs1.getrows() rs1.close
We now write the information from the database to the page.
Response.Write arraytime(0,0) & “<br>” Response.Write arraytime(1,0) & “<br>” Response.Write Year(arraytime(1,0))& “/” & Right(“0” & Month(arraytime(1,0)), 2) & “/” & Right(“0” & Day(arraytime(1,0)), 2) & “<br>” Response.Write arraytime(2,0)& “<br>” Response.Write arraytime(3,0)& “<br>” Response.Write arraytime(4,0)& “<br>”
The EndTime is now set and the total time it took for the process is displayed.
EndTime = Timer Response.write “<p>Processing took “&(EndTime-StartTime)&” seconds<p> ” %> </body> </html>
Now that you have information into the database and IIS running, you can display the data in various ways.
Charts:
Graphs:
Gauges:
This ends our robust logger design. For the complete PLC program, VB source code and web page file please send me an email and ask for the ACC Robust Logger Program. I will be happy to email you the information.
If you have any questions or need further information, please contact me.
Regards,
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.
ActiveX Data Objects (ADO) is used to access databases from your web pages. ADOVBS.inc is a file that has all of the ADO constants defined. Be sure to add this file in your root web application directory. How to add this code to a web page is shown in the sample code below.
You can download ADOVBS.inc from this site in text format. (Just rename to ADOVBS.inc from ADOVBS.txt)
ADO Introduction: http://www.w3schools.com/asp/ado_intro.asp
Lets set up ASP on IIS to display any error messages to our browser.
Call up Control Panel and then go to Administrative Tools. Call up Internet Information Services (IIS) Manager.
From IIS Manager, double click on ASP under IIS. Expand Debugging Properties and change the Send Errors To Browser to True.
Let’s also ensure that your browser is set to display the error messages in internet explorer (IE). Call up Internet options from the main settings.
Click the setting for ‘Show friendly HTTP error messages’. This will ensure that the error messages show up in your browser.
The last part of our project is to display the database information to the network. We do this by using a webpage. The HTML and VBScript can be writing in any editor. (Like Notepad)
There are also a great number of online editors that you can visually see what your page will look like while developing your code.
Place this AccRL.asp file into the root directory of our web server. Call up the page though our browser (http:\\localhost\AccRL.asp) and the following output will be seen.
In part 12 we will break down the ASP code and modify. For the complete PLC program, VB source code and web page file please send me an email and ask for the ACC Robust Logger Program. I will be happy to email you the information.
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.