Method of determining occurances

D_Kintz

Member
Join Date
May 2023
Location
Hillsboro, OR
Posts
3
Good morning! I am looking for a clever method to determine the number of occurrences in a series using ladder logic. What I need to determine is if a certain value goes high 3 out of 20 times within a certain time period.
 
Which is it, 'out of 20 times' or 'within a certain time period'?

If you are always looking at 20 measurements, then a shift register is easy enough to implement with a counter that increments/decrements as high values enter and leave the register.
 
Good question, thanks for your assistance. Not time-based.

I am using an FFL and FFU to increment/decrement according to when a pallet enters. Enter + good = decrement, enter + bad = increment. The length is 20 for both. This would tell me if I get 20 in a row but not if I get 3ea in a 20 pallet interval.
 
You need to Loop through the array/register each time it is updated.

If you are comfortable with Structured Text, it is pretty straightforward:

// You need a 'counter' variable CONT and the iterator i
CONT := 0
FOR i := 0 TO 19 DO
IF ARRAY THEN CONT := CONT + 1; END_IF;
END_FOR;

// Then you can check if CONT is equal or greater than 3

If you are using a DINT as a register instead of an array of booleans, you need to put 'i' between brackets:

CONT := 0
FOR i := 0 TO 19 DO
IF REGISTER. THEN CONT := CONT + 1; END_IF;
END_FOR;

If you want to stick with ladder, a similar implementation is possible with some JMPs and a manual increment of i.
 
Stick with your FFL/FFU setup, all you need to do is keep track of the goods and bads as they enter and leave your FFL/FFU stack.

Create a DINT called, for example, Bads_In_Last_20

Each time a pallet is loaded, check if your stack is full (FFL control .DN bit on). After the first 20 pallets, it will always be on.

Assuming the .DN bit is on, perform your FFU to unload the pallet 20 pallets ago, and check the status of the pallet that was unloaded from the FFU. If it was a good pallet, do nothing. If it was a bad pallet, subtract one from Bads_In_Last_20.

Then, load your FFL. As you load it, if the entry is bad, add one to Bads_In_Last_20.

Instead of looping through your array each time and manually counting the bad pallets, just count them as they enter and leave - unless you manually clear or otherwise manipulate the contents of your FFL array, the only way bad pallet flags are getting in and out is with you counting them.
 
Thanks! I actually found the FBC command which essentially does exactly what I need, no script writing. It takes a source DINT and compares it to a reference DINT (empty in my case) and loads the result into another DINT. You get the number of bits that are different in the .POS of the Results Control. Helpful instructions at https://bryceautomation.com/index.php/2021/08/20/controllogix-file-bit-compare/ or look up File Bit Compare.

I loaded the source DINT with a BSL (Bit Shift Left) and then compared to the reference DINT with the FBC. In the FBC, set the number of items to compare with the "Length" parameter of both controls (20 in my case).
 
Last edited:
Thanks! I actually found the FBC command which essentially does exactly what I need, no script writing. It takes a source DINT and compares it to a reference DINT (empty in my case) and loads the result into another DINT. You get the number of bits that are different in the .POS of the Results Control. Helpful instructions at https://bryceautomation.com/index.php/2021/08/20/controllogix-file-bit-compare/ or look up File Bit Compare.

Well, this will be archived in the obscure instructions folder in my brain. Thanks for sharing.
 

Similar Topics

sir, while running program in codsys an error occur 'C0138: No matching 'FB_Init' method found for instantiation of FbPowerPlantControl.' how to...
Replies
1
Views
82
Hi, I have a 2.2kw drive, this is a lift application and the manufacturer says to use the 87hz method. In theory I understand this but in...
Replies
6
Views
870
Hi Guys, During PID Tuning by Ziegler Nichols Closed-loop method, In TIA Portal there is a Trend Tool used to determine Ultimate Period; marking...
Replies
9
Views
1,873
I'm using ftview 13 with rslogix v35. I want to use a button to reset all alarms coming from process CPU L83-EP. I tried using invoke method to...
Replies
10
Views
1,875
I forget if there is a way to find out what this is if I don't currently have access to the original HMI computer. I only have the InTouch...
Replies
15
Views
6,782
Back
Top Bottom