Programming Application - How to use Bit Shifts (BSL) in PLCs
I've been asked many times enough through e-mails, forum questions on how to use a bit shift. I use bit shifts in just about every program I write for an automated machine company. Bits shifts are used in anything from an index table, to a machine that has a walking beam, or even a servo controlled conveyor. What do you use bit shifts for? They can be used for tracking the individual status of multi-product on a fixed mechanical motion device. That's my definition that I am going to try and explain. I only try and use bit shifts when my product or part is confined in a space mechanically locked down. Then you can assign some meaningful way of tracking the part status as it moves through your machine. The most common method is a good or bad part sorter at the end of your machine.
You can download the animated bit shift GIF file here and follow along if you like.
Everyone is entitled to an opinion, so I am going to explain to you my theory of how I apply a bit shift. In my example below, let's assume I have a servo controlled conveyor that indexes. Each bottle is separated one behind the other, and I need to make sure a bottle is in position on my conveyor "carrier pallet", fill the bottle, apply a label, and vision inspect the label on the bottle. If all those condition pass, finally place a cap on the bottle, then send it down stream for packaging. If my bottle doesn't have a label or failed the vision test, then I want to reject the bottle down a reject trap door. I also do not want to waste a cap if the label is wrong or missing.
In my application, I choose to use two bit shifts at the same time. One bit shift "means" bottle is present. So the whole time, regardless if the bottle has a label, filled or not filled, I just want to know that a bottle is in the servo controlled conveyor belt carrier. If a bottle is not in the carrier, then I do not want to fill up that space with liquid when the empty carrier passes under the bottle filler. At the same token, I use the second bit shift to track a good bottle or bad bottle status. This is primarily used for the reject chute at the end of the process. The logic of the reject chute will be, if bit shift B3:0/7 is equal = 1, which means bottle present, but bit shift B3:1/7 is equal = 0, which means bad bottle, then run the reject chute. If B3:0/7 = 1 and B3:1/7 = 1, then do not run the reject chute because the bottle is good. However if B3:0/7 = 0 and B3:1/7 = 0, then do not run the reject chute either because there is no bottle present in the carrier.
So there is no need to place a photoeye at each station when using two bit shifts. Granted, there maybe times when you still need a photoeye at some stations, like if you need to make sure your part dropped down the bad part chute using a bad part chute verify photoeye. Since an index table or other mechanically fixed device can contain the part mechanically, then save some money and place only one photoeye in the beginning of the process to track the status of the part through the machine.
A couple of other rules I'd like to point out with my theory of bit shifts. These are my personal preferences. Most of the time I rarely have any more than 15 stations or operations on a part that need assembled or work. So that makes a bit shift an ideal setup for dedicating one whole word to a tracking process. Since I am going to use the whole word anyway, then I also try and correlate bits to station numbers.
Word file = B3:0 means: Tracking the bottles for part present
Word file = B3:1 means: Tracking the status of the bottle good or bad.
Bit level, B3:0/1 means, is there a bottle at station #1? 1 = yes, 0 = no.
Bit level, B3:1/1 means, is the bottle at station #1 good or bad? 1 = good, 0 = no.
Each bit number means which station to me. Bit 1 = station #1, Bit 7 = station #7. This helps me remember when I have multi-bit shifts, which bits do I need to track certain processes and at which stations. I've had as many as five bit shifts to track a single part through a machine. What this also does for me is I never use B3:0/0 or B3:1/0 in this application case.
Rule number two for me and my bit shift theory is I latch my bit shift bits with an OTL command and unlatch bits in the shift register with OTU commands. I never actually "load" the bit shift up like most people would do. I've seen programming examples where people try and program the "BIT ADDRESS:" field of a BSL instruction to be the loading bit in the bit shift register. I am going to tell you right now in my example here in this article that is NOT how I do this. I set my bits in the shift registers, manually for each station. There will be a time in my life when I will need to load the bit shift from the "BIT ADDRESS" field of the BSL, but for now, I am going to show you a different way.
Example, my bit shift rung looks like this:
B11:0/0 is a bit that is NEVER ON. It stays false all the time. So every time the bit shift "shifts" it moves a ZERO into position B3:0/1 and B3:1/1. This is because I don't turn on B3:0/1 or B3:1/1 until I have verified presents with a photoeye. Once I have cycled the photoeye check logic, then I allow the machine to index again, which shifts the B3:0/1 bit to B3:0/2. This also moves a zero back into B3:0/1 again until I check the status of the part with a photoeye verification. I also have less than 15 stations, so I set my bit shift limit to 15. If you have more than 15 stations, just make sure the next word is clear because the bit shift will try and spill over into the next word if you have your length greater than 16. An example of this is when I had a 72 stop station index table. I set my length to 80 bits and made sure five words were clear to use.
So let's assume the bit shift register is all zeros. When the index conveyor moves the bottles into station #1, then I run some logic which will look at the photoeye input. If the photoeye input is "ON", this is what will set the bits for station #1 part present and part status.
Rule number three for me and my bit shift theory is to always set the bit shift FALSE when a new operation starts. For example, if a part in station #2 had a good status, then the conveyor moves and indexes the bottle to station #3 where it will be filled. At station #3, I start the filling process because the bit shift register has a logical 1 for B3:0/3 and B3:1/3. But as soon as the filling starts, I set the bit shift bit for station #3 to logical 0 (B3:1/3). I do this for one reason. If the filling cycle never finishes, then nothing will set the good part bit status back to logical 1 which means the bottle is good. This can happen if someone e-stops your machine during a filling cycle, or you have run out of fluids during your filling cycle. Upon recovery of your machine, your status for station #3 is still logical 0 which means if someone manually indexes the bottles to the next station, that bottle was marked bad and never completely filled. If everything on each station finishes correctly, then at the end of each process for each station, then set the bit back to logical 1 for that station (B3:1/3). So when the conveyor indexes to station #4, station #4 will see the bottle is still good, and will run station #4 labeler.
Bottles move into position at station #3. The bit shift status starts the filling cycle at station #3 because B3:0/3 and B3:1/3 was logical 1. When your logic detects the filling has started, then use an OTU to turn off the bit status B3:1/3. Leave B3:0/3 alone, because that bit shift status is only for bottle present.
When the filling cycle is complete and finished correctly, then turn the bit status bit back on with OTL command for the same bit you just turned off.
When all the stations are complete, you can now move the conveyor and also shift your bit shift register.
To keep going with the flow of this application, you'll notice that an empty bottle is coming. When that bottle arrives in front of the photoeye at station #1, the bottle present shift bit never sets nor does the bottle status.
Now anytime that carrier or pallet arrives at a station that needs to do an operation, the station sees that the bit shift is equal to zero, that station should not run.
Animated BIT SHIFT:
The animation stops every 2 seconds. There are 52 frames. Study each frame and see if you can figure out the logic of each station and how the parts are tracked.
Here are some more downloads.
Download a 72 station bit shift example program here:
Video clip of 72 station bit shift example good and bad part sorting.
Video clip of bit shift tracking as seen on the HMI screen.