EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)

Video: https://youtu.be/eHfJ3C5lhKA

#PLC #TwinCAT3 #Beckhoff #Motion_Control #Hardware #Industrial_Automation #Redes_Industriales

🔙 Previous Part | Next Part 🔜

↩️ Go Back

Related Notes:

Table of Contents:


A) Test Bench Walkthrough

Welcome back Internet learners. Let continue a bit from [[EP2 - Tour of the Test Bench]]

A.1) EtherCAT master

We're back at the test bench here just for a second so I can show you how this [[EtherCAT]] system is wired up,

these are both Network cards on top of the PLC here, on the left side the yellow one we're dedicating to [[EtherCAT]] whereas the other one is gonna handle our regular [[TCP/IP networking]],

With this [[Ethernet]] cable is how we program the PLC.

In practice it wouldn't necessarily need to be there but modern days pretty much everybody runs some sort of networking to their PLC's.

A.2) E-bus slices

And then of course you get the [[E-bus]] out this other side for anything that's gonna be in the cabinet with the PLC,

we typically just run those [[E-bus slices]] right there and not bother with cables. But for servo drives and remote mounted stuff you got to have something to get this [[EtherCAT]] out to a cable so we're gonna dedicate this network card to be an [[EtherCAT master]],

A.3) EK1100 (EtherCAT Coupler)

so if you take a look down here I've got my I/O. This bus coupler right here on the left side is an [[EK1100]],

and what that does is takes an [[EtherCAT]] [[RJ45]] in, sends it back out, but in the middle here it puts all of your [[E-bus slices]] as well,

so you can have these mounted in a remote box somewhere or just somewhere else in the cabinet (if it doesn't make sense to put all these next to the PLC in a line).

You can look closer at its ports here:


A.4) EL3255 Analog Input Potentiometer Slice

So what we've got here is like a [[Potentiometer slice]] on the left there we're not going to mess with that too much.

NOTE: Other Examples of Potentiometer devices,
|200


A.4) EL1008 and EL2008 (digital IO)

An [[EL1008]] and at al [[EL2008]] that's digital input 24 Volt DC and digital output 24 DC,

so you can flip solenoids with this and read sensors with this.

So that comes out at [[EtherCAT]] in this green cable here, and it runs down to the floor back up here,

and yellow here is 24 Volt power to this pod here,

A.5) EP2318 (EtherCAT Box)

that's an [[EP2318]] it's got 4 digital inputs and 4 digital outputs,

so kind of a mixed thing that you might put out on the end of a robot to add a little bit of IO in both directions.

So it goes [[EtherCAT]] into this [[M8 connector]] and it has a spot for an [[M8]] to come back out,

so that can jump over to additional pods and go to other you know back into servo drives or wherever so it's really flexible how you settle this up.


B) STEP 1 - Adding an EtherCAT Master to the Solution

Alright, so we're back on the PC side, right where we left off in the last episode.

I can come in here and add a new device.

This is really cool because you can add all sorts of different stuff:

Note: You can sometimes use built-in drivers like Ethernet/IP if you have an extra network card. You can make it an adapter or a scanner, or use master/slave configurations. You can pull in CANopen, Profibus, and straight-up TCP/IP as well if you want.

So, what we're after here is an EtherCAT master....

Right off the bat, it hasn't been assigned to any hardware,

so we need to tell it, "Hey, you need to be bound to that bottom network card with the yellow cord coming out of it."


B.1) Search for Devices (assign EtherCAT Master rol to a network device)

We'll come over here, and when I'm connected, I've got this PLC targeted....

This means, I'm talking to it in the context of that PLC, so I'll come here and say, Search for devices,

We will see a list of devices found...

Note - PCI Bus

The PCI bus slot is actually the [[E-bus]] going off that right side that I kept pointing to.

We're not going to mess with it right now because I don't need to talk to any of that I/O. We're setting up the stuff that's coming off that other NIC, which will end up being its own EtherCAT master on the system.

This one here, I'll just guess, is the Local Area Connection. I normally like to name these on the PLC, calling one EtherCAT and one LAN, or something similar. Those names will travel through here to make it clearer for debugging. Since I didn't rename them, I'm just going to pick one...

You can see the IP address it got.

Note: The 169.254.67.30 is a link-local address, which means it doesn't have an address. It can talk to other link-local stuff, but it searched for DHCP, and nobody gave it an address, so it's just hanging out. That's what we want because it doesn't need an address to talk on EtherCAT. For that matter, you can go and uncheck the TCP/IP stack on the driver to ensure nobody mixes it up for other stuff accidentally.

It has grabbed the MAC address, which is another way to check that you have the right one.

We know we do because the other one would have an address like 192.168.1.130, which we don't want. This is the one we want, so we're happy.


B.2) Scan for devices (connected to the EtherCAT Master)

Normally, what you do is scan, but there's no option here...

because we're in run mode.

Let's kick this guy back into config mode using this little blue button here.

Load I/O devices? Yes, I don't think that matters for what we're doing, but I always just say yes. It doesn't hurt anything.

Now we come here, we can rename this...

We could name this "local NIC" or something else if we wanted.

We'll scan this,

and it automatically finds all that stuff...


B.3) Reviewing our Scanned cards

B.3.1) EK1100 (EtherCAT Coupler)

Terminal 1 is the [[EK1100 (EtherCAT Coupler)]],
|400

Remember, it is the one that is connected to the PLC,

B.3.2) EL3255 Analog Input Potentiometer Slice

then we've got the [[EL3255 potentiometer slice]],

B.3.3) EL1008 DI and EL2008 DQ

and then the [[EL1008]] and [[EL2008]] cards.

the Yellow Cards is for Inputs, and you can see Channel 1 has its input

and it is an 8-channel card.

Same thing for the Red card, it is for outputs and Channel 1 has its output

It is an 8-channel card as well.

B.3.4) Some troubleshooting indicators

These extra WC state indicators have meaning and can be helpful when debugging. Data valid, data invalid, you can check that to make sure everything's good.

If you collapse that, you get info about things like your slave configured count and slave found count.

There is useful stuff here, but it's more advanced for debugging. For now, we have what we need.

We can look at these values with this handy little graph built in,

but nothing's really going to work yet because this is just our working copy. It's not what the PLC knows about.

B.4) How to Load Configuration to the PLC

Let's Save our progress so far...

and Activate this configuration.

B.4.1) Troubleshooting "task variable" error

NOTE:
This error message says it needs at least one variable linked to a task variable.

Tasks were discussed in the first series ([[ℹ️ Learning TwinCAT with Structured Text by SquishyBrained (MOC)]]), so I won't go into them much more.

But, basically these variables are saying, "Hey, I don't have anything linked to me, so I don't know how fast you want me to run or anything."

So these are essentially not going to do anything right now.

Even if I set one of these outputs here,

it won't actually happen on the slice because something on this network card needs to have a sync master.

You can either make a fake task or link up one of these variables,

which will work if you're just playing around....

But since we have real I/O to mess with, we'll start that process next.


C) STEP 2 - Linking Variables to our Real I/O

Writing code with %Q* and %I*

I'm back in our main program, and I wrote some code offline to save typing.

Essentially,

  1. I've converted the heartbeat over to a byte, which I'll explain in a minute.
  2. Here (one, two, three, four) are just a bunch of bits, basically Booleans, which are either true or false.

Now, this part looks a little confusing, but it's just saying that one exists AT the memory address Q, which means the [[output memory area]].

There's only Q and I memory areas, so don't stress about it.

Star * is where you'd normally put the memory address, but using star lets the mapping system handle it for you, so you don't have to worry about shifting addresses.

People used to put these in manually on older PLCs, but we don't have to anymore. The * symbol represents a placeholder for the actual address.

For Example - older PLC declaration:

For the input, we'll type prox AT %I*.

Once I've done that, we'll increment our heartbeat every scan. And, this code takes the heartbeat, modular divides it,

and checks if it's equal to zero. If it is, it turns the bit on; if not, it turns it off. It's just easy code to make it blink these bits in sequence.

Copy PLC Code:

PROGRAM MAIN
VAR
    heartbeat : BYTE;

	//Outputs
    one AT %Q* : BOOL;
    two AT %Q* : BOOL;
    three AT %Q* : BOOL;
    four AT %Q* : BOOL;
    
    prox AT %I* : BOOL; // Input
    
END_VAR

---------------------------------------------------------

heartbeat := heartbeat + 1;

one := heartbeat MOD 2 = 0;
two := heartbeat MOD 4 = 0;
three := heartbeat MOD 8 = 0;
four := heartbeat MOD 16 = 0;

Linking the variables with the placeholder

I'll save that and build the solution.

It's still complaining about that, but that's okay.

Now that we've built, we should be able to come over here to our Terminal 4, the EL2008, right-click, change link,

and these show up now.

Untitled1 is our PLC's runtime program, and then we have .one, .two, .three, and .four, which are part of the MAIN program.

As soon as you put that %Q* on there and Build Solution, it becomes part of your image.

I can click on it, hit OK

And just like that, we have linked our first variable .one to the Channel 1 of our IO Cards...

We do the same for the other Channels...

Note: There is a way to automate this if you have tons of I/O, but let's not worry about that today.

Our other one, prox, is a %I*, indicating it's an input coming into our program.
We can make decisions based on that value and affect the outputs.

I have wire my input at Channel 5, so there is where I'll make our Link.

STEP 3 - Activate Configuration and Run the Program

Once you save, none of this takes effect until you activate it again...

So, let's do that,

Note: just with I/O changes we require the Activate Configuration, most code changes can be done online without shutting down the system.

Now, I'm activated, I'll log back in...

and hit run...

and you should see these blinking!

These are actually blinking really fast, but this online view shows them slower.

We can check the graph here,

Improving our Example... (using the Input Variable)

Back in our program, I'm not happy with what we've done because we don't utilize the prox at all....

I wrote some more code offline, which says if the prox is TRUE, do our blinky routine, and if not, turn everything off.

Copy PLC Code:

PROGRAM MAIN
VAR
    heartbeat : BYTE;

	//Outputs
    one AT %Q* : BOOL;
    two AT %Q* : BOOL;
    three AT %Q* : BOOL;
    four AT %Q* : BOOL;
    
    prox AT %I* : BOOL; // Input
    
END_VAR

---------------------------------------------------------
heartbeat := heartbeat + 1;

IF prox = TRUE THEN
	one := heartbeat MOD 2 = 0;
	two := heartbeat MOD 4 = 0;
	three := heartbeat MOD 8 = 0;
	four := heartbeat MOD 16 = 0;
ELSE
	one := FALSE;
	two := FALSE;
	three := FALSE;
	four := FALSE;
END_IF

We'll save that, activate it, and we should be good to go.

I've situated the proximity sensor right on top of my inputs and outputs.

This would be analogous to a part showing up on a conveyor, and the outputs would actuate from your program control to fire a pneumatic cylinder or turn on a conveyor zone.

This is a basic I/O example and works similarly for other I/O types, analog stuff, and different voltages, whether turning on a motor or something else through the EtherCAT network and into your PLC.

We'll dig deeper in the next episode. I'll see you in the next one. Bye!


🔙 Previous Part | Next Part 🔜

↩️ Go Back


Z) 🗃️ Glossary

File Definition
EtherCAT EtherCAT – Ethernet for Control and Automation Technology – is a cost-effective, real-time, international standard that makes Ethernet technologies available at the I/O level.
Uncreated files Origin Note
E-bus EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)
E-bus EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)
E-bus slices EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)
E-bus slices EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)
EK1100 EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)
EK1100 (EtherCAT Coupler) EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)
EL1008 EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)
EL1008 EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)
EL2008 EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)
EL2008 EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)
EL3255 potentiometer slice EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)
EP2318 EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)
EtherCAT master EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)
Ethernet EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)
M8 EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)
M8 connector EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)
output memory area EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)
Potentiometer slice EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)
RJ45 EP4 - Beckhoff TwinCAT IO (EtherCAT Master for Digital Inputs and Outputs)