TIA Portal: Bit Rotation and Shifting

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to today's video last time we talked about left shift left rotate right shift right rotate and just in the theory today we are going to program those with the same example that I had here actually unless of you I didn't mention applications for this I think the most valuable application for this is actually a shift register where you have a workpiece or you have a machine that has in our case here it's 16-bit it has 16 steps one workpiece at a time can be at any of those 16 steps and those steps are usually one after another all right so let's assume we have the following scenario there's work pieces sometimes they are green sometimes they are not green so one here indicates they are green zero indicates they are not green the green ones they have to be treated specially so we need to somehow remember that in our memory which position is that workpiece in so we are basically shifting our our manufacturing sequence here through from each step to the other step so now we did one step next now we do another step next now we do another step so it doesn't matter at which position our workpiece is we know exactly hey ok this one that's here right now is green this one is also green this one is green this one is not green this is not green not not not not not and then one more step right everyone is done with that step we push it all one to the side or a conveyor belt goes one step further but we now know hey this was green this is not green this green green and so on and so on we're shifting this through our whole production right and then sometimes we start back from the beginning which would be rotating and sometimes we just push it and then it's gone all right outside now we know all the pieces are done nothing is green anymore no special treatment for those pieces that's one and the most important application is shift registering now that's what we can also shift to the right shift to the left depending on our sequence that we have the other application that some people mentioned on the comments last video is the following if I now have a zero zero zero zero one that is the same value as a one in integer right in our word that would be a one if I now shift it once to the left that is one zero meaning this is a two if I shift it again that's one zero zero now it's four if I shift it again that's one zero zero zero that's eight shifted again 16 32 40 64 128 256 512 and so on and so on and so on meaning we always double by two we could do the basic mathematic operation times two if we shift by two digits and if we shift by two digits that would be times four right if we shift by three digits that would be times eight so that's shifting to the left shifting to the right would be the same but not multiplying by 2 but division by two right if I now right shift this thing here by one we are basically having half of the value so right now it is a one zero that is a 2 if I right shift by one that is now a 1 so we can do those mathematical operations which is important on like a microcontroller assembler level but for our automation you just in your program you just write x 2 no one cares your controller is powerful enough so that's a rare application in higher devices like inexpensive and strong devices it's pretty rare that you actually MultiPlan to fight like this you just write in your program x - that's it pretty much all right pretty simple ok and just because I forgot to mention some applications there's definitely more but those are the important ones those are the ones that you usually get to see especially the shift register very important stuff so what can we see right now I have this one you see right this one I can shift left I can't shift right what's missing I can rotate left but you see which one doesn't work right now this rotate right doesn't work unfortunately because I deleted it from program we're going to create that now together right we we are going to create this rotate right so I will push my HDMI away and here is my PLC program and we're going to create this what was it rotate right therefore we have in our instructions when we are in the program we have instructions there we have the so called shift and rotate there we have SH our shift right SH L shift left our our rotate right our or L rotate left as those four they all work very very similar that's why I only show the rotate right because then it applies the same thing applies to all the others as well it's just one difference I will show that so we need to rotate right because that's the one I do not have my program you anymore rotate right it does not work anymore so let's take the rotate right let's whoops let's take rotate right let's put it in our program and you see it looks like well a little block we have this little block we have RoR we have three question marks if I go here to the question marks I can select the data type let's leave that open for now because if we leave it open it will automatically decide which data type is correct so now what do we need we have an en en is an enable if this enable is true so logic one we will execute the command so what do we want on this we want this rotate right at this button we want this button this button I have prepared I have prepared actually a database that's communicating with my HMI we choose the button I can actually show it which one is the button I forgot which one is the button let me show it and let me see in the other program pod say the button is there okay it's just called rotate right this one is linked to the button so I will just put that here with a normally open contact Hyuga right now if I press the button enable is on meaning we are going to do that if you leave this open if we leave this open this enable is always active meaning that we always do the operation meaning a thousand times per second approximately we are going to rotate right that might be a little bit too much you always want to have something on the enable here just in my case this button then we have an inn and you see at the orange lag here the orange lag indicates that we need a data type there we could put some data types here if we hover on top of this we snow it can be a word it can be a double word it can be a byte it can be a long word long word only available for 750 hundreds the rest is available for pcs this is where my input value goes that I want to shift and I have called this variable just variable that's what I want to shift then I called it byte which is actually not correct because it's a word why did I do that word now I need to recompile my whole program damn it got them yeah that's still an operon missing you need to of course connect something to all the inputs and outputs and now that I put a word variable here we automatically see we see that the block automatically decided hey this is a word I am going to work with a word value done right so we don't really need to care about the datatype that it's using the next step we have is an n this n indicates how many how many positions do we want to go right if I have this value right now it's a zero zero zero zero let's make it a 1 whoops let's make it a 1 I have moved by one so if I shift left here by one we're moving the one position I can also do it by two positions by three positions by let's say six positions so we really see it right now it's one zero zero zero and it will be 1 0 0 do a little shifted by six positions you see it we're jumping by 6 positions just by one button press right usually you want this add one but of course every other integer number would be ok that's why we are also limited here to integer right and you see also some others but or full numbers is it called for numbers or natural numbers I think natural numbers not negative but all positive natural numbers or I could too type of constant if I want to right now I put a 1 so it will always shift by 1 but I want to be a little bit flexible so I'll take this move by this is the value that I put in here you can also put a constant there no problem at all next thing is the out what we will have our tea at the out this is where are we going to push that value right where are we going to push that value so therefore I have created this feared here you see every operation here has a fear next to it this feared is unique right so each field uses another variable what I want to do first is I actually want to use the same variable that I use as the input so I just want to push the same variable on and on and on and which is the standard case usually you don't have something this is just for display he actually usually don't have something like this you just rotate the same variable that you actually have as an input that's what I'm also gonna do so I'll take my input control C control V and I have it on the output side here good that's that's pretty cool that's pretty cool that's what we have so now if i download in my simulation now i download the my simulation and here i go finish it everything's good now i didn't know that would happen that's fascinating that is fascinating i did not know that would happen i just do that so right now that's that's funny right now you see this is a little bit funky actually see this it actually displaced up here just those those those grid signs those those signs which indicate hey i do not have a valid value for this and we have if i click growth head right if i keep it pressed you see it starts rotating all the time if i just press it once very quick you see just jumps random since that's pretty stupid why does it jump random positions that's very strange right that's very strange it should not do that it should not do that it does it because let's have a look here if I go online I see my rotate right and I see my rotate right if I click the button you see it as active and it's kept active so it's forever active that is a big problem right there is actually a big problem because we're doing it over and over again how many times do we want to do it just one time we only want to do it one time so what do we have to do either click this button for exactly once which is very difficult or transform it to an edge so and that's what I also want to do I want to transform it to an edge which I can simply do here I can't just double click on the operation and I just say P for positive edge and I also have a trigger bit prepared remember those edge trigger bits they always have to be unique in your program so if you use this twice in your program doesn't work it has to be unique so I have five HSC in my program and every Edge has a unique edge trigger bit so if I do this I download you see everything is going to be fine now not everything yet we will see in a second so if I go online you see this is ok now if I click you won't even see a turning green because it is only agreed for one cycle and that is approximately one millisecond and we will not see that because it is so short and it is below my refresh rate so we won't see it we might see it with the chance of one to a thousand but then only for one millisecond which is very very various fast so if I click now you see we just rotate by one it doesn't matter if I keep it pressed we just rotate once and that would be the same for all others as well so try to use some edge at the enable input so that you don't rotate over and over the other problem that we saw here is those what are those in English I call it hashtag right now because I'm young it is not called the hash tag pound sign it's a pound sign those pound signs actually indicate hey the hm I cannot find this variable and that's the case because I renamed it here what I need to do is basically restart my HMI and then it can't find the value because I didn't I didn't compile it in before so let's do it this will take a second until it starts off the compilation started at five percent complete HMI is starting as soon as the HMI starts now it should have the link to the variable I think I clicked twice is that true then it might take a second so because it actually opens and it reopens and then it destroys everything I'm stupid for clicking twice so fix that problem as well because if you rename a variable on your database on your memory you also have to do that on the HMI at least recompile and start the whole thing that'll be automatic Reena Ninan but it couldn't find the variable variable byte it was named it couldn't find and now it knows hey I should saw it for very real word okay why didn't you tell me that it works I think my runtime actually crashed I don't know okay so this is how you would normally do this left shift right shift whatsoever this rotation there's movement of bits I did those bit operations that's how you do it that's the standard thing so what I also have because I like to have a good overview is on my action I hear what you see for the others you see that I have also this little field that says hey this is how it's going to look like it is definitely not necessary definitely not necessary but I would just show you because it's quick and easy to create and then we're good with the video so this looks like the following what I want to do is I want to always display it so here at the output of my rotation I want to have something that is this just rotate it and it should always be the case so I don't want the something at the neighbor because I always want to shift it it's just for this play right it's just for this play so I will take my right rotate it I've prepared that it's a word again I take this and put it here at the output this is linked to my display value here now when I press the button I actually want to move this variable into our input but only when we press the button so if I press the button move this one in here right that's the same that I did everywhere else if I press the button move this value from here into the value that we have at the input this is something not necessary but I like to do that just so I know what's going on so I'm now always pushing the value into the rotated value and I'm only taking the rotated value and put it to the input if the button is pressed this is just for an overview so now this one should behave exactly as the others on button press that's with the edge detection we're pushing the current value the the rotated value into our current value and this is how you can do it also a little bit tweaks as I said the version that I had earlier without this year at the end basically like this and this and this this is the standard version that's how you want to use it all right the rest that I did was just additional stuff for display I said there's one thing we have to we have to take care and that's this if you have a rotation and if you have a rotation you can only select word double word bite and long word because when we are rotating we are really rotating bits from the beginning to the end and from the end to the beginning again so we're rotating around that does not make sense in a mathematical way if we're talking about in integer value about values it doesn't make sense hey I have one if I rotate once now I have 255 that does not make sense or 256 that does not make any sense that's why for rotation you only have bit values right all we are not talking about bit values for error --air for shifting not rotating but for shifting you can also work with numbers with integer number short integer long integer answer integer and so on because there it makes sense because left shifting multiplying by 2 right shifting division by 2 so here it definitely makes sense also to have those data types right so don't be confused in the end Tia portal tells you what it needs all right T at Pala tells you if you have no idea just let it automatically decide there were question marks and now there's integer don't need to alright don't need to there is however one difference between I have a shift when I using a word value I have a shift when I'm using an integer value so this one uses the value this one is just a bit sequence the bit sequence behaves a little bit different than the real value the integer value the bit sequence so the bit sequence if I shift to the right takes a 0 at the highest place the integer the mathematica cause the one on the left it actually indicates the plus or minus sign it automatically takes the 1 and it actually adds a 1 so it stays mathematically correct so if you select integer or what makes a difference and they're there you need to be aware but only when right shifting actually so if you right shift take care of your data type yeah maybe one more thing now that we are edit also be aware of the size of your bit string if you have a word you also want to rotate a word if I now for example select hey this is just a bite so instead of 16 bit I rotate 8 bit you see it makes this little square which is a type transformation typecast which is a typecast it goes from this is a word internally it's now a byte so we're losing a bit if I do that be very very careful I'd be very careful about this because now let's look at my right rotation something looks strange right you see this it doesn't push to the complete left it only pushes until bit eight so this does not work anymore very like in our case it doesn't work anymore so I have a sequence of ones and zeroes right if I have a sequence and you see here it just cuts off at bit number eight right it just cuts off half of it because I took only a byte so please make sure that if you're working with the word also use a word that's it that's pretty much it I talk too much about rotation and moving and whatnot I hope this is any helpful if you liked it leave a like if you have any comments any questions leave a comment I try to go through those but it's pretty difficult it has gotten pretty difficult since I have now 3,000 subscribers thank you everyone by the way for 3000 subs that's just great and it's quite difficult to get through all the comments but I it is a small community now so pretty cool that you also answer each other I liked that I saw that on a lot of questions thank you very much everyone for your help continue doing that continue hitting the like button continue hitting this subscribe button and as always I will see you in the next video bye bye [Music]
Info
Channel: Hegamurl
Views: 18,011
Rating: undefined out of 5
Keywords: tia, tia portal, plc, siemens, plcsim, advanced, v15, v15.1, v14, clock, controller, simatic, 1500, s7, hmi, tp700, tp900, tp, easy, learning, intro, beginner, help, training, navigation, change, quick, fast, english, german, 1200, s7-1200, s7-1500, data, users, wincc, basic, simulation, example, templates, template, screen, screens, copy, paste, panel, new, key, table, admin, trace, trouble, v16, features, force, test, testing, difference, watch, watch table, rot, byte, word, shift, sh, right, left, rotate, bit
Id: Dh6J-rzjAsE
Channel Id: undefined
Length: 21min 46sec (1306 seconds)
Published: Thu Jan 16 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.