PART III Register Match Interrupts The Do-more BRX PLC has a register match option
for generating interrupts.
What does that mean?
Suppose you setup input X0 to be a high speed counter of some kind and you want to know
when the count reaches some specific number.
And you don’t want to wait for the next scan to come around to find out about it when
all the regular inputs get updated because it might be too late.
Instead, you want to know about it right away so you can react accordingly.
Well, that smells like an interrupt thing – right?
And that’s what this register matching interrupt option is.
You can trigger an interrupt on one of three dedicated counter/timer accumulators or one
of three output pulse counters.
Let’s do a couple examples and see how this works..
Assume the counter has already been setup correctly – that’s a subject for another
video.
And we want to react when that counter reaches 1234.
Create a new ISR and we want it to execute that ISR when High Speed counter timer 1 is
equal to 1234.
Hit ok and we see an equation that says, execute the ISR when this timer counter is equal to
this number.
Perfect.
In the ISR we’ll set output Y3 with an immediate set command.
So we should see output Y3 turn on when the input accumulator equals 1234.
Let’s do the exact same thing with function 2 but when the accumulator equals 1500 we’ll
turn Y3 off.
So we’re gonna need another ISR which we’ll use to turn Y3 Off.
And when that same accumulator is equal to 1500 we want to execute that ISR routine.
And in that ISR we’ll use an immediate Reset instruction to turn Y3 off so it will turn
off immediately and not wait for the bottom of the scan like all the other outputs.
Accept all of that.
Write it out.
And make sure the PLC is back in run mode.
I've connected one output from an encoder to input X3 on the PLC.
Here’s a Dataview that shows the input counter’s accumulator and its reset control.
The output we are controlling and the run counter for both ISRs so we can see how many
times they have been triggered.
I’ll hit the reset to make sure the accumulator is cleared before we start.
If I rotate the encoder up to the 1234 we specified, sure enough output Y3 turns on
and we can see that the ISR ran one time.
If I keep rotating to 1500, Y3 turns off and it’s ISR ran one time.
Perfect.
And again, Y3 turned on and off immediately when the input changed – it didn’t wait
for bottom of scan.
Which means you now have an accurate way to react to high speed input counters and timers
without having to wait until the top of the scan.
This is really great for monitoring and reacting to high speed inputs.
You can do the same thing with high speed outputs.
Suppose you’ve setup a motion axis to control some piece of machinery and you want to know
exactly when that axis reaches a certain position.
Well, it’s the exact same thing we just did, except you tell the interrupt service
routine to monitor the output register instead of the input accumulator.
A word of caution about this: If you think you need to react to a high speed output using
interrupts, hold that thought for a second and go take a look at the table driven output
commands.
They do the same thing BUT they run in the background in their own dedicated hardware
so they don’t have any impact on the scan time and you can specify a whole sequence
or table of events to watch for and to react to.
This says when the output counter get to this value set the output and when it gets to this
value clear the output.
Etc.
You can even see a plot of the out here.
Very cool.
There are separate videos that show you how to do all of that.
The key thing to understand is the interrupt register matching method we did in this video
interrupts the scan which could affect your performance and it only responds to a single
event.
We had to create three different ISRs tjust to turn Y3 onand back off again, didn’t
we?
The good news with the ISR is you can do whatever you want– set an internal bit, modify a
register, record the date, etc.
The Preset Table and Table Driven output instructions only set the one output – you can’t do
things like record the date and time, manipulate other registers, and stuff like that.
So just know that you have a choice when you need to respond quickly to high speed outputs.
And when you DO need interrupts, as you can see, Do-more’s interrupt system is extremely
capable and will usually be more than you could ever need.
One side note: It’s tempting to use the immediate instructions everywhere – I mean,
why wait for bottom of scan for anything – right?
Well, you could do that, but it’s really not a good idea.
PLCs are designed to read inputs at the start of scan, do the ladder logic, and then update
all the outputs at the end of scan.
Using immediate output instructions outside of an interrupt service routine is a good
way to get things confused and to make your code really hard to debug.
So avoid that temptation.
If you need any help with the Do-more PLC, please contact AutomationDirect’s free award
winning support team during regular business hours.
They will be happy to help.
And don’t forget the forums.
There are lots of automation professionals there that love to share their years of experience.
Just don’t post any questions directed at automation directs support team there, they
don’t monitor the forums on a regular basis.
Spend Less, Do More with AutomationDirect