TIA Portal #16: Shift and Rotate in Tia Portal | Bottle filling using shift register

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Are you interested to learn how this filling machine with different bottle sizes works? Let’s see it together. Hi friends. Welcome back to the channel. You asked me in the comments to have a video about this topic so today we’re going to talk about the shift and rotate operations and how to use them in Tia portal. In the end, we will create together a project to track bottle positions and fill them with different sizes using a shift register. First I’m going to explain what shift and rotate mean. As we know the binary format of 5 is 101. if we want to store this value in a byte in PLC memory it would be like this. Now if we want to shift all bits one bit to the right or left, what do we have to do? For example, if we move all the bits 1 to the left we will have this value. Each time with shifting, 0 will be added to the first bit from the right. The new value now is 10 in decimal. Or if we shift the bits to the right, the last 0 comes from outside, and 1 that was in the bit 0 is shifted now by one to the left. in fact, it will be deleted and the new value is now 2. So we can shift the bits to the right or left and change their position. But as you see when a bit comes to the end of the right or left side, with another pulse it will be shifted outside, and actually, it will be deleted. Sometimes we need these bits again and we don’t want them to be deleted. In this case, we can use rotate. Rotate is exactly like shift but the bits which go to the right or left are not deleted and they come back to their extreme left or right. Same thing we can do with tia portal. Go to the program and open the main ob. From the instructions, there we have shift and rotate. SHR shift to the right, SHL shift to the left, and rotate to the right, rotate to the left. Let’s put the shift and rotate right into the program. Shift right is used to shift the content of the input IN bit by bit to the right. Input N determines The number of bit positions by which the value is to be shifted. For example with n equal to 4, 4 bits will be shifted when the input enable is activated. Let’s define each input and output. If we open the 3 ? mark we can select the data type. If you don’t select a data type TIA can detect automatically the data type according to the type of the variable in input IN. En is enable. Be careful if you leave here open this function will be executed with each plc cycle time which is approximately 5 ms. So use always a button here. But we can not turn it on and off very fast in 5 ms. It takes 1 or 2 seconds to do this and during this time the shift or rotate register will be activated hundreds of times. So we define in the software for this button a rising or falling edge. The inputs and outputs for rotate are the same as shift. I’m going to simulate the program. Hit the glass icon to monitor the program. Let’s modify the input value 5 in binary format. When there is no pulse in enable input, the data is 101 which is 5 in hexadecimal, when we have a pulse in enable, bits are shifted to the right. With another pulse, bits will be again shifted. Let me first modify the new output in the input. That’s how bits are shifted with every single pulse. One interesting thing. If you remember in data types when we have a signed value, for example, a signed integer, the first bit is the sign bit and if we shift and change this bit the sign of the value will be changed. Let’s modify a value with a signed bit 1. (10001000) as you see the decimal value is minus. I’m going to shift the bits. Now our shifted value is positive because the sign bit is 0. Tia has a solution for that. When you choose the data type as a signed integer, the most significant bit will not be changed. Here we have 1 in the highest bit and the shift operator with each pulse will not change this bit. It actually copies this value to the next bit. That’s the difference between shift and rotation. For rotate, you can only use word double word, byte and long word. Also, be careful using the data type. If your variable is a word and you select for rotate or shift byte, only 8 bits of the word which are 16 bits will be shifted. Alright, that was the basics of rotate and shift. Let’s do a project together with a shift operation. The most application of shift in the real world and industrial projects is a shift register. Where you have for example a machine with some levels or steps that each one is considered as a bit. So we shift basically these levels from each step to another one. For example, here we have a bottle filler with 8 filling nozzles, filling the bottle with 2 different sizes. 200 and 500 ml. each filling station is considered as a level or step. So we need to track the bottles to know their size and position and fill them according to the size. How we can do this project in TIA Portal? Imagine these 8 filling places as data bits of a shift register. When the size of the bottle is 500 ml we consider the data bit as 1 and 200 ml as 0. Now we can use a height sensor to detect which bottle is 200 ml and which one is 500. I have used another sensor. think about it and write in comments the reason for using this sensor. First, we have a big bottle. The height sensor detects it and gives 1 as the output. With starting the conveyer bit 1 will be shifted. Next, we have a 200 ml bottle which gives 0 from the height sensor. Similarly, the data bits in the form of 1 and 0 are being entered into the data register and shifted right with each new bottle. In the end, Based on this information we can create the shift register and we know which bit is 0 or 1. In this way, we can track the bottles and fill each one correctly. Let’s see our program in TIA. To save time I have already created the program. I just show you and explain each network. First we need to detect big and small bottles. So when the height sensor is false and the second sensor is true it means we have a small bottle. And when both are true we have a big bottle. With each bottle the program gives you 2 seconds and after that, the conveyer starts for 4 seconds to move the bottle to the next station. I used a counter to count up the bottles. We have 8 stations and Our register is a 8 bits so with the 8th bottle the counter will be reset. After that and after 6 seconds, the filling will be started. 6 seconds is 2 seconds for waiting and 4 seconds for the transition of the last bottle to the filling station. Next network. as you know when we shift the bits to the right, 0 will be added from the left. But When we have a big bottle we need to add 1 to the first bit from the left. So with this network, we can do this. 80 in hexadecimal is equal to this number in binary. Next we need to reset the shift register when the filling of 8 bottles is done. So when the filling is finished and with falling edge 0 will be moved to our register. And also stop the shift operation when the number of bottles is 8. Here we have the main network. With each pulse of bottle detection and if the number of bottles is not 8 the bits will be shifted to the right. And finally filling network. When a bit of the shift register is 1, a long filling with 4 seconds will happen. If the bit is 0, filling will be 2 seconds. Let’s start a simulation. The first bottle is big. After 2 seconds the convoyer will be started. The shift register is now 40. Let me show you 40 in binary format. 1 is shifted to the right. Next is small. And then again big bottle. And the last one is small. In the end, we will have this shift register. I have increased the filling time to understand the process better. The big bottles with the value 1 will be filled 40 seconds and the small ones just 20 seconds. You see the bits are exactly like what we have here and the bottles are filled correctly. Shift register and counter are again 0. Alright, this was a simple example of using a shift operator in the Tia portal. Based on your requirements you can change some parts and use it for yourself. This program has also some weaknesses that I want you to tell me about in the comments. For example one of them is in the filling section. What happens if all the bottles are small. For more exercise write a program with a shift register to detect the boxes and at the end of the conveyor, an arm sorter will sort the boxes to the right and left. I hope this video could help you improve your tia portal programming. See you next video. Bye.
Info
Channel: Industrial Automation
Views: 2,183
Rating: undefined out of 5
Keywords: tia portal tutorial, step 7 tia portal, tia portal, step7, آموزش تیا پورتال, آموزش نصب تیا پورتال, plcsim, plcsim v16, tia, plc, v15, v15.1, v16, s7, 1200, 1500, beginner, s7-1200, s7-1500, plc programming, tag, v14, hmi, wincc, intro, v17, example, siemens, how to, automation, programming, tutorial, help, how to download and install, Visualization, iec61131, sps, short integer, Shift, rotate, shift register, shift register in tia portal, bottle filling using shift register, bottle filling in tia portal
Id: XvRjnn5FIFY
Channel Id: undefined
Length: 15min 24sec (924 seconds)
Published: Sat Jan 28 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.