Best way to set an array to an initial value?

agrajag42

Member
Join Date
Dec 2015
Location
Bahstahn
Posts
17
I've got an array valve_set which has a data type of BOOL[32].
I've got another array valve_set_init which also has a data type of BOOL[32].

I'd like valve_set_init to have a constant value of, let's say, [1,0,0,1,1,0,...etc].

At various times, including (but not limited to) at startup, I'd like to make valve_set equal to valve_set_init.

Two questions:
1. What's the best way to set the initial (constant) value for valve_set_init?
2. What's the best way to copy valve_set_init into valve_set?

I've tried the COP (and CPS) instructions, but I get the following error:
Error: Rung 1, COP, Operand 0: Invalid data type. Argument must match parameter data type.​

Thanks!
 
This advice pertains not only to your particular application, but everything you will ever program in a Logix-based PLC.

Never use BOOL arrays

They are enormously painful to work with, as you're finding out. Your best bet is to use a DINT. Instead of addressing valve_set[0] through valve_set[31], you'll address it as valve_set.0 through valve_set.31. If you need to use indirect addressing, you use the . and the square brackets - e.g. valve_set.[Pointer]

Once you're using a DINT, COP or MOV will work just fine. COP would be the more "correct" choice.

If you want to be really neat about it, you can set the style to Binary, and then view all of your bits as a string of ones and zeroes still. And if you want to type in a constant in binary, just preface it with 2# (e.g. 2#0000_1000_1011_1100).
 
1. You can manual set the value or have a MOV instruction set a value for you from another constant with the first scan bit (s:fs).

2. Change your data type from BOOL[32] to a DINT, which will still have 32 BOOL within the DINT. Then use COP, MOV, or FLL as needed.
 
Question about not using BOOL Arrays

Hi All,
Thanks for your information and help with the problem above. I am curious, however about the apparent lack of support for BOOL arrays. I have found these to be very useful in the past for storing large amounts of data efficiently but I have also found they are not well supported.

If I use DINT sized BOOL arrays it is easy, but what if I want to use a different number of spaces?
 
What if I don't want to use DINT-sized buckets?

For example, currently I have an application that uses FactoryTalk view Alarms and Events which requires me to encode on/off switches as bits for each alarm. I have about 500 alarms for each of several phases so using DINTs just doesn't really make a lot of sense.

Does that make more sense?
 
You would just have to use an array of 32 bit DINTS that has greater than 500 bits (16 DINTS= 512 bits).

I understand what your saying though. I am working on a project with 70 alarms. I've set up a Bool array of 70. I like this because it matches my alarm timer array of 0-70. I'm not 100% sure if FTV alarms will read this correctly but I have Valve_alarms trigger set to bit and the trigger values as shown.

alarm bit.JPG
 

Similar Topics

Good Evening , I’m trying to get our maintenance staff to set the IP Address for a 22-Comm-E card for PowerFlex 40 drive . I usually use...
Replies
4
Views
2,345
Hi All, With AB RsLogix PID: What is the best way to reset the output to a specific value. For now i'm overwriting the PID.DATA[0] but i'm not...
Replies
9
Views
2,922
I have an old melsec fx1n and fx0n with ladder program that consists entirely of set and rst of everything imaginable. Some of the coils were set...
Replies
8
Views
2,500
Compactlogix controller, program has 28 conveyors that use TON's to start the conveyors. The TT sounds a warning horn during start and the DN...
Replies
10
Views
482
I have S7 1512C controler for controlling 48 PID temperature loop, the output is PWM. Please I need the best, most efficient way to write the...
Replies
13
Views
587
Back
Top Bottom