1756-L73, Studio 5000 v32. I added a routine to a periodic task on Friday that has been running untouched since 2017. Downloaded at 15:10, controller faulted at 15:14.
Major Faults says Type 06 Code 01, Task watchdog expired, and names the task, T_Weigh. That one is 10ms periodic with the watchdog at 20ms, which somebody set in 2017. My new routine takes an array of 500 REALs and does a running average in a FOR loop. I cleared it and it faulted again about three minutes later, and with the JSR pulled back out it ran all weekend with nothing.
Am I looking at raising the watchdog, or is the L73 just slow for this? Pretty sure 500 REALs in a FOR loop isn't a lot of work, so is it the loop, or has that 20ms been getting away with it since 2017?
Before anything: Task Properties, Monitor tab, what does Max Scan Time say for T_Weigh with the new routine in? And what's the max on the continuous task? A FOR loop over 500 REALs in a 10ms task is a lot to ask, and 20ms isn't the default watchdog, the default is 500ms if I remember right, so someone chose it.
Is the watchdog basically a timer for how long one pass of the task is allowed to take?
> Max Scan Time
23.4ms with the routine in, 4.1ms without. Continuous task max is 38ms. So yes, it blows straight past 20. finn, yes, and if the pass isn't done when it expires the controller faults instead of skipping.
Not sure why 20ms specifically was chosen back then, but 23ms of work in a 10ms task is the problem, not the watchdog. Even at 500ms you'd overlap every pass, the task would never keep up, and your weigh logic runs late anyway. Same in CODESYS, same in TIA, the box doesn't care what brand.
Move the average out. Put the FOR loop in the continuous task, or in its own 100ms periodic task at lower priority, and hand T_Weigh the result. Or don't loop 500 elements each pass at all: keep a running sum, add the new sample, subtract the oldest, one line of ST. Then set the watchdog from the Monitor tab max with margin, not from a guess. Writeup on scan time versus task period here: https://plctr.com/understanding-plc-scan-time-and-cycle-time/
Went with the running sum. Add new, subtract oldest, divide once, and the array is now a ring buffer with an index. T_Weigh max scan time is 4.6ms with it in, ran all night, no fault. Watchdog left at 20ms.
My 500 element loop was pushing a 10ms task to 23ms, past a 20ms watchdog. The fix was not looping at all.
Still don't know why whoever set it up in 2017 put the watchdog at 20 on a 10ms task, the default is a lot bigger. Might have been on purpose, might not. Left a note in the task description.
edit: forgot to say, watchdog's still set at 20ms, I never touched it.
Thanks carav9 and boris_h.
Ring buffer beats a FOR loop in a fast task every time.