Ron Beaufort
Lifetime Supporting Member
Greetings widelto ...
thanks for sharing that program with us ... to be honest, I think that's the most imaginative way of doing a "moving average" that I've ever seen ...
just a quick comment though - in case someone decides to use this in an actual application ... the "Reset" operation on Rung #0001 has a subtle flaw ... the placement of the OSR will keep S:1/15 from triggering the "Reset" operation in the following conditions ...
suppose that the processor is in the "Run Mode" ... suppose that the "Manual Reset" bit is set to a ONE condition ... (maybe an operator's button is "stuck on" or has been "taped down") ... suppose that the processor is now placed in the "Program Mode" ... (or that the power to the processor is cycled) ... when the processor eventually comes back into the "Run Mode" the "Reset" operation will NOT be automatically triggered by S:1/15 as intended ...
the picture above shows the original rung construction - but slightly modified to demonstrate the use of an ADD to test the triggering operation ... I've done that in case anyone wants to experiment with these concepts ...
now ... here's a more reliable way of programming the condition side of the "Reset" rung ...
yes, it takes an extra rung - but at least now the status of the "Manual Reset" bit won't be able to interfere with the "Reset" operation which was intended to be triggered by S:1/15 each time the processor first starts up ...
going further ... if the posted SLC-500 program is to be converted for a PLC-5 or ControlLogix processor, using the original rung construction will NEVER allow the "First Pass/Scan" bit to trigger the automatic "Reset" operation - REGARDLESS of the ON/OFF status of B3/0 ... of course the PLC-5 or ControlLogix platforms use ONS instructions instead of OSR instructions - and that's the point ... even though OSR and ONS instructions might SEEM to be identical, the processors handle them quite differently during "pre-scan" ...
the method shown above should work reliably for a PLC-5 or ControlLogix system ... note that this same "one rung" approach can't be used for the original SLC-500 program - because (unlike an ONS) an OSR cannot be placed within a "condition side" branch ...
one final note:
the posted program is titled "Running Average" ... this, of course, is mathematically different from the "Moving Average" that our original poster inquired about ... regardless of the title, the program DOES compute what is commonly called a "Moving Average" - so once again, Bill, thanks for sharing it as part of this particular discussion ...
DISCLAIMER: it looks like the posted program might have been intended as part of a PLC training course ... it is entirely possible that the original programmer intentionally left the "Reset" bug in place just to test the students' ability to find it ... personally I often include such "tests" in some of my own "classroom" programs ... even so, over the years I have personally been called upon to help debug a few "sometimes-it-works-sometimes-it-won't" problems which can be traced down to exactly this type of program construction ... in MANY cases, it's the result of the original programmer assuming (gosh I hate that word) that ALL Allen-Bradley platforms work the same way ...
they don't ...
moral of the story: once you get the program "working" don't forget to check - and then double-check - how it will respond under various "startup" conditions ... surprises in that particular area can be both exciting and expensive ...
thanks for sharing that program with us ... to be honest, I think that's the most imaginative way of doing a "moving average" that I've ever seen ...
just a quick comment though - in case someone decides to use this in an actual application ... the "Reset" operation on Rung #0001 has a subtle flaw ... the placement of the OSR will keep S:1/15 from triggering the "Reset" operation in the following conditions ...
suppose that the processor is in the "Run Mode" ... suppose that the "Manual Reset" bit is set to a ONE condition ... (maybe an operator's button is "stuck on" or has been "taped down") ... suppose that the processor is now placed in the "Program Mode" ... (or that the power to the processor is cycled) ... when the processor eventually comes back into the "Run Mode" the "Reset" operation will NOT be automatically triggered by S:1/15 as intended ...
the picture above shows the original rung construction - but slightly modified to demonstrate the use of an ADD to test the triggering operation ... I've done that in case anyone wants to experiment with these concepts ...
now ... here's a more reliable way of programming the condition side of the "Reset" rung ...
yes, it takes an extra rung - but at least now the status of the "Manual Reset" bit won't be able to interfere with the "Reset" operation which was intended to be triggered by S:1/15 each time the processor first starts up ...
going further ... if the posted SLC-500 program is to be converted for a PLC-5 or ControlLogix processor, using the original rung construction will NEVER allow the "First Pass/Scan" bit to trigger the automatic "Reset" operation - REGARDLESS of the ON/OFF status of B3/0 ... of course the PLC-5 or ControlLogix platforms use ONS instructions instead of OSR instructions - and that's the point ... even though OSR and ONS instructions might SEEM to be identical, the processors handle them quite differently during "pre-scan" ...
the method shown above should work reliably for a PLC-5 or ControlLogix system ... note that this same "one rung" approach can't be used for the original SLC-500 program - because (unlike an ONS) an OSR cannot be placed within a "condition side" branch ...
one final note:
the posted program is titled "Running Average" ... this, of course, is mathematically different from the "Moving Average" that our original poster inquired about ... regardless of the title, the program DOES compute what is commonly called a "Moving Average" - so once again, Bill, thanks for sharing it as part of this particular discussion ...
DISCLAIMER: it looks like the posted program might have been intended as part of a PLC training course ... it is entirely possible that the original programmer intentionally left the "Reset" bug in place just to test the students' ability to find it ... personally I often include such "tests" in some of my own "classroom" programs ... even so, over the years I have personally been called upon to help debug a few "sometimes-it-works-sometimes-it-won't" problems which can be traced down to exactly this type of program construction ... in MANY cases, it's the result of the original programmer assuming (gosh I hate that word) that ALL Allen-Bradley platforms work the same way ...
they don't ...
moral of the story: once you get the program "working" don't forget to check - and then double-check - how it will respond under various "startup" conditions ... surprises in that particular area can be both exciting and expensive ...
Last edited: