Interrupts are a powerful feature of the BRX PLC and are super easy to use. This brief tutorial will get you up and running quickly with basic interrupts.
Interrupts are great for reacting to things when they actually happen. Remember, normally a PLC reads the inputs, executes all of its logic and then updates its outputs. We call that a Scan. So, what do you do if an input comes and goes during the scan, well, you’ll miss it because the PLC only reads at the signals the top of the scan. Or maybe you need to respond to that signal right now and can’t wait until the bottom of the scan. If you need to catch a fast signal or respond immediately to a signal, interrupts are the answer. Why? Because once you setup the interrupt, it responds whenever the event occurs. It literally tells the PLC to stop whatever it is doing and go do this right now. It doesn’t wait until the top of scan or the bottom of the scan to do something. And the interrupt can occurat anytime during the scan. And Do-more makes using interrupts really easy. I’ve connected a simple pushbutton switch to input 0 on this Do-more BRX PLC so we’ll use that to trigger an interrupt. In the dashboard I click on interrupts and let’s assign event one to do respond to this push button press. Enable this interrupt and we want input 0 to be our trigger and let’s look for the rising edge. We haven’t defined the routine that is going to service this interrupt – we could have done that over here if we had thought of it ahead of time – but this button right here takes us to the exact same dialog. Let’s give it a name. We call this an interrupt service routine, or ISR for short. Do-more-Designer knows we want an ISR so we just hit CREATE. The name gets automatically dropped in here and we’re good to go. This little equation says an ISR named ISR_EVENT1 will be executed when it sees the positive going edge of X0. It won’t wait for top or bottom of scan, it will do it immediately. Let’s do a little experiment. At the top of the scan let’s clear D0, and then add a loop that increments D0 a thousand times. In the interrupt service routine or ISR, let’s copy D0 into D1. That will record where in the loop we were when the interrupt occurred. Accept all of that. Let’s see – we haven’t actually connected to the PLC yet, so I’ll go ahead and take care of that .. Make sure the PLC is not in run mode, and write it out to the PLC. I’ll reach over and flip the switch on the PLC to RUN and we see the PLC is running. So, how long does it take the PLC to increment D0 a thousand times? Well, click on INFO and we see on average it takes about 15 milliseconds to increment D0 a thousand times. Let’s bring up a data view and monitor D0 and D1. Remember that the data view updates at the end of each scan so all we see is D0 AFTER it has been incremented a thousand times. When I hit the pushbutton switch, that triggers the interrupt, D0 gets copied to D1, and we can see where the loop counter was when the interrupt occurred. . How fast does the interrupt respond? The time it takes for the Do-more to react to an interrupt is what we call interrupt latency. And look at this - there is an ISR structure member that tells you what the latency is! In this example it’s taking the Do-more about 3 micro-seconds to react to the event. How cool is that. You can also see how long it takes for the ISR to run, whether it has been triggered or not, if it is currently inhibited, how many times it has been run. Everything you could want to know about an ISR right there. Now remember – the ISR is literally stopping the regular scan, doing its thing then letting the scan continue. It’s really important to keep an eye on that execution time and make sure it doesn’t take too much time away from your regular scan. Looks like out ISR is taking this much time out of our 7.6ms loop. That’s has almost no impact on our scan time which is what we want. Normally you just want to record something in the ISR- like we recorded the loop counter in D1 – then do something with that in another task or program later as part of the regular scan. Don’t let that interrupt service routine get too long. A few other things to keep in mind about interrupts: An interrupt that triggers an event, can’t re-trigger the same event while its interrupt service routine is still running. That event will be lost. If an interrupt for a different event occurs while an ISR is running, then that event WILL be processed after the current interrupt is done. Another good reason to keep your ISR as short as possible. Can you do anything you want in an ISR? No. You can’t do looping, for example. Why? Because ISR’s don’t yield so the loop has to run to completion which takes a long time so they simply aren’t allowed in an ISR. Asynchronous instructions aren’t allowed in an SIR. Why – because Asynchronous instructions require multiple scans to run and you never know when or if an ISR is going to run. So asynchronous instructions don’t make any sense in an ISR. You don’t need to remember all of this. Do-more designer will tell you if you try to use an instruction that doesn’t work in an ISR. Well, that’s enough for a quick intro to Interrupts in the Do-more BRX PLC. In the remaining videos in this series will take a close look at exactly how to use the OTHER kinds of interrupts and then cover loose ends like configuring interrupts while the PLC is running. And if you need any help with the BRX PLC, please contact AutomationDirect’s free award winning tech support during regular business hours. The will be happy to help. And don’t forget the forums. There are lots of experienced automation professionals there 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.