Looking at Boolean Arrays - Logix5000

TrashKetchum

Member
Join Date
Jun 2020
Location
Kings Lynn
Posts
2
Im pretty new to software and could use some advice please,

I am trying to fire an output if any alarms on my software are on.

I have a boolean array of ALARMS[416]. If any of these are 1 i need my output to also be 1.

If anyone has any advice, thanks in advance
 
I take it you are considering filling in the ellipsis in summat like the code below and thinking, there are better uses of your time?
Code:
      ALARMS[0]      ANYALARM
---+-----] [- ---+------( )-----------
   |             |
   |  ALARMS[1]  |
   +-----] [-----+
   |             |
   |  ALARMS[2]  |
   +-----] [-----+
[SIZE=5][B]...[/B][/SIZE]
   |             |
   | ALARMS[414] |
   +-----] [-----+
   |             |
   | ALARMS[415] |
   +-----] [-----+


I can think of a few approaches

  • Do it in a loop
    • unlatch the output bit
    • initialize a COUNTER to 0 for indirect addressing
    • loop over the bits
      • start with the LBL instruction; also
        • OR two branches
          • LES COUNTER 416
          • XIO OUTPUT_BIT
          • so the loop ends when either the counter reaches 416, or any bit is 1
      • latch the output bit if ALARMS[counter] is 1
      • increment the COUNTER
      • jump back to the LBL
  • Whoops, Logix5000 has a FOR loop, and I have spent too much time with RSLogix Lite, so scratch that first suggestion
  • Look for a Logix5000 instruction that examines multiple bits at once
    • I can't imagine you are the first to come up against this; maybe there is already a built-in instruction that can examine all bits in an array in one shot. In fact, I would do this first.
    • Again, since you are not likely the first, maybe there is an AOI somewhere on this site
    • Somehow converting (COP or CPS) that boolean array into an equivalent array of 13 32-bit DINTs, and comparing each of those 13 DINTs to 0 (NEQ DINT_ALRM[0] 0), or bitwise ORing them together into a single DINT and comparing that result to 0.
  • N.B. A loop may add significantly to the time it takes to test 416 bits.
    • Perhaps a response time of up to, say, a seconds or so, to one boolean changing from 0 to 1, or back, is acceptable
    • In that case, you could test only 32 per scan, so all 416 are tested over 13 scans:
    • I.e. on each scan
      • With DINT COUNTER and boolean ANY_ALARM
      • If
        • ANY_ALARM is 1,
        • or COUNTER is less than 0
        • or COUNTER is greater than 12,
        • Then assign 0 to counter
      • Test (OR) 32 ALARMS boolean, from ALARMS[32*COUNTER] to ALARMS[32*COUNTER-1];
        • if any are 1, latch ANY_ALARM to 1, and assign 13 (or -1) to COUNTER
        • Perhaps this could be done in an AOI or separate routine?
      • Add 1 to COUNTER
      • If COUNTER equals 13, unlatch ANY_ALARM to 0
These are just a few ideas; someone will probably post summat much simpler and better soon.
 
Use the FOR …DO loop to do something a specific number of times before doing anything else.

Operands

FOR count:= initial_value TO

final_value BY increment DO

<statement>;

END_FOR;
 
You mean something like this?

I’m not familiar with structured text at all so need to have a look into this. Only been doing this a month.

And yes, the ladder example is exactly what I’m trying to avoid.

Thanks for your help

AF96418E-A893-4B14-88F7-FFFD75943581.jpeg
 
Use bitaccess and set the bits of a DINT(32Bits) and then test to see if the DINT is > 0 also to reset all the bits write 0 to the Dint with a mov instuction.


Works for upto 32 bits.
 
Here is some logic if you are not doing it in ST, however, this is not RSL but should be able to do the equivalent.
One uses the FOR/NEXT loop the other does one each scan so if your scan time was 10 per second then it would take length of array times 10. On a RSL probably the scan time will be in ms so should not be a problem.
Note: due to the way this PLC works cannot jump out of a for next loop, also the pointer has to be stored in an index register where yours will not.

Per_Scan.png For_Next.png
 
I had the same task a few months back.

I had two Boolean arrays each with 256 and needed to know if any was active,

I was not up for continually running true the arrays counting bits and was looking for a faster response.

I change the program around, so I only have one routine pr. array controlling everything going in and out of the array,
added a few counters, counting up and down, when ever a bit is set or reset.

And I have an response immediately when the first bit is set.
 
I change the program around, so I only have one routine pr. array controlling everything going in and out of the array, added a few counters, counting up and down, when ever a bit is set or reset.




Ooh, I like this, approximately four rungs for the subroutine, and then a few rungs at every alarm. Very clean.


Unfortunately for the OP, that involves adding a couple-three branches wherever each alarm is set.
 
You mean something like this?
{structured text}


yes, or this, which assumes the dimensioning includes at least one extra unsed boolean in the array i.e. ALARMS[417] or ALARMS[448]:


Code:
ALARMS[416] := 0;  /* Elephant in Cairo */

index := 0;

WHILE index < 416 AND NOT ALARMS[index] DO
   index := index + 1;
END_WHILE

RESULT := ALARMS[index];
I am not sure about my ST syntax, but someone should be able to fix that.


Or even better, in the code golf sense:

Code:
ALARMS[416] := 1;  /* Elephant in Cairo */

index := 0;

WHILE NOT ALARMS[index] DO
   index := index + 1;
END_WHILE

RESULT := index < 416;
These approaches have the advantage of producing a result as soon as the first 1 bit is found.
 
DR: yep I agree, however, not sure about RSL 5000, but in some PLC's if not using ST then the FOR loop cannot be prematurely ended, found this in GXWorks. however, if this is the case and he does not have ST could just roll your own using label jumps. Here is one, needs to be converted to RSL

loop with a skip.png
 
Unfortunately for the OP, that involves adding a couple-three branches wherever each alarm is set.

I am the lazy type, I use pointers whenever I can get away with it :)

If this is the case here, then it would be pretty simple to setup
 
Ha Ha. You must have deleted it & re-posted, after I replied your post had gone & then there it was (re-posted) with the attachment
 

Similar Topics

Hi , Where i can find Mitsubishi PLC Card end of line & replacement model details. i am looking for Q02CPU replacement model. Please advice. thanks
Replies
2
Views
126
I have Allen Bradley plcs, I have had Circuit breakers and other automation equipment in the past. There's no solid buyers local. How much do you...
Replies
2
Views
204
can anyone has a good program to learn plc programming online. i have the basic looking into improve my skills thanks
Replies
1
Views
144
I want to monitor a couple signals in a place where there is no PLC but there is ethernet. I know I can use an AENTR or Flex I/O and a module but...
Replies
21
Views
785
I downloaded v24 for studio 5000 but can’t find where the download manager put it! Any help? I’ve done it before but can’t remember. Thanks
Replies
9
Views
391
Back
Top Bottom