Live demo showing you how to use the PLS (Programmable Limit Switch) instruction to accurately monitor and control high speed processes independent of scan time.
The programmable limit switch instruction works just like a mechanical rotating cam with limit switches - except you can control the shape of the cams in real time. And since it runs on the High Speed Input module – or HSI Module – it’s completely independent of the processor load or scan time. So you always get accurate timing even with high speed inputs. Let’s do an example. For this video we just have an encoder wired into an HSI module like this with both phases and the Z pulse connected. I’ve already configured the HSI module with no scaling, these status tags, and we’re using the encoder’s Z-pulse to reset the count each rotation. Could we have chosen rotary mode where the module automatically rolls the count over for us? Sure, but then we would have to find another way to decide where the home position is. This Z-Pulse option does both for us. We have a 1X multiplier on the encoder input so we’ll get 1024 pulses per revolution. Let’s grab a PLS instruction, make sure we have the right HSI module and channel and create a structure. This row of this table represents ONE of the cams with these four guys being the contacts that open or close as the cam rotates. We refer to this row as a “switch.” We can create up to 16 switches per HSI input channel. We’ll use 4 of the switches in this demo. In our example, one revolution is 1024 counts of the encoder. So if we visualize a CAM that looks like this, it will close this contact when it rotates around to 100 and then release the contact at 300 encoder counts. So we setup this switch to mimic that CAM – it starts at 100 and releases at 300. If you disable this row – or switch – these outputs won’t do anything and these registers won’t be get updated. This disable feature is handy especially when you are testing. It allows you to isolate switches for debug or even build in switches for future features. We want to enable all of ours of course. There are 16 registers on the HSI module. You can use any of them here – in any order – and have them increment, decrement or zero when this switch goes active. These registers give you a way to track how many times a particular switch is being used. While this zeros the register when entering this switch, this zeros the register when enabling the instruction. Let’s clear all of our registers when this PLS instruction is first enabled. Finally, when the encoder is between these two values, what do we want the contacts to do? Let’s make output 1 active for this one. For switch 2, let’s have him go active between 200 to 512, increment register 2 and he will enable output 2. Switch 3 will be active from 700 to 800, will increment register 5, and activate output 4. And finally switch 4 will activate between 900 and 1024, won’t change any registers and will enable all 4 outputs. You can think of this turn on and turn off as your normally open or normally closed outputs. You can only use one type per column, of course. Once you have decided an output is normally open you can’t switch it to normally closed later – right? So graphically that would look like this. We have 1024 counts per rotation of our encoder. As we rotate the encoder, output 1 is active here, output 2 overlaps 1 for a 100 counts, output 3 is active here by himself, and all four outputs are active here. And remember, back in the configuration, we told the HSI to reset the count when the encoder Z pulse comes around, so this will all repeat as long as the instruction is enabled. Now there is one thing to be aware of – there are 16 of these registers and 16 possible steps – switches great right? Because you can have a dedicated register for each of the 16 possible ranges. Well … yes and no … There ARE 16 registers, but they are shared between the two channels on the HSI module. So both channels can increment the same register – which in some applications could be handy, but most of the time you will want to be sure you keep them separate. Maybe dedicate one set to one channel and another set to the other channel. The point is you have that flexibility but also that responsibility, so keep an eye on that. Also, these little blue arrows remind us that we can change these values while the code is running – of course we would have to have a tag here that we could change in our code. We’re using fixed values just to keep the demo simple. Finally, this option says once the instruction is enabled; wait for a trigger on one of these general purpose inputs or one of these encoder z pulse inputs before starting. That allows you to trigger this instruction from an external source which works great when you want to align timing to the encoder’s z-pulse. Let’s add an enable contact … and transfer to the processor…. Make sure we are in run mode and bring up the dataview. Let’s add the instruction enable, the switch status, the register counts and the HSI current position, which in our example is the encoder count. Let’s make the switch status is binary so it’s easier to see the individual switches toggle. Did you notice that we didn’t use the instruction’s register names in the dataview? We used the tag names assigned to those registers back here in the HSI configuration. Why? Because the instruction registers are local to the HSI module, so we don’t actually have access to those from our ladder code. Instead, those values get copied each scan to the tag names we define in the HSI configuration so we have access to them from the ladder code. Let’s enable the instruction, and I’ll reach over and rotate the encoder and sure enough as we pass into the first switch’s range output 1 turns on and increments the register. You can see switch 1 is active here in its status. Keep rotating and the second switch enables output 2 and since it overlaps with switch 1, output 1 is still active until we hit 300. Switch 3 is enabled between 700 and 800 and all outputs are active during switch 4’s range of values. Exactly what we expect. And this works in both directions: if we rotate into a region, and then rotate backwards into the previous switch’s region, the outputs react accordingly and the register gets incremented again. It literally works like the contacts being open and closed by a series of rotating cmas. And while we didn’t do it in this video, you should ALWAYS check to make sure a high speed module is ready before sending it commands. Remember – it runs independently of the main CPU so this is the only way you know if it’s ready to receive those commands. Just go to the hardware configuration, we’re using the HSI module in this demo, and setup the module ready tag here. There are a couple things to be aware of. There has to be at least a 1 count difference between the low and high limit. These two numbers can’t be the same. When the PLS instruction is disabled, the outputs hold their values. If you need to clear them then use the Write High Speed Outputs instruction. Be careful when using scaled units. I love being able to convert pulses into units I understand in the hardware configuration, BUT that could hide when the pulse counts between steps falls below 1 for example. So just be conscious of that. You can reset the HSI position register while the instruction is enabled by using this option in the configuration. When enabled, if you set this tag to a 1, then whatever value you put here will overwrite the current position register. Remember, you can’t run two HSI instructions on the same channel at the same time. So we can’t have PLS running AND do a Set Position. This reset position Tag gives you a way around that. If you need any help with the Programmable Limit Switch on the Productivity Series controllers, please contact AutomationDirect’s free award wining support team during regular business hours. They will be happy to help. And don’t forget the forums! There are lots of experienced automation professionals here that love to share their years of experience. Just don’t post any questions directed at AutomationDirect’s support team there, they don’t monitor the forums on a regular basis.