While it is not an everyday requirement, there are plenty of control applications where having a constant scan rate for the controller is a desired approach. In this technical session we will show you how to implement this control strategy in the Horner OCS All-in-one controller.

 




0:40

Good morning everyone and thank you for joining us today.

0:45

Today we are going to talk about use a constant scan rate with Horner OCS and the presentation should last around 11 minutes.

0:54

As always if you have any questions please add them in the question panel and we will go through them at the end. That said let’s get started.

1:04

Hello and welcome to today’s webinar.

1:07

Today we will look at how to use a constant scan rate with Horner OCS. Let’s look at our agenda for today.

1:15

We will do a quick review of what a PLC scan rate is then we are going to go into today’s topic which is using a constant scan rate.

1:23

We will show you how you can lengthen your scan rate along with the describing some scenarios where it is We are going to show you how to do it in a verbal based languages and also with a register based advanced ladder and there will be demonstrations throughout and we will finish with a Q &A session.

1:41

What is a scan rate or controller scan rate?

1:45

It is the amount of time in milliseconds it takes to make one pass through the logic program and one pass through the logic program covers several different steps and we have graphically shown them here on the right.

1:57

You need to read your inputs.

1:59

This is what the PLC does or the OCS-01 controller.

2:02

In the case of most corner products, the controller reads the inputs, then it solves the user logic, writes outputs that need to be changed, performs some housekeeping and does it all over and over again.

2:15

And as an example, your scan rate might be about 2.5 milliseconds for instance.

2:21

Generally, we think of PLC scan rates or controller scan rates of being constant.

2:26

In other words, it always takes the same amount of time to go through the program.

2:31

But that is not entirely true and there are a variety of reasons why the scan rates vary slightly from scan to scan.

2:38

Different machine conditions can occur so that different proportions of the logic or different instructions are being executed on a particular scan or in the housekeeping section there and that is where things are like network connections are taken care of, potentially reading or writing from a memory card.

2:55

There are a variety of other functions that a modern PLC or a modern controller needs to take care of which have an impact on the scan, but even most modern PLCs and all-in-one controllers have a scan rate of in the 10 milliseconds or less type range unless you have a large program or you are dealing with a particular basic controller.

3:14

Let’s talk about entering your scan rate to an accessible value in other routes.

3:18

If you just set the controller to its thing, you might have a 2 or 3 ms scan rate, but there is a reason why you want that to be longer, say 10 ms or 30 ms or even 50 ms.

3:32

Now let’s not confuse setting a longer scan rate with time interrupt.

3:36

What is time interrupt?

3:37

Well some PLCs have the capability to set a time interrupt which is a logic routine, not the entire logic in the program but a routine that is executed on a fixed periodic schedule and these were really important when PLCs and controllers had really long scan rates for instance like 50 milliseconds was typical or even a hundred milliseconds was also typical and you had a routine you wanted to make sure got executed at least every 10 milliseconds for instance so time interrupts were really important and that ensured that section of logic was scanned much faster than the overall logic but what we are talking about today is taking what would normally be a shorter scan and lengthening it to a longer one and why would you want to do that?

4:21

This is not something you would need to do often but there are a couple of solutions where setting a constant or longer scan rate can be useful.

4:28

One example is in process applications where a longer consistent interval might better match the timing of the process you are controlling.

4:36

Now this does not mean you need to slow down your entire program just to match something like a PID loop.

4:41

Most PID instructions, like the one from the Horner, let you set your own execution rate independently.

4:48

So if you want a PID to run every 100 milliseconds, you can do that without affecting the rest of the logic.

4:54

But where this comes in handy is during a retrofit project.

4:57

Say you are replacing an older controller with a much faster one, you might start seeing machine sequences acting up or getting stuck.

5:04

That is often due to race conditions that did not show up before because the old controller slower scan rate was masking them.

5:12

Ideally you would fix those phrase conditions in the logic.

5:15

However when a median machine operation is necessary a particular short-term solution is to configure the new controller to match the scan rate of the original.

5:24

For example if the previous controller operated at approximately 30 milliseconds and the new one runs at 3 milliseconds you can apply the technique demonstrated in today’s presentation to adjust a new controller’s scan rate to 30 milliseconds. How are we going to accomplish that?

5:41

Well what we do is we stretch out the logic portion out of the scan rate to what our target is so if we are looking for about 30 milliseconds scan rate instead of just putting our logic in and letting it execute as fast as possible.

5:55

We can add a little bit of logic to the end of our user logic where that will be stretched out to a desired level.

6:01

So that is what we are talking about in today’s presentation so what might have taken two or three milliseconds would now take about 30 milliseconds. How can we accomplish this?

6:11

Well that is what we are going to review today with the logic examples we have for you.

6:16

But one thing we want to highlight before we get in there is that there are some system registers available in the Horner RCS that you can use to tell what the scan rate is and the one that is most practical for this application is average scan which is SR6 and that is the average of the last five scans is the system register will tell you.

6:34

For our demonstration today let’s start by taking a look at this program which is a register based advanced ladder and typically what we would have in our main routine here is this.

6:45

This is where all our loser logic from the existing program would be.

6:49

So generally let’s say if you have got a 15 year old program or a 10 year old program that you are now going to be running and a faster controller and it runs out that is not executing the way you expected probably because of some race conditions then what you are going to do is you are going to add some additional logic to lengthen the scan.

7:10

So what we have done here is we have left the main loop alone, the main set of the logic alone and we have added something called a constant scan routine.

7:18

However because this is a racetrack based logic you are going to have to make sure that you do not have any racetrack conflicts between this added logic here and the adding it to.

7:31

So almost certainly you are going to need to add or to change these register references here in this example program to make everything work the way it should into some unused register areas.

7:42

Now there are not a lot of registers that are used by this routine so there are 6% Rs and 2% Ts so not much to it here.

7:51

So that is not a lot to have to remap in the variable based languages.

7:55

Here is the logic you are going to be adding Again you would need to remap those 6 registries and those 1 or 2 T bits to unused areas but what is happening is, in this added routine you are going to set your target scan, let’s say that the program that was running in the old controller was running at 25ms, well in that scenario you are going to want to set that run to set your target scan rate to 25ms.

8:20

The default is 30, so to set it to 25 you would set this move block here with a source 250 because it is in tenths of a millisecond.

8:30

So that would need to be changed after you have remapped your registries and then by adding this routine we have got about six runs.

8:37

By adding these six runs here after remapping and setting your target scan rate, now you are going to have a result of a longer scan rate.

8:45

Because what this routine is going to do is it is effectively going to be looping until the scan rate matches what it needs to match.

8:52

let’s take a look at how this works on the bench.

8:55

Here it is on the bench and with our example program you can see we have set our target scan rate 30 milliseconds.

9:02

We have got enable bit here and we have turned on to enable this constant scan rate and as you can see we are in the range of 29 to 31 milliseconds continuously so it is not exactly 30 but it’s around 29 to 31 approximately.

9:17

Now if we were to disable this logic you would see that the scan rate when it is not in fixed mode and that is below 2 milliseconds so you can see how there is a vast difference between having a logic enabled and having the logic disabled and so if you are trying to lengthen your scan rate for the reasons we have given you this is a way to accomplish that.

9:38

Now let’s show you how to do the same lengthening of your scan but this time with our variable based language option including variable based advanced ladder in the IEC.

9:47

Let’s start with the variable based advanced ladder.

9:50

So what we have done here is we have created a user defined function block here that incorporates all the logic that we just talked about with the register based approach and so this is the user defined function block that you can import into your project that has three inputs.

10:06

It has an input for linking it to the system register that contains your average scan rate value. It has another input which is your target scan rate.

10:15

Remember that is in tenths of a millisecond and that is another integer.

10:19

And then we have an enable bit.

10:21

Now if you were starting with an existing variable based program the first step you would have to do is to import the user defined function block into your program. How do you do that?

10:31

Well you go to the logic modules and you right click and say import logic modules and then you navigate to the directory that has the file in it and then once you have imported that file it is going to show up here under UDFB modules.

10:46

It is also going to show up here in your project toolbox under UDFBs that have been imported.

10:52

Once it is here then you can drag it into your program like we previously did and then you can assign your variables to the three inputs.

10:59

Now this is unusual UDFB in that it only has input. It does not have output but the results would be the same.

11:06

Once you have your tiger scan rate and you have tied the sr variable here and you have assigned an enable bit then you are good to go and it is going to operate on the bench precisely the way the register based example will. So this is what we need to do for a variable based advanced ladder.

11:23

Now let’s take a look at the IEC if that is the language you are using.

11:27

We will take our IEC example here. What we have here is somewhere at the end of our logic.

11:32

You are going to want to The user defined function block we have created for you in the IAC format.

11:38

And here is the structured text instruction for calling this particular user defined function block.

11:43

As you can see here, we are calling or tying in that user defined function block to our system register.

11:49

We are setting constant for the target and we are enabling it through always on bit.

11:54

This is a very simple way of incorporating that.

11:57

and then if we take a look at the logic here for our target scan rate you will see that we have chosen to write this user defined function block in structured text because it is easy to do so and it involves looping and a lot of the times looping is a scenario where you want to use structured text for that.

12:14

So here is a written version in structured text which is a user defined function block which is being called in the main loop module here.

12:22

That concludes our webinar for Thank you so much for listening and the Q &A session will begin shortly.

12:38

Okay, I’m back. I’m not currently seeing any questions. In this case, let me jump into my screen.

13:03

Okay, I hope you can see it now. As you can see, we don’t have any webinar scheduled over the few weeks.

13:13

And that’s because we are taking a short summer break, we will release the next schedule afterwards and make sure to update everyone by email once it’s ready.

13:26

And if you want to watch any of the old webinars, you can just use this page and scroll down, you’ll be able to see all of them.

13:35

I’d say that’s all for today.

13:38

Thank you all for your presence and I hope to see you in the next webinars.

13:44

Thank you and have a nice day