Counting multiple outputs

imonline

Member
Join Date
Mar 2006
Location
New Brunswick
Posts
13
I'm using RSLogix5 and need to count the number of outputs that are active at any given time. I have 20 outputs that represents bins. When one is active, this tells me that that bin is full. So what I'm trying to say is I need to know own many bins are full at any given time.

I can program one output to one counter

I'd appreciate any help to ladder programming this.


Thanks,

Don
 
The cheap and dirty way is to add 21 rungs of logic.

Rung 1 Mov 0 into N7:0
Rung 2 (ote 1 on) Add 1 to N7:0, place result in N7:0
Rung 3 (ote 1 on) Add 1 to N7:0, place result in N7:0
Rung 4 (ote 1 on) Add 1 to N7:0, place result in N7:0
and so forth.
 
Yeah, thats how I do it. Counters don't actually work too well there, so use the add statements. Even if you tried to use the rising and falling edges to trigger up and down counters to keep track that way, it'd be a lot more logic, and also be very likely that the numbers would get off on a regular basis.

-jeff
 
I'm not going to bother to convert the pseudo code to ladder, this subject has been covered ad nauseum here.


To count the bits in X with the least number of loops:

N:=0
Loop_Begin
If X then {
N:= N+1
X:= X & (X-1)
Repeat Loop
}
Loop_End
 
Hello,
If your PLC support array type you can create an array of bool
like:

TYPE
Bit[1..20] as ARRAY OF BOOL;
END_TYPE

If i<20 THEN
i:=0;
N:=0;
If x THEN
N:=N+1;
END_IF;
i:=i+1;
ELSE
i:=0
END_IF

Something like this you can assign corresponding input to an array element.

Best Regards
 
How about the LIFO (Last In First Out) Instructions (LFL, LFU)? If you implement it correctly, the position would give you the number of outputs energized at any one time.
 
I'd vote for KentuckyMark's suggestion. I recently had the same issue but with about 40 bits to count. I first tried doing a loop with indirect addressing, but my scan time doubled (7 ms to 14 ms) on an SLC 5/05. I changed it to 40 rungs with ADD instructions and now it works great without affecting the scan time. Yes it's a lot of logic, but stick it in a subroutine and you'll forget it's even there.
 
Thanks guys,

I think I'll be going this way:

Scan.jpg



Again Thanks,

Don
 
Your logic will not work as you expect.
Each compare rung will be true for multiple scans, so you will get multiple additions. I would not do it exactly like that, but you can if you add one shots to each addition rung.
 
Ken Moore said:
Your logic will not work as you expect.
Each compare rung will be true for multiple scans, so you will get multiple additions. I would not do it exactly like that, but you can if you add one shots to each addition rung.
I know I tried it as shown and did get multiple additions. I did though add one shots to each rung and my count was good. On my first try it was showing 5 lights on and I had 5 lights on. Tried with 10 and got 10. Went back to 8 and go 8.

It's working fine now and I'm gonna leave it as is.

Thanks for the inputs.

Don
 
Golly, I'm having trouble following that. Purely academic, i realize, but lets see if i have this straight. Since you have 20 inputs to count, I'm assuming your timer really goes up to 20. So, once a second you are checking each rung and adding 1 to your total if needed. Once you've been through them all, you reset the timer and do it again. After 59 iterations you move the count into another register (to log for posterities sake?) and after the 60th iteration, you reset the counter and start again. The one thing conspiculously absent here is how does N9:49 get reset? You say it works and I beleive you because you're a trustworthy sort. But this looks like it would just keep counting up until the number got so large it faulted the processor.

-jeff
 

Similar Topics

Hello I am looking for tips on how to count the duration of a given function and then how to display it on the hmi panel in the hh:mm:ss format...
Replies
4
Views
1,698
Guys, I know it will be silly but can't get my head around it. I have 3 conveyors, every one on a separate servo drive, and 2...
Replies
25
Views
3,496
The 1734-IB8 has no hardware counting function correct? I am trying to find something to substitute in for a 5069-IB16F (since lead times are...
Replies
3
Views
1,408
Been scratching my head at what I thought should be a relatively simple task. I need to count how many rows a .csv file has, so I can later read...
Replies
6
Views
2,538
Hi All, I need to count my Contactor switching times. There are lots of them so I created a template logic with local variables in FC2000. Now I...
Replies
10
Views
2,115
Back
Top Bottom