I have a SLC5/03 that suddenly started faulting. It has been running for 2 years without issue, and I tracked the problem to a math error (underflow?)
just for me I put in a subroutine to count how many scans per second the PLC is doing, and calculate it every minute. I count every other scan, at :01 seconds I move the counter.ACC, at :02 I move the counter.ACC, subtract for the number of counts, multiply by 2 for the scans value and reset the counter.
The odd part is even though the counter is reset every minute it somehow got to the negative count of -28465 and tried to SUB -28554, faulting the CPU.
I have watched this before and the count never went over 3000 until it was reset, the JSR to this is unconditional and processed every scan, so it's not getting bypassed, the OSR's are unique and not used elsewhere in the program.
What concerns me is I have this subroutine in almost every SLC, and a few other brands of PLC, I put in to see how the PLC performs, and is still in many machines.
For this one I added a latch bit on the first MOV, and perform a RES on the counter if the seconds are over :03 or the counter.ACC is over 12000 - see the second picture
![Scans2.jpg Scans2.jpg](https://www.plctalk.net/data/attachments/40/40871-a45ac465861b90536cda837b2dd2973d.jpg)
just for me I put in a subroutine to count how many scans per second the PLC is doing, and calculate it every minute. I count every other scan, at :01 seconds I move the counter.ACC, at :02 I move the counter.ACC, subtract for the number of counts, multiply by 2 for the scans value and reset the counter.
The odd part is even though the counter is reset every minute it somehow got to the negative count of -28465 and tried to SUB -28554, faulting the CPU.
I have watched this before and the count never went over 3000 until it was reset, the JSR to this is unconditional and processed every scan, so it's not getting bypassed, the OSR's are unique and not used elsewhere in the program.
What concerns me is I have this subroutine in almost every SLC, and a few other brands of PLC, I put in to see how the PLC performs, and is still in many machines.
For this one I added a latch bit on the first MOV, and perform a RES on the counter if the seconds are over :03 or the counter.ACC is over 12000 - see the second picture
![Scans.jpg Scans.jpg](https://www.plctalk.net/data/attachments/40/40870-11a2a511c5dae260483436ee660bdf3b.jpg)
![Scans2.jpg Scans2.jpg](https://www.plctalk.net/data/attachments/40/40871-a45ac465861b90536cda837b2dd2973d.jpg)
Last edited: