Alternative PLC Logic

WhatThe

Member
Join Date
Nov 2003
Posts
16
I have 10 different product lines.
I need to know when At Least two production lines are in service.
The long way would be something like.
If A AND B or C or D or E or etc.
If B AND C or D or E or etc.
If C And D or E or etc.
down until the last two combinations are tested.
Approx 44 different combinations.
Any suggestions on how to accomplish this is a shorter cleaner way.
Thanks
 
You didn't mention what kind of controller you're using, so I'll give an A-B example ('cause I work there).

If each production line can be represented by a bit in an Integer word, you could determine if only one of them is running with eleven Not Equal (NEQ) instructions in series.

For example, if lines 2 and 7 are running, the data word (like N7:0 in an A-B PLC) is represented like so in binary:

0000 0000 0100 0010

Taken as a two's complement number, that data word value is 66 (decimal). If only line 7 was running, the value would be 64 (decimal).

If only one of the ten lines is running, the data word can only be one of ten values: 1, 2, 4, 8, 16, 32, 64, 128, 256, or 512. Add one more NEQ instruction to account for zero lines running, and you will be able to tell when 2 or more lines are running.

This probably isn't the most elegant way, but it's the first one that came to mind.
 
OR...

If each production line can be represented by a bit in an Integer word,

Use the FBC instruction and check the length of the result file (.acc of the result control structure).
 
OR...

If your particular PLC has the "SUM" instruction (so far we know that sum (er...some) Koyos and Mitsubishis have it), this sounds like a good use for it... :nodi:

The "SUM" instruction will return the number of bits that are ON in a word. If you stick all your 'machine running' bits in one word, you can just check if the "SUM" value is greater than 1.

Seems like a pretty short, clean solution to me... :confused:

beerchug

-Eric

P.S. Also check THIS THREAD for more ideas on counting 'number of bits ON in a word'.
 
As always I am confused

I have 10 different product lines. I need to know when At Least two production lines are in service.

Questions like this I dont understand. WHY would there be this kind of need, I am curious.

I have my ideas on HOW TO but I am not really a programmer and it would depend on HOW the information was used to SHOW 2 or more are used.

Technically you asked for a method to show when any 2 are in service...is there a need to know when ANY and ALL are in service?

Lets number the machines 1 to 10...do you need to know if just 1 AND 10 are in service OR if 1, 2 3 and 10 are in service.

I assume IN SERVICE means running.
 
You could do what I've done in a similar situation. It may not be the cleanest, but it gets the job done.

Label an integer (say N7:0) Number_Running
Mov 0 N7:0
If #1 Running: Add 1 N7:0 N7:0
If #2 Running: Add 1 N7:0 N7:0
.
.
.

Then you can do whatever tests on the number of lines (or motors or whatever) you have running.
 
In an Omron PLC i;m lucky enough to have a Bit Counter Instruction....

OR as Ken said, u can use a multitude of comparison instructions...

OR Assuming that all of the inputs are on a single word I have attached a bit counter program for a single word that uses a shift register. Then take the result of this, compare it to a value of 2 and vola turn on an output...
 
Ken Roach said:
I always wanted a SUM instruction.

I'm sure most of us would be willing to sacrifice the TOF instruction for a SUM instruction. Experienced programmers avoid TOF like the plague, and eliminating it would also prevent confusing the newbies with useless instructions... :D

beerchug

-Eric

P.S. Here's the green 'envious' smilie you wanted... ;)
[attachment]

frown.gif
 
Experienced programmers avoid TOF like the plague
Really?!

I would have thought it was inexperienced programmers that did that.

Some superstitious programmers avoid the RTO because "sometimes they don't get reset".

In the days before PLC, there were on- and off-delay timers. Granted, there were more instances of on-delay but off-delay was far from obscure, and was not considered a plague.
 
Thank you for the suggestions.
I am using an A/B 5/40.
I don't need to know exactly how many are running, I just need
to turn another piece of equipment on when 2 or more are in service.

About the suggestion to add 1 for every line in service. You would
then need to subtract 1 for every line taken out of service and reset to zero when no lines are in service.

Ken, I didn't fully understand your example but I will play around with it. And a SUM Function would be sweet.

Any other suggestions and additional clarification is greatly appreciated.
 
WhatThe said:


About the suggestion to add 1 for every line in service. You would
then need to subtract 1 for every line taken out of service and reset to zero when no lines are in service.

Any other suggestions and additional clarification is greatly appreciated.


You don't need any extra logic. See the first instruction I listed moved 0 into the number_running. That way, it is reset every scan through the program, and always gives the current number of lines running (at least current up through the last scan, but that's as good as it gets regardless)
 
Lots of ways to skin this cat (sorry, Pierre)

WhatThe said:

About the suggestion to add 1 for every line in service. You would
then need to subtract 1 for every line taken out of service and reset to zero when no lines are in service.

And a SUM Function would be sweet.


I think you missed a critical piece of Jimbo's code. The whole thing is in a single rung with many branches.

The first branch clears the "Service Counter". Then there is one branch for each line that just adds one if it is "in service", or "running" or whatever the condition you need to count is.

There is no need to "subtract 1 for every line taken out of service" because the "Service Counter" register is cleared each scan, and each scan it gets recalculated based on what's current.

This IS a SUM function - it's just handmade instead of pre-canned.

If you are using a PLC-5/40 (and not a SLC 5/04), and you want a SUM function, then use an FAL, like so:
CLR N7:0
FAL R6:0 10 0 ALL N7:0 (N7:0 + #N7:1)

Note the '#' sign in front of the N7:1 in the equation, but not with the N7:0 (and that N7:0 is the destination as well as part of the equation).

What the above code will do is add N7:1 + N7:2 + N7:3 + ... + N7:10 and store the result in N7:0. It's not as good as counting bits (unless, of course, that you only use the /0 bit in N7:x), but it could do what you want.

Ken's idea is another techique youi could use, if you have the bits consecutive in a single word (and don't use any other bits for other purposes).

If the value of that word is zero, you know you have no lines available.

If the value of that word is exactly one, then you know that only line #1 is available, and no other. If the value of that word is exactly two, then only line #2 is available.

Taking it further, if the value is either 1, 2, 4, 8, 16, 32, 64, 128, 256, or 512, then one and only one line is available. So anything other than zero or those numbers must mean that you have "2 or more".

So you program the individual BITS with coils to indicate the status, but you do a compare on the WORD to determine the overall status.
 
I'm sure most of us would be willing to sacrifice the TOF instruction for a SUM instruction. Experienced programmers avoid TOF like the plague, and eliminating it would also prevent confusing the newbies with useless instructions

Why couldn't we just wish for the SUM in addition to what's already in the box ... I kinda like the TOF and use it often. Many times it makes more sense to use a TOF instead of a TON.
 
Thank you all.....I overlooked the fact that the register is reset every scan. I like this manually created SUM function, I believe it is a good fit for my application.
 

Similar Topics

Greetings All, I recently decided to start freelancing in Controls and Automation part time, most of my experience has been with Rockwell...
Replies
2
Views
144
Hi everyone, I'm pretty new to PLC's in general, and working on a project where I have to get familiar with the PLC compilation process...
Replies
5
Views
4,550
Hi Guys, Does anyone know of an virtual PLC similar to RS Emulate. I need one for testing programs created for AB and general training. The RS...
Replies
5
Views
2,595
Hello all, Has anyone tried a more economical alternative to the 9300 RADES (Allen Bradley PLC modem)? Thank you!
Replies
4
Views
2,745
Recently I have requested a quote from Magnetek for their Impulse Drives but can't raise a response from them. I've requested a quote FOUR TIMES...
Replies
3
Views
1,062
Back
Top Bottom