How are you defining "shut down"? And how do you define "lost memory"? When a PLC is downloaded, the program gets written to a ROM, doesn't it? And then it gets automatically loaded into memory, no? I say this because I've found if you cycle power on a PLC, you don't have to reload it. It reloads from its on-board copy (as if it had a hard disk, but it doesn't). So, in my case, I don't know where these junk values are coming from. If the array is preset to all zeros in the app, *that's* what should be loaded into memory - regardless of *where* it gets loaded into memory (I would think).
"Lost Memory" usually occurs on older processors when the PLC is powered down for a long period of time, and the battery is depleted. In that case, program no longer exists, so neither does the array, and so any discussion of the values in it are moot. In modern Compact Logix PLC's there is an energy storage module that holds the power up for long enough to transfer the program - including the values of all tags - into non-volatile memory, so it's really a non-issue. The only other way a program might be lost is in the case of a Major Non-Recoverable Fault (MNRF), which is usually associated with a serious hardware fault. I don't think I've ever seen one.
All compact logix memory is retentive. Whatever values are in your array will stay in your array until modified by either logic, an external device writing to them, or a download that overwrites them. You can switch the PLC from Run to Program, cycle the power, do whatever you like - but the array values will stay the same until one of those things happens.
If you do a download, whatever values are stored in the offline copy of the PLC program will be written into the array. Let's take a simple example of an array with 5 elements. When you create the array for the first time, they'll all be zero, and when you download to the PLC, the array will be created with all it's members zero. Then, you run the code for a while, and your array now has values 1, 2, 3, 4, 5 in it respectively. You make a change to the offline code, download the program to the PLC again, and your array is reset back to all zeroes, as that is what is in the offline code. Now, you run the code for a while, until the values 1, 2, 3, 4, 5 are in your array. Then you go online with the PLC, and press Save. You'll get a dialog box asking if you want to upload all tag values. If you click yes, the values of all tags, including those in your array, are uploaded into the offline file. So now, the array in your offline file has the values 1, 2, 3, 4, 5. Let's say your code runs some more, until the values in the array are 2, 4, 6, 8, 10. But then, you do another download. You will download whatever values are stored in your offline file - 1, 2, 3, 4, 5. So after the PLC goes back to run mode, your array values will once again be 1, 2, 3, 4, 5.
Does that clear that part of it up?
But if you do it the way you've described, you are constrained by the periodicity of your task. Let's say your task runs at 250 ms and you have to loop through 1000 array elements. You'd have to wait 250 seconds (over 4 minutes) to loop through your array! I don't see anything wrong with running a loop within a scan, as long as you don't MAX TIME your thread execution.
Absolutely - there are certainly reasons where you might want to create a loop. In ladder, you use JMP and LBL instructions. Keep in mind though, that there are several instructions you can use that will operate on every element in an array of any size, within one scan, by default. So you may still not need to create a loop, depending on what you're trying to do.
With those military applications I mentioned above, a task had 25 ms to execute its thread, and if that time was exceeded, the OS would terminate the task and send it a WarmStart message (to re-start). Earlier versions would simply stop the processor, but this wasn't 'fault tolerant'. What happens in a PLC when you exceed the MAX TIME for your thread execution? Does the PLC come to a screeching halt?
Yes. Each task has a configurable watchdog timer, which if exceeded, will cause a Major Fault (not MNRF, though), and your PLC will stop executing code.
Looks like I can use a FLL (per OkiePC) or, as you suggested, a COP or CPS.
If you're trying to clear all values to zero, an FLL is a better option, as you can use a constant (i.e. 0) as your source. With a COP, you can't - you'd have to set a tag to 0, and then copy that tag to the rest of the array elements. Which, I mean, you can still do, but FLL is simpler.