How to Reset an Array in Allen Bradley CCW: Troubleshooting Tips and Code Examples

Question:

Hello everyone, I’m currently engaged in my first project utilizing an Allen Bradley Micro 810 with Connected Components Workbench (CCW), and everything has been progressing smoothly until now. I've encountered a challenge that I can't seem to overcome. My setup involves an amplified load cell and a series of TON (Timer On Delay) blocks, which I am using to create an array that captures load cell values at specified time intervals. The array is defined as a DINT[0..100] and appears to be functioning correctly. The issue I need to address is the requirement to reset this array to an initial value of zero at each cycle, enabling the storage of new load cell readings. Unfortunately, it seems that the COP (Copy) command is not available in my current version of CCW. As a workaround, I attempted to use the MOV (Move) command to replace the contents of the Load_Cell_Array with a corresponding array of zeros, but I have not been successful. I came across an article in the Allen Bradley knowledge base (#531939) suggesting the use of structured text (ST) to iteratively set each value in the Load_Cell_Array to zero. However, I am still unfamiliar with how to achieve this using ST. I have put together some code that I'll share below, but I'm encountering several errors during the build process. If anyone has faced a similar challenge or has insights on this topic, I would greatly appreciate your help. Thank you in advance! Best, Tim Here’s the code I’ve been working on: ```structured-text PROGRAM Zero_Array VAR i : DINT; VarInput1 : DINT[0..100]; END_VAR; FOR i := 0 TO 100 BY 1 DO VarInput1[i] := 0; END_FOR; END_PROGRAM; ``` (Note: 'VarInput1' is linked to the function block representing 'Load_Cell_Array'). I'm eager to hear any advice or suggestions you might have!

Top Replies

You're almost at the finish line! Just a few adjustments are needed. First, ensure that your "Load_Cell_Array" is defined as a GLOBAL variable of type DINT with an index range of [0..100]. Next, create a User-Defined Function Block (UDFB) using Structured Text. Inside this function block, declare an index variable "i" as DINT to limit its scope. Insert the following code into your function block: ``` FOR i := 1 TO 100 BY 1 DO Load_Cell_Array[i] := 0; END_FOR; ``` Once you’ve built the function block, it should be free of errors. To clear the "Load_Cell_Array" at any time, simply add the "ClearArray" function block to your ladder logic rung, and it will reset the array. I trust this guidance will be helpful for you!

Thank you for your valuable feedback! The build process completed successfully. I realized that I overlooked the step involving the creation of a local variable, specifically for "i" as a DINT type in the custom block.

Hi Tim, it sounds like you're on the right track with using structured text (ST) for your project! I noticed a couple of things that might be causing the build errors. First, ensure that your array declaration matches the intended array you're trying to reset. Since you're resetting `Load_Cell_Array`, make sure your `VarInput1` is correctly linked to it, or directly access `Load_Cell_Array` in the loop. Additionally, check the upper limit in your `FOR` loop; it should be `TO 99` instead of `TO 100`, as arrays in most programming environments (including ST) are zero-indexed. So your `FOR` loop should look like `FOR i := 0 TO 99 DO`. This should help clear up the errors you're facing. Good luck, and don’t hesitate to reach out if you need more help!

More Replies →

Streamline Your Asset Management
See How Oxmaint Works!!

✅   Work Order Management

✅   Asset Tracking

✅   Preventive Maintenance

✅   Inspection Report

We have received your information. We will share Schedule Demo details on your Mail Id.

You must be a registered user to add a comment. If you've already registered,
sign in. Otherwise, register and sign in.

Frequently Asked Questions (FAQ)

FAQ: ```structured-text

Answer: PROGRAM Zero_Array VAR i : DINT; VarInput1 : DINT[0..100]; END_VAR;

FAQ: FOR i := 0 TO 100 DO

Answer: VarInput1[i] := 0; END_FOR; END_PROGRAM; ```

Ready to Simplify Maintenance?

Join hundreds of satisfied customers who have transformed their maintenance processes.
Sign up today and start optimizing your workflow.

Request Demo  →