Category Archives: Programming Example

How to Implement Modbus TCP Protocol using VBA with Excel

We will use Visual Basic for Applications (VBA) to communicate to a PLC using Modbus TCP protocol. Reading ten registers in the PLC and displaying a bar graph in Excel. Previously we have used VB6 to communicate Modbus TCP.
The following steps will be done:

  1. Explain Modbus TCP protocol
  2. Install OstroSoft Winsock Component
    – Winsock API Calls for communication on network
  3. Develop the Excel and VBA application
    (Microsoft Excel 2010)
  4. Communicate to the PLC and sample code
    (Do-More Simulator)

 

The Modbus TCP/IP or Modbus TCP is a Protocol  that is used for communications over TCP/IP networks. This is done on port 502. Modbus TCP does not require a checksum calculation as lower layers already provide checksum protection. You can think of this as a letter being sent and Ethernet TCP/IP acts like an envelope for the Modbus Commands. I will not go into the details of the communication protocol but here are some links to references:
Introduction to Modbus TCP/IP
Simply Modbus – Modbus TCP

 

OstroSoft Winsock Component
OSWINSCK.dll serves as a wrapper for the Winsock API and helps programmers to abstract from the complexity of API calls and focus on application functionality. Works with programming and scripting languages supporting COM.
You will need to download and install the OstroSoft Winsock Component on your computer.
For use with .NET, Visual Basic 4 or 5, Visual C++, ASP, VBA, VBScript, JavaScript or any other language, supporting COM:
1. Download oswinsck.exe

2. Run downloaded file from Windows Explorer or command-line

Hit OK

I use the default directories where the program will be installed. Click the button to install.

Leave the program group to the default so I know what the program is after installation. Click continue.

Click OK
The OstroSoft Winsock Component is now installed.

Start Microsoft Excel.


Select ‘Developer’ along the top tabs.

If the Developer tab is not present then we must turn on the developer tab.
Select File | Options Select ‘Customize Ribbon’Check the ‘Developer’ under Main Tabs.

Under the Developer menu. Select ‘Visual Basic’
The Visual Basic Editor window will now be displayed.
From the menu – Tools | References
We can now add the OstroSoft Winsock Component to our application.
Select OK
Select Sheet1(Sheet1).

Now put the visual basic code in the Sheet1(Sheet1)
Here is the code:

‘This example uses OstroSoft Winsock Component
‘http://www.ostrosoft.com/oswinsck.asp

Option Explicit

Dim bytesTotal As Long
Dim sPage As String
Dim MbusQuery
Dim returnInfo
Dim wsTCPgdb
Dim WithEvents wsTCP As OSWINSCK.Winsock
Dim SetObject
Dim RetrieveData

Private Sub CommandButton1_Click() ‘ Retrieve Data
On Error GoTo ErrHandler
  Dim sServer As String
  Dim nPort As Long
  Dim StartTime
 
  DoEvents
  nPort = 502 ‘ See configuration in Do-More Designer
  ‘ Set the IP address of the PLC
  sServer = Sheets(“Sheet1”).Range(“B4″) ‘”192.168.1.3”
  RetrieveData = 1
  CommandButton1.BackColor = “&H0000FF00” ‘ Set colour to Green

‘Check to see if the object has been created. If not set wsTCP.
If SetObject = “” Then
Set wsTCP = CreateObject(“OSWINSCK.Winsock”)
wsTCP.Protocol = sckTCPProtocol
SetObject = 1
  End If

‘ Check the state of the TCP connection
‘0 sckClosed connection closed
‘1 sckOpen open
‘2 sckListening listening for incoming connections
‘3 sckConnectionPending connection pending
‘4 sckResolvingHost resolving remote host name
‘5 sckHostResolved remote host name successfully resolved
‘6 sckConnecting connecting to remote host
‘7 sckConnected connected to remote host
‘8 sckClosing Connection Is closing
‘9 sckError error occured

‘ If TCP is not connected, try to connect again.
If wsTCP.State <> 7 Then
    If (wsTCP.State <> sckClosed) Then
      wsTCP.CloseWinsock
    End If
    ‘ Open the connection
    wsTCP.Connect sServer, nPort
    StartTime = Timer ‘ Use the timer to determine if a connection cannot be made
    Do While ((Timer < StartTime + 2) And (wsTCP.State <> 7))
        DoEvents
    Loop
    If (wsTCP.State = 7) Then
    Else
       Exit Sub
    End If
End If

‘ If we are connected then request the information.
If (wsTCP.State = 7) Then
    MbusQuery = Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(0) + Chr(6) + Chr(0) + Chr(3) + Chr(0) + Chr(0) + Chr(0) + Chr(20)
    wsTCP.SendData MbusQuery ‘Send out the Modbus Information
    ‘ Read the information
    ‘0000:    Transaction Identifier
    ‘0000:    Protocol Identifier
    ‘0006:    Message Length (6 bytes to follow)
    ’00:      The Unit Identifier
    ’03:      The Function Code (read MHR Read Holding Registers)
    ‘0000:    The Data Address of the first register
    ‘0002:    The number of registers to write
   
    ‘ Write the information
    ‘0000:    Transaction Identifier
    ‘0000:    Protocol Identifier
    ‘0009:    Message Length (6 bytes to follow)
    ’01:      The Unit Identifier
    ’16:      The Function Code (read Analog Output Holding Registers)
    ‘0000:    The Data Address of the first register
    ‘0001:    The number of registers to write
    ’02:      The number of data bytes to follow
    ‘0030     The number to put into the register
   
    ‘ Note: Addresses are offset by 1
    ‘   Example: MHR1 = Address 0000
    ‘   Example: MHR30 = Address 0029
   
End If
  Exit Sub

ErrHandler:
  MsgBox “Error ” & Err.Number & “: ” & Err.Description
End Sub
Private Sub CommandButton2_Click() ‘ Stop the communication
RetrieveData = 0
CommandButton1.BackColor = “&H8000000F” ‘ Set the default colour
End Sub

Private Sub wsTCP_OnDataArrival(ByVal bytesTotal As Long)
  Dim sBuffer
  Dim i
  Dim MbusByteArray(500)
  Dim h As Integer
  Dim txtSource
wsTCP.GetData sBuffer
  txtSource = txtSource & sBuffer
 
Dim j As Byte
returnInfo = “”
For i = 1 To bytesTotal
    wsTCP.GetData j, vbByte
    MbusByteArray(i) = Asc(Mid(sBuffer, i, 2))
    returnInfo = returnInfo & Asc(Mid(sBuffer, i, 2))
Next
 txtSource = returnInfo
 txtSource = Val(Str((MbusByteArray(10) * 256) + MbusByteArray(11)))
 Sheets(“Sheet1”).Range(“B10”) = Val(Str((MbusByteArray(10) * 256) + MbusByteArray(11)))
 Sheets(“Sheet1”).Range(“B11”) = Val(Str((MbusByteArray(12) * 256) + MbusByteArray(13)))
 Sheets(“Sheet1”).Range(“B12”) = Val(Str((MbusByteArray(14) * 256) + MbusByteArray(15)))
 Sheets(“Sheet1”).Range(“B13”) = Val(Str((MbusByteArray(16) * 256) + MbusByteArray(17)))
 Sheets(“Sheet1”).Range(“B14”) = Val(Str((MbusByteArray(18) * 256) + MbusByteArray(19)))
 Sheets(“Sheet1”).Range(“B15”) = Val(Str((MbusByteArray(20) * 256) + MbusByteArray(21)))
 Sheets(“Sheet1”).Range(“B16”) = Val(Str((MbusByteArray(22) * 256) + MbusByteArray(23)))
 Sheets(“Sheet1”).Range(“B17”) = Val(Str((MbusByteArray(24) * 256) + MbusByteArray(25)))
 Sheets(“Sheet1”).Range(“B18”) = Val(Str((MbusByteArray(26) * 256) + MbusByteArray(27)))
 Sheets(“Sheet1”).Range(“B19”) = Val(Str((MbusByteArray(28) * 256) + MbusByteArray(29)))

DoEvents
‘ Determine if we retrieve the data again.
If RetrieveData = 1 Then
    Call CommandButton1_Click
End If
End Sub

Private Sub wsTCP_OnError(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
  MsgBox Number & “: ” & Description
End Sub

Private Sub wsTCP_OnStatusChanged(ByVal Status As String)
  Debug.Print Status
End Sub

Note: The program utilizes the CHR and STR functions to convert the data from binary to ASCII and back.
The highest value of a byte of data is 256. This is why we have to multiply the highest significant byte with 256

Interface:
Go back to Sheet1 and we can now put on the worksheet what we would like to see.

Note the following:
IP Address = B4
MHR 1 to 10 values located at B10 to B19
‘Stop Data’ – CommandButton2
‘Retrieve Data’  – CommandButton1

 

Communication to the PLC

Start the Do-More Designer software.
Under the Project Browser select ‘System Configuration’

Make note of the IP address. If you are running the simulator then this is automatically filled in.

Ensure that the Enable Modbus/TCP Server is checked. Also make sure that the TCP Port Number is 502.

The sample PLC program will write values in the range from 0 to 4000. These values will be put in MHR 1 to MHR 10.

Here is the first couple of rungs of the PLC program. It will use clock bit flags to increment the MHR 1 channel. When it gets to the value above 4000, a move instruction will put a 0 back into MHR 1.
If input X0 turns on then the value in XW0 will be moved into MHR1 and the previous clock bit will not be in effect. Values will be between 0 and 4096. (12 bit resolution)

This is repeated with different internal clock bit flags up to MHR10.

Running the program will produce the following:

As you can see the Modbus TCP protocol is easy to implement with visual basic for applications.
Download the PLC program and Excel file.

Additional Information:
Excel – Conditional Movement of Data

Watch on YouTube : How to Implement Modbus TCP Protocol using VBA with Excel
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.

Implementing the Omron CX Server DDE and Excel

Utilizing the CX Server DDE Manager will allow us to provide a link to the information in the Omron PLC. This link can be placed on an Excel spreadsheet. Charts, graphs, etc. can be made from the data. We will create links on an excel spread sheet from a CQM1H and a CP1L PLC. The information will then be displayed as a bar graph comparing the first ten memory areas.

Dynamic Data Exchange (DDE) is a channel through which correctly prepared programs can actively exchange data and control other applications within Microsoft Windows. The DDE manager will allow us to set up all of the links.

Start the DDE Manager by clicking Start/Programs/Omron/CX-Server/DDE Manager

This will start the DDE Manager and place an icon on your toolbar at the bottom of your screen. The application will run minimized.

Right-click on the minimized DDE Manager icon and select Project/New.

Assign a filename (ACC DDE.cdm) to the CX-Server project that you will create, and save it.

The create project will minimize to the taskbar. Right-click on the minimized DDE Manager icon and select Project/Edit.

This will call up the DDE Manager Project Editor. We can now add the PLC’s (Devices) and Points that we want to display.

Select File/New/PLC, or hit the PLC Icon on the taskbar.

Under Change PLC, we can now enter the information about how we are communicating to the programmable logic controller.

Device Name: – Name in which the DDE Manager will call the PLC
Device Type: – The model of PLC that will be connected
Network Type: – This is the communication method that we will be talking with the device.

In our example we will use the following two Omron PLCs.

  • CQM1H – SYSMAC WAY (Omron Host Link Protocol) Communication Port  11, 9600, E, 7, 2. Unit #00
  • CP1L – USB

 Once we have the PLC information, we can now add points that will contain the information that we wish to retrieve from the units. Select File/New/Point  or select the point editor icon to start the point editor.

On the Logical tab you can give a name (Or Change) to the point in the PLC to get. Select the Physical tab.

On the physical tab we set the following information:
PLC: – This is the list of PLCs entered in the previous step
Data Location: – The memory location that we want to read from
Internal Data Type: – This is the interpretation of the data that we are reading. (Example: Bit, Word, BCD, etc.)
Command Modifier: – This is used if we need to Force Set / Reset the data location. This can be used to override the PLC program. Use with caution.
Press OK when finished setting the address.

 Our point is now programmed. You will notice the symbols before the name of the point. This tells us at a quick glance what type of data we are looking at. Please refer to the CX Server Runtime manual for all of the symbol meanings.

Fill out the remaining points for our example.
CP1L – D0 to D9
CQM1H – DM0 to DM9

Start Microsoft Excel.

Go back to the DDE manager and the points under the Project Editor. We can now select the first ten items in the list. Click the first one and then move to the last item. Hold the shift while clicking the last item will select all of them between.
Hit the DDE Link icon.

In Excel, we now paste the information onto the worksheet. (Ctrl + V) Right click the cell and select paste.

The information will now be displayed and updated  on your worksheet.
The update time will depend on the interval set in the DDE Manager. Right-click on the minimized DDE Manager icon and select Update Interval…

We can also set individual point update times in the DDE link item. The default update time is set via the DDE Manager but we can also set the time in the individual points on the spreadsheet.
DDE Update Default Link:
=CDMDDE|’C:\ACC DDE.cdm’!’\CP1L D0′
5 Second Update Link:
=CDMDDE|’C:\ACC DDE.cdm’!’\CP1L D0,5′

In the Project Editor of the DDE Manager you can see the first 10 memory areas are being used. This is the yellow triangle with the lightning bolt symbol. (You will not be able to delete the point if it is in use.)

Calling up an excel file with the links embedded, will give you a Security Alert – Links warning. Select ‘Enable the content’ and then hit OK.

Here is an example of the finished excel file. We have 10 memory locations from each PLC listed. We have inserted a graph that will dynamically change when the values are read.
Download the excel file here.

 As you can see implementing the CX Server DDE Manager is not a difficult task. It provide a quick and efficient way to view the information that we need.

Additional Information:
Excel – Conditional Movement of Data

Watch on YouTube : Implementing the Omron CX Server DDE and Excel
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.

Here’s is a quick way to send email (text) messages from the PLC

Sending email messages from the PLC sounds like an easy task. However, very few applications do this on the production floor. This is probable due to the networks involved and using authentication can be complicated. In our example we will use a restricted Gmail SMTP server so no authentication will be required. We will walk through sending email and text messages from the PLC to Google Gmail. Once in your Gmail account, the message can be automatically forwarded to another verified email or SMS text message address.

Simple Mail Transfer Protocol (SMTP) is an internet standard for email transmissions.

Google provides three different SMTP settings in which you can send email messages from a printer, scanner or application (PLC).

  1. SMTP relay service – used to send mail from your organization by authenticating with the IP address(s). You can send messages to anyone inside or outside of your domain.
  2. Gmail SMTP server – requires authentication with your Gmail/Google Apps account and password. Messages can be sent to anyone inside or outside of your domain.
  3. Restricted Gmail SMTP server – does not require authentication, and you will be restricted to send messages to Gmail or Google Apps users only.

We will use restricted Gmail SMTP server to send emails and text messages. This is located at aspmx.l.google.com. This does not require authentication so a greater number of PLC’s will be able to communicate to the server.

If you do not have a Google Gmail Account then you will need to set up this free service. Google Email Account

Now start the Do-more Designer software. This is available free of charge and is a fully functional package complete with a simulator. We will be using the simulator for our example. The actual Do-More PLC will have to have an Ethernet connection on board connected to the internet. (H2-DM1E)

Start a new project with the simulator or an existing project that has connection to the internet.

Under ‘Project Browser’: ‘Tools’ select ‘System Configuration’

In ‘CPU Configuration’ verify the IP address and Net Mask. This will be automatically populated when using the Do-more Simulator.

Hit the “Configure…” button if the IP address needs to be modified.

In ‘System Configuration’ select ‘Device Configuration’

Select “New Device” (If you do not already have a SMTP Client (Email) configured. If you do then select it and hit “Edit Device”)

Select ‘SMTP Client (Email)’ and hit ‘OK’

Beside the ‘Device Name’ enter a name for the Email Client. Ex: @MyEmailClient Beside the ‘SMTP Server IP Address’ hit the ‘DNS Lookup…’

Beside the URL: enter the server address aspmx.l.google.com and then hit ‘Lookup’. This will retrieve one of the IP addresses of the server. Then press ‘Select’ to return this address to the configuration page.

Ensure that the SMTP Server Port is set for 25. This is the default port setting. The Timeout setting can be left at 30 seconds. This is the amount of time for the PLC to wait before setting any error message. Enter your ”‘From’ Email Address” – Enter your Google Gmail account address. Select ‘OK’ to end the configuration. 
Ensure that authentication is disabled.

Now that we have our email client device ‘@MyEmailClient’ set up we can move onto programming the Email messages.

We use the EMAIL instruction in the PLC to send the messages. We will send two messages; one will be an email and the other a SMS text message. The subject line will be different to distinguish the two.

Here is the PLC program for sending both messages.

You will notice that the messages are triggered by a one shot.


Notice in the message we combine text with actual word and bit addresses that we want to send. The help function in the Do-more Designer software can provide further information.

Running the program and triggering the messages will send the Email to your google account.

You will notice if you open the message, a warning is given. ‘This message may not have been sent by’ appears because authentication is turned off. We can just ignore this message.

We need to now set up the Email forwarding to any account.

Under the gear sign in Google Gmail select the ‘Settings’.

Select ‘Add a forwarding address’

This will bring up a dialogue to now forward Email to a specific account. During this process a verification code will be sent to this address. You must enter this code for validation or respond to the Email in order for the forwarding address to work.

Email to SMS Gateways can be used to forward your message in a text format. Here is a website that will show a List of Email to SMS Gateways.

Here are some that we use in Canada: Example: 613-451-0104 on Rogers network = 6134510104@sms.rogers.com

  • number@txt.bellmobility.ca
  • number@sms.wirefree.informe.ca
  • number@sms.fido.ca
  • number@msg.telus.com
  • number@sms.lynxmobility.com
  • number@text.mtsmobility.com
  • number@mobiletxt.ca
  • number@sms.rogers.com
  • number@sms.sasktel.com
  • number@vmobile.ca
  • number@txt.windmobile.ca
  • number@sms.wirefree.informe.ca

Once we have the forwarding address in and verified, we can move onto the last step, which is creating a filter. The filters will allow automatically look at the incoming Email message and perform an action on the message. In our case we will be forwarding the message.

Under the settings menu, select ‘Filters’ and then ‘Create New Filter’

The first page contains the items that we are looking for in the filter. Fill in the address of the sender, which will be our Gmail account and the subject. The subject will be ‘ACC PLC _ GMail Text’.

Select ‘Continue >>’

Our filter parameters appear at the top of the screen. Now we can determine what to do when a message arrives.

  • Mark as read
  • Forward it to: (Select forwarding address)
  • Never send it to Spam

You can create as many filters as you wish. Sending to multiple accounts requires only to repeat the filter with the additional email addresses.

In the above example we used a restricted Gmail SMTP server. No authentication was required so we can send email with only an internet connection to the PLC.

Watch on YouTube : Here’s is a quick way to send email text messages from 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.

What Everybody Ought to Know About PLC Programming Languages

PLC programs are normally written in a special application on a personal computer, then downloaded to the PLC. This downloaded program is similar to compiled code to keep the program efficient. The program is stored in the PLC either in battery-backed-up RAM or some other non-volatile flash memory.

Albert Einstein said “The world as we have created it is a process of our thinking. It cannot be changed without changing our thinking” PLC programming languages have evolved to both adapt and change the way we program these units. We will look at all five programming languages as defined by the IEC 61131-3 Standard.

  • Structured Text (ST)
  • Function Block Diagram (FBD)
  • Sequential Function Chart (SFC)
  • Instruction List (IL)
  • Ladder Diagram (LD)

Not all of these programmable controller languages are available in every PLC. Ladder logic programming is by far the largest percentage of use in PLC’s today. Fundamental concepts of PLC programming are common to all manufacturers. Differences in I/O addressing, memory organization, and instruction sets mean that PLC programs are never interchangeable between different makers. Even within the same product line of a single manufacturer, different models may not be directly compatible. This is true when looking at manufactures that private label other controllers.

Estimates are as high as 95% of installations use ladder logic programming in the programmable logic controller.

The PLC programming language that is used can be decided when you look at the following:

  • Maintenance and troubleshooting
  • Knowledge of language
  • Acceptance of the country, location, or individual plant
  • Application of the PLC
  • Ease of changing PLC program

The actual programming of the PLC is the second last step in the development of programs. The five steps to PLC program development is a good method to follow before picking what programming language to use. As mentioned before the languages supported by each PLC may differ. Please refer to the types of programming that are available for your model and version of PLC.

Let’s quickly review some of the different programming languages for the PLC.

Structured Text (ST) is a high level programming language that closely resembles Pascale programming. Statements are used to define what to execute.

Function Block Diagram (FBD) is a graphical representation of AND, NAND, OR, NOR gates, etc. that are drawn. It will describe the function between input and output variables.

Sequential Function Chart (SFC) is like a flowchart of your program. It defines the steps through which your program moves.

Instruction List (IL) can also be referred to as mnemonic code and statement list. It contains simple instructions for looking at your variables.

Ladder Diagram (LD) is the most popular programming language for the PLC. It was written to mimic the mechanical relays in the panel that the programmable logic controller replaced. It has two vertical rails and a series of horizontal rungs between them. Controllers will usually scan from left to right top to bottom. The output of one rung is available for the next rung.

Note: All pictures from PLCopen IEC 61131 Basics

PLC programming methods are evolving. PLC Open is an organization that is defining new methods to take advantage of the latest computer innovations. They have defined the IL method of programming to XML (Extended Markup Language) which is used for web development. This in my opinion keeps moving the ideal method, to a standard way to program PLCs.

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.

PLC Programming Example – Paint Spraying

We will look at a PLC basic tutorial of a paint spraying station. Following the 5 steps to program development this PLC programming example should fully explain the procedure for developing the PLC program logic. Ladder will be our PLC programming language.

We will be using the Do-more Designer software which comes with a simulator. This fully functional program is offered free of charge at automation direct.

Define the task:

What has to happen?

Paint spraying system where boxes are fed by gravity through a feeder magazine one at a time onto a moving conveyor belt. Upon the start signal, boxes are pushed towards the conveyor by valve 1. This is a cylinder which extends and retracts which operates switches S1 and S2 respectfully. A spraying nozzle paints each box as it passes under the paint spray controlled by valve 2. A sensor (S3) counts each box being sprayed. When 6 boxes have been painted the valve 2 shuts off (paint spray) and valve 1 (cylinder) stops moving boxes onto the conveyor. Three seconds later the conveyor stops moving and the hopper with its load moves forward (valve 3) where it is emptied. Ten seconds later the hopper returns to the original position. The cycle is then complete and waits for a start signal again.

Define the Inputs and Outputs:

Inputs:
Start Switch – On/Off (Normally Open) – NO
Stop Switch – On/Off (Normally Closed) – NC
S1 – Valve 1 (cylinder retract) On/Off – NO
S2 – Valve 1 (cylinder extend) On/Off – NO
S3 – Box Detected- On/Off – NO
Outputs:
Motor – On/Off (Conveyor Run)
Valve 1- Cylinder to feed boxes – On/Off
Valve 2- Paint Spray – On/Off
Valve 3- Cylinder to move hopper – On/Off

Develop a logical sequence of operation:

Fully understanding the logic before starting to program can save you time and frustration.

Sequence Table: The following is a sequence table for our paint spraying application.


1 – Input / Ouput ON
0 – Input / Output OFF
x – Input / Output Does not Matter
When power goes off and comes on the sequence will continue. This means that we must use memory retentive areas of the PLC. The stop pushbutton will stop the sequence. The start will resume until the end.

Develop the PLC program:

The best way to see the development of the programmable logic controller program is to follow the sequence table along with the following program. You will see the direct correlation between the two and get a good understanding of the process.

This is the main process start and stop bit. V0:0 is used because it is memory retentive.

Control of the Motor (Conveyor) and the paint spray is done with the V0:0 contact in front of the actual PLC output. The conveyor and paint spray will stop when the timer 0 is done. This is the delay after the last box is detected to allow the box to be painted and loaded onto the hopper.

Control of the box movement onto the conveyor. As long as we have the process start and the hopper count is not complete this will allow the cylinder to put boxes on the conveyor.

Count number of boxes in the hopper via S3. The counter is memory retentive.

Timer to stop the conveyor and spray after the last box is detected for the hopper. This will allow time for the box to be sprayed and loaded into the hopper.

Hopper movement to load and unload the boxes.

The hopper unload timer is to unload the boxes and will then trigger the reset conveyor timer, box counter and the process start bit (V0:0).

Test the program:


Test the program with a simulator or actual machine. Make modifications as necessary. Remember to follow up after a time frame to see if any problems arise that need to be addressed with the program.

Watch on YouTube : PLC Programming Example – Paint Spraying
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.

PLC Programming Example – Shift Register (Conveyor Reject)

Allot of times when programming a PLC you need to track what has previously happened. Shift registers allow you to do just that. We will look at a PLC basic tutorial of a conveyor belt and reject station. Following the 5 steps to program development this PLC programming example should fully explain the function of shift registers. Ladder will be our PLC programming language.

We will be using the Do-more Designer software which comes with a simulator. This fully functional program is offered free of charge at automation direct.

Define the task:

What has to happen?

A start pushbutton (NO) is used to start the conveyor and a stop pushbutton (NC) is used to stop. Sensor B detects product on the conveyor belt and sensor A will detect if it is too large and needs to be rejected. The product is tracked along the conveyor belt and when under the reject station the Reject Blow Off will expel the bad product. Product is randomly placed on the conveyor belt, so an incremental encoder is used to track the conveyor movement. The reset pushbutton (NO) will signal that all of the product on the conveyor has been removed between the sensors and reject blow off.

Define the Inputs and Outputs:

Inputs: Start Switch – On/Off (Normally Open) – NO Stop Switch – On/Off (Normally Closed) – NC Reset Switch – On/Off – NO Motor Encoder – On/Off – This will give a discrete signal when the conveyor is moving. It picks up the movement of the free wheel. Sensor A (Part Reject) – On/Off – NO Sensor B (Part Present) – On/Off – NO

Outputs: Motor – On/Off (Conveyor Run) Air Blow Off – On/Off (Reject)

Develop a logical sequence of operation:

Fully understanding the logic before starting to program can save you time and frustration.

Sequence Table: The following is a sequence table for our conveyor reject application.

It is a simple sequence table, but clarifies the following: When power goes off and comes on the sequence will continue. This means that the shift sequencer must be memory retentive. Sensor A and B must be on to get tracked with a shift register.

Shift Registers: The Shift Register (SR) instruction shifts data through a predefined number of BIT locations. These BIT locations can be a range of BITs, a single Word or DWord, or a range of Words or DWords. The instruction has three inputs. Data, Clock and Reset. The data input will load the beginning bit with a ‘1’ if it is on or ‘0’ if it is not. Clock input is used to shift the data through the shift register. In our example, we will be using the encoder on the conveyor to track the reject container. So each pulse of the clock represents a distance on the conveyor. The last input is the reset. It will place ‘0’ in all of the bits within the shift register.

Develop the PLC program:

Start and stop of the conveyor motor.

Shift register to track the rejected parts. This will move the bits with each pulse of the encoder. Note that the ‘V’ memory is used because it is memory retentive.

This will look at the bit in front of the reject station. We can measure and count off the length (conveyor) and then find out what the bit location will be at the reject location.

Test the program:

Test the program with a simulator or actual machine. Make modifications as necessary. Remember to follow up after a time frame to see if any problems arise that need to be addressed with the program.

Notes: Sometimes you can use multiple shift registers in your program. This can be helpful if you want to actually track the container as well as the rejects. You could also use bit shift right (BSR) and bit shift left instructions (BSR) to do the same thing as we did with the shift register instruction. In the Do-more PLC it is rotate left (ROTL) and rotate right (ROTR) instructions. Always check your instruction set of the controller that you are working with before starting to program.

Watch on YouTube : PLC Programming Example – Shift Register (Conveyor Reject)

Additional information on shift registers can be seen at the following URL:
http://accautomation.ca/plc-programming-example-sorting-station-shift-register/
This PLC programming example will look at sorting coloured tags into three different exits. The 3D simulation will use three different shift registers to trigger when to direct the correct colour tag.
Watch the sequence of operation video below.
Watch on YouTube : PLC Programming Example – Sorting Station Testing

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.

PLC Programming Example – Process Mixer

We will apply the five steps to PLC Program development to our next programming example of a process mixer.

1 – Define the task:


A normally open start and normally closed stop pushbuttons are used to start and stop the process. When the start button is pressed, solenoid A engergizes to start filling the tank. As the tank fills, the empty level sensor switch closes. When the tank is full, the full level sensor switch closes. Solenoid A is de-energized. Mixer motor starts and runs for 3 minutes to mix the liquid.  When the agitate motor stops, solenoid B is engergized to empty the tank. When the tank is completely empty, the empty sensor switch opens to de-engergize solenoid B. The start button is pressed to repeat the sequence.

2 – Define the Inputs and Outputs:

Inputs:
Start Pushbutton – Normally Open – On/Off
Stop Pushbutton – Normally Closed – On/Off
Empty Sensor Switch – On/Off
Full Sensor Switch – On/Off
Timer 3 minutes done bit – On/Off (Internal)

Outputs:
Mixer Motor – On/Off
Solenoid A – Fill – On/Off
Solenoid B – Empty – On/Off
Timer 3 minutes – (Internal)

3 – Develop a logical sequence of operation:

A flow chart or sequence table is used to fully understand the process.  It will also prompt questions like the following.

What happens when electrical power and/or pneumatic air is lost? What happens when the input / output devices fail? Do we need redundancy?

This is the step where you can save yourself allot of work by understanding everything about the operation. It will help prevent you from continuously re-writing the PLC logic. Knowing all of these answers upfront is vital in the development of the PLC program.

4 – Develop the PLC program

Since we need to continue the sequence when the power goes off then memory retentive locations in the PLC must be used. In our example we will use the ‘V Memory’ locations.

The first thing in our program is to control the start and stop functions. This is done through a latching circuit. From the sequence table we know that to reset the sequence we need to have the timer done and the empty sensor off.

The filling of the tank is done through Solenoid A. It is turned on by the start signal and off by the full sensor switch. (Sequence Table) You will notice that we have a memory retentive output and the actual output to active the solenoid.

The memory retentive timer will start timing when we have the start sequence signal and when the empty and fill sensors are on. The timer will reset when the empty and fill sensors are off. Mixing motor will be on when the timer is timing and when the timer is not done.

Solenoid B turns on to empty the tank when the timer is done and the full and empty sensors are on. It will reset when the empty sensor switch goes off.

5- Test the program

Test the program under many conditions. Check to see what happens when power is removed.

Using this five step to program development technique will shorten your programming time. The result will be a better defined logic and easier to understand program, because it has within the documentation the logic flow chart or sequence table.

Watch on YouTube : PLC Programming Example – Process Mixer

Factory IO provides a 3D simulation of the process. Testing of the program is important and should be done in a variety of ways. Factory IO provides a straight forward method of seeing your program in action before you wire your application.

We will be using the BRX PLC Modbus TCP Server (Slave). Factory IO will be the Modbus TCP Client (Master). When the tank fills up we will start a dwell time instead of the mixer time for the simulation.
Here is the mapping of the inputs and outputs using Factory IO.

Factory IO Website is at the following URL:
https://factoryio.com/
Documentation is well done. Start at the ‘Getting Started’ at the following URL:
https://factoryio.com/docs/

You can download the PLC program and Factory IO scene here.

Watch the following video to see this simulation in action.

Watch on YouTube : Process Mixer Test Simulation
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.