Counting Active Bits in PLC-5

Floffle

Member
Join Date
Jan 2011
Location
a
Posts
3
This may be a foolish question, but is their a simple way to count the number of active bits in PLC-5? I can think of some complex ways to do this but was hoping there is a simpler way.

For example, I have a number of digital inputs on different cards, lets call them
I:1/0, I:1/1, I:1/2, I:1/3, I:2/4, I:2/5, I:3/1, I:3/2
Now lets say I want to know how many of these inputs are true (1), is there a simple way?

I've tried using the ADD function but RSLogix gives me an error saying "The Address must be specified to the word level."

I've used some DCS programs where this could easily be done by simply saying IN1 + IN2 + IN3 + .... and the result would be the number of active digital inputs since each active input would add 1 to the equation. Does PLC5 has something equally as simple?
 


----------------+-clr-------+
| n7:0|
+-----------+

i:1/0
--] [-----------+-add-------+
| 1|
| n7:0|
+-----------+

i:1/1
--] [-----------+-add-------+
| 1|
| n7:0|
+-----------+

i:2/5
--] [-----------+-add-------+
| 1|
| n7:0|
+-----------+

i:3/2
--] [-----------+-add-------+
| 1|
| n7:0|
+-----------+


----------------+-mov-------+
| n7:0|
| n7:1|
+-----------+


 
Funny how the simplest of solutions escape you when you get your mind stuck on a previous idea.

Thanks Alaric.
 
You might also want to add One Shots or a Trigger Event to Aleric's Code to make sure it only performs the ADD for each Bit one time. The current Code will add 1 each Scan the Input is true.

I am sure Aleric is aware of this, and was just giving you an example of one way of doing what you asked.

Stu....
 
Wouldn't that problem be taken care of by the CLR command? On each scan N7:0 would first be set to zero by the CLR and then incremented to the number of active inputs.

If we use one shots or a trigger wouldn't we have to remove the CLR command and add additional rungs with a one shot / trigger and a subtraction command in order to count down each time an input is turned off?

Alternatively, leaving the CLR command in place and using one shot / trigger would set N7:0 to the number of inputs that became active since the last scan would it not?
 
Wouldn't that problem be taken care of by the CLR command?

Yes, I bet Stu overlooked that, or he meant to point out that you may want to condition when you call the logic so that the result is valid for your application.

Also notice that Alaric wisely copies the result to a different integer at the end. If you have some device that reads the result asynchronously to the program scan,(like RSLogix or an HMI), make sure it reads N7:1, so that is doesn't sporadically pick up an interim value for N7:0 while that section of code is started but not finished.
 
Using two registers, clearing the counting register each scan and then moving the result to another register takes care of that - in the example I posted you get the count of how many of each of the bits of interest are on for a given scan. If you need to freeze that value then add additional logic to move the final result to a location that updates only when triggered.
 
Yes, I bet Stu overlooked that, or he meant to point out that you may want to condition when you call the logic so that the result is valid for your application.

Also notice that Alaric wisely copies the result to a different integer at the end. If you have some device that reads the result asynchronously to the program scan,(like RSLogix or an HMI), make sure it reads N7:1, so that is doesn't sporadically pick up an interim value for N7:0 while that section of code is started but not finished.

You are right Paul, I did not think it through enough before I posted. As long as you use the information right away for what you intend, it should be fine. I should know better than question Aleric. :unsure:

Oh well, we are all here to learn, and help out when we can. I for one have learned a lot more from my mistakes than my successes.

Stu....
 
I have similar task and I highly appreciate your help.
there are 8 sensors/inputs.
if any one of them is blocked for 1 second , the output stops for 5 seconds
if any 2 are blocked for 1 second, the output stops for 4 seconds
if any 3 are blocked for 2 seconds, the output stops for 4 seconds
and so it goes on with varying times until all 8 are blocked for 4 seconds
I tried logic with amount of inputs and it's ok. But I cant find the way how to manage the logic with 2 outputs and 3 outputs when we don't know which one will be on.
 

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,699
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,412
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,540
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