Counting consecutive faults

Bobobodopalus

Member
Join Date
Feb 2020
Location
Surrey
Posts
89
Hi all
I have a program that when a can is rejected from the machine this is put into a shift register, which is moved via a clock pulse on the machine, we currently flag a fault when there are 4 in a row.


--|h20.00|--|h20.01|--|h20.02|--|h20.03|--O 14.14(consecutive fault bit)
is there anyway i can make the amount of faults changeable? is there any function that might do something like this?


using a cp1l-em PLC and NB7W HMI
 
I'm not too familiar with OMRON but one way is to use the trigger and Bad Can sensor to trigger a counter, the pre-set of the counter could be a variable that could be modified on the HMI so a pre-set of 1-10.
The reset of the counter could also be the shift trigger and NOT bad can.
So if a bad can is detected then the first bit of the shift register is a "1" and the counter increments to 1 and so on until the counter reaches the pre-set and turns on a bit, however, if a good can is passed into the shift register then this will also reset the counter.
Caveats:
The error bit from the counter will only be on providing the number of bad cans are consecutive and not the total bad cans in the shift register for example if a pre-set of 5 is entered then there must be 5 consecutive cans enter the shift register. should 4 bad cans enter and then a "0" followed by a bad can the counter will be reset even though there are 5 bad cans in the shift register (but not consecutive).
I suppose depending on what you do when you reach the detected consecutive value i.e. stop the process, allow it to run but latch the alarm bit in until reset by operator etc.
 
Last edited:
parky's suggestion is easier to implement and understand, but if you already put the data into a shift register ...
[AND h20 15 h20] [EQ h20 15]
is equivalent to what you are doing now, assuming the shift register is not used elsewhere and you are not interested in anything more than the most recent four bits (cans) in h20, and assuming h20 can be treated like an integer of some form.



Change those 15s to 7s and it looks for three in a row.


Change those 15s to 31s and it looks for five in a row.


Change those (2^4-1)s (i.e. 15s) to (2^N-1) and it looks for N in a row.


Assuming h20 is a signed 16-bit integer, this approach is good to N=15 (15s become 32767s).



Figuring out how to use (2^N-1) in the PLC when N is entered in some HMI thingy is an exercise left to the programmer.
 
Last edited:
the counter being reset when there is not a fault makes a lot of sense to me, i have a separate addition just incrementing by 1 on the rising edge of the reject sensor.
for this part of the program i am only interested in the consecutive faults, this will stop the machine and display a warning to investigate the cause.



drbitboys method i understand but the being able to change the value in the HMI seems like a bit more work
 
It is easy to do so all you enter on the HMI is a decimal value into the number of bad cans register.
The code below is a way of putting a decimal value (bad count setpoint) on the HMI and converting it into a bit pattern of x bits
So if you put 4 into the HMI bad can count it converts it into 0000000000001111 or 15 decimal (note: due to the way the shift register works you need to subtract 1 from the sum.
Then compare the bit pattern so if the first n bits are the same then the bad can count is true. Note: this works based on n cans entering the shift register so it only compares the number of bits related to the decimal value on the HMI bad cans so if the bad can number = 6 it looks only at the 6 bits (0-5) and ignores any odd bad cans further down the shift register.
You will need to convert this into OMRON tho.

Bit Compare.png
 
[Update: second! I didn't see that parky already coded summat similar; I did not assume there was an SFL instruction or equivalent]


drbitboys method i understand but the being able to change the value in the HMI seems like a bit more work


Yes, I agree, use parky's method and you will thank yourself the next time you look at it in a few months; only bitboys ;) would do it the other way.


That said:

  1. user enters number of consecutive fault cans
  2. user hits (HMI?) button to send that number to PLC e.g. to h32 (with check to ensure value is in range [1:15])
  3. PLC detects sent value and MOVes a 1 into h31
  4. On each successive scan, as long as h32 is greater than 1:
    1. shift a 0 bit into h31 (or multiply h31 by 2)
    2. Decrement h32 by 1
  5. whenever h32 equals 1, subtract 1 from h31, put result in h30
  6. use h30 in AND and EQU instructions in place of the 15s
It will take up to 14 scans to update the process with the new value, but that should be quick enough.
 
Last edited:
haha you could also write a linear function of the number of bad cans to check into the exponent bitfield of a REAL, and subtract 1 from that REAL to get the bit pattern.


Only a bitboy would do that though ;).
 
Nice one My logic does it all in one scan I have not added the shift register for the bad cans only convert an integer to the bit pattern You are right the HMI should have a limit (most have limit fields to limit the range as standard) there is no need to have a button to write it to the PLC, HMI's always write on change so pretty instant. The shift function completes the shifts in the function so is effectively instant before it moves on to the next as bit 0 is always 1.
(not sure if this works in other PLC's like AB as to do a shift takes a lot more coding if I remember correctly).
I also did one using a for next loop & indirect addressing with exit for on reaching the bad count or a zero.
There must be many ways to do this but I'm not going to find them all lol.
 
Sergei, unfortunately he only wants a count of bad cans consecutively and assuming you mean count the "ONES" in the shift register would not do what he wants, however, this has just pinged an idea for the OP.
Why not expand the info on the HMI so not only detect x bad cans consecutively to stop the plant but add a total bad count with a reset button so the operator can see how many bad cans in total during the shift.
 
  1. user enters number of consecutive fault cans
  2. user hits (HMI?) button to send that number to PLC e.g. to h32 (with check to ensure value is in range [1:15])
  3. PLC detects sent value and MOVes a 1 into h31
  4. On each successive scan, as long as h32 is greater than 1:
    1. shift a 0 bit into h31 (or multiply h31 by 2)
    2. Decrement h32 by 1
  5. whenever h32 equals 1, subtract 1 from h31, put result in h30
  6. use h30 in AND and EQU instructions in place of the 15s
It will take up to 14 scans to update the process with the new value, but that should be quick enough.




Duh on me: step 3 should MOVe a 0 into h31; step 4 should shift a 1 bit onto h31 when h32 is greater than 0 (not greater than 1); step 5 should move h31 to h30 when h32 is 0 (not when h32 is 1).
 
thanks for all the replys, i already have a bad can count that is resetable for total faults, i've been a bit busy lately but i will get this solution made into a function block one of these days.
 

Similar Topics

Hello, I am in need of a solution to a problem I've failed to come up with a solution to that doesn't take entirely too long for my needs. I...
Replies
40
Views
15,622
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,687
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,466
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,389
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,512
Back
Top Bottom