Sign in to follow this  
Followers 0
gblack

Counting bad parts

8 posts in this topic

I have an application where I need to shut down a machine if 5 of the last 10 parts were bad. I wrote some code that uses a bit shift to set bits in a word for every bad part, but I can not find a simple way to count the bit on in a word. I did come up with a method of using these bits to count into another word and it works fine for 10 parts but would get pretty complicated if I have to expand it to 20 or 30 parts. Does anyone know a simple way to get a percentage of bad vs good parts? The application is using a micrologix 1000 with an input to show a part is in the test area and an input that identifies the part as good.

Share this post


Link to post
Share on other sites
OK, I haven't tested this, but RSLogix will let you enter an address like N7:0/35 which is N7:2/3. I'm pretty sure that as long as you don't index past the end of the file you won't get an error. So you should be able to use a FOR loop to count through the entire shift register using an indirect address Let the bit shift register be 3 words long N7:0 to N7:2. We will use a FOR NEXT loop for 0 to 47 (48 loops) Create the following: SOR CLR N7:10 EOR SOR CLR N7:11 EOR SOR LBL 1 XIC N7:0/[N7:10] ADD N7:11 1 N7:11 EOR SOR ADD N7:10 1 N7:10 EOR SOR LES N7:10 47 JMP 1 EOR I'm pretty sure this will work. I'll load it up and check it tomorrow. For a 10 bit shift register, modify the loop termination value from 47 to 9. EDIT: Nevermind. I forgot that the ML1K does not support indirect addressing. It won't work on the ML1K. But it will work on ML1500 and above. Edited by Alaric

Share this post


Link to post
Share on other sites
Take a look at something like this, count the bits with a "Counter" or "ADD" function that are loaded into the bit shift, then subtract them back out after part 10.. in this case at bit B3:0/11. Edited by TechJunki

Share this post


Link to post
Share on other sites
I would do something like this ... SOR BST XIC PART_PASSED NXB XIC PART_FAILED BND OSR OSR_BIT BST XIC HISTORY/0 SUB COUNT 1 COUNT NXB OTU HISTRY/0 NXB DIV HISTORY 2 HISTORY NXB XIC PART_FAILED BST ADD COUNT 1 COUNT NXB OTL HISTORY/9 BND BND EOR SOR GEQ COUNT 5 OTE STOP EOR where: HISTORY is a word containg the last 10 results COUNT is a word containg the number of fails in the last 10 parts It uses divide by 2 instead of bitshift (making sure bit 0 is clear otherwise it will round-up) and stores the latest result in bit 9 to reset clear HISTORY and COUNT Edited by Spedley

Share this post


Link to post
Share on other sites
I would just copy and paste a bunch of rungs inline. Who cares if there is a rung for each bit? CLR n7:0 XIC b3/0 ADD n7:0 1 n7:0 XIC b3/1 ADD n7:0 1 n7:0 XIC b3/2 ADD n7:0 1 n7:0 XIC b3/3 ADD n7:0 1 n7:0 XIC b3/4 ADD n7:0 1 n7:0 XIC b3/5 ADD n7:0 1 n7:0 XIC b3/6 ADD n7:0 1 n7:0 XIC b3/7 ADD n7:0 1 n7:0 XIC b3/8 ADD n7:0 1 n7:0 XIC b3/9 ADD n7:0 1 n7:0 GEQ n7:0 5 OTE bad_cond Very easily read by the guy that has to support it later on down the road on the shop floor. At a glance he knows exactly what the goal is. I won't get any phone calls asking me about this. Edited by jstolaruk

Share this post


Link to post
Share on other sites
How would you set the bits in B3:0 ?

Share this post


Link to post
Share on other sites
Oh, you need the bit shifing logic too? For anything less than 16 parts you can use XIC bad_part OTE B3/0 XIC shift_parts OSR temp MUL B3:0 2 B3:0 If more then 15 XIC bad_part OTE B3/0 XIC shift_parts OSR temp OTE many_shifts XIC many_shifts BSL #B3:0 R6:0 B3/0 1 XIC many_shifts BSL #B3:1 R6:1 R6:0.UL 1 ... XIC many_shifts BSL #B3:n R6:n R6:n-1.UL 1 then test CLR n7:0 XIC b3/1 ADD n7:0 1 n7:0 XIC b3/2 ADD n7:0 1 n7:0 XIC b3/3 ADD n7:0 1 n7:0 XIC b3/4 ADD n7:0 1 n7:0 XIC b3/5 ADD n7:0 1 n7:0 XIC b3/6 ADD n7:0 1 n7:0 XIC b3/7 ADD n7:0 1 n7:0 XIC b3/8 ADD n7:0 1 n7:0 XIC b3/9 ADD n7:0 1 n7:0 XIC b3/10 ADD n7:0 1 n7:0 .... XIC b3/n ADD n7:0 1 n7:0 GEQ n7:0 ??? OTE bad_cond Edited by jstolaruk

Share this post


Link to post
Share on other sites
The following program will work in a ML1000 to count the number of bits set in a 16 bit word. It has been tested. Rung 0: SOR BST MOV N7:0 N7:1 NXB CLR N7:5 NXB CLR N7:3 BND EOR Rung 1: SOR LBL 1 BST XIC N7:1/0 BST ADD 1 N7:3 N7:3 NXB OTU N7:1/0 BND NXB DIV N7:1 2 N7:1 NXB ADD 1 N7:5 N7:5 NXB LEQ N7:5 15 JMP 1 BND EOR Rung 2: SOR MOV N7:3 N7:4 EOR You can adjust it for 10 bits by changing the LEQ instruction in rung 3 from LEQ N7:5 15 to LEQ N7:5 9 The contents of N7:0 are copied into N7:1. Next a For loop is executed against N7:1. This is the general format: For I:= 0 to 15 If the least significant bit of N7:1 (N7:1/0) is set, increment the bit count by 1 and clear the bit Divide N7:1 by 2 End For The final bit count result is copied into N7:4.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0