Transcript for:
Siemens S7-1200 PLC and Encoders Overview

hello everyone in this video I would like to discuss how can we use cens i7 1200 PLC to read the sensor or read the incremental encoder for counting the signals from the sensor or incremental encoder so we can measure the speed or measure the distance this is very common case if you are developing one packaging machine or conveyor or some very simple distance or speed measurement system one typical case I showing in this picture we can use the regular sensor detect the P from the roller maybe this roller has one PA one revolution maybe 100 puses one revolution or a little bit higher end that you can use the incremental encoder the incremental encoder mounted on the Sha for example if you are using 1,000 lines of that incremental encoder that means 1,000 counters represent one revolution so if you receive 1,000 counters from this channel the highp is channel that means the roller run one revolution right so in this case I would like to show how can we implement this if you already have some basic knowledge on CS s 7 1200 PLC probably you can read this application example that from this number 10 97423 46 and from this application example it includes three examples for counting the speed or counting the distance for that which is very useful so you can download the manual or download this project and in this video I will start from the scratch to explain how can we use the hsc's resources of this controller so we can read the counter from that ID 1000 channel so we can read the counter and after we got the counter we can do a little bit simple Mass manually program how can we translate this counter to Revolution per second or RPM Revolution per minute before we start I would like to explain the basic knowledge of this incremental encoder for the new learner probably you can browse the Wikipedia to search the incremental encoder and read the detail on this page so the basic idea of this incremental encoder it has pople lines here and and per revolution of this encoder it might give you hundreds or maybe 1,000 or maybe higher resolution the common resolutions from the incremental encoder in Industry world the probably from 200 lines to 4,000 lines per Revolution therefore if your incremental encoder mounted on the shaft and if your shaft run one revolution so that means you will get 200 PES or 4,000 PES depends on the incremental encoder resolution you are using if you are using the common incremental encoder so the basic channel from the incremental encoder it can give you a and b two channels the two channels actually run like this to count the actual signals one channel that's enough so we can use this raising H to count how many counters from the signal the reason why we're using two channels usually the incremental encoder give us two channel one thing that A and B can give us a Direction so if a Behind the B maybe that represent the forward if the a at the left side of the B the system will know you are doing the reverse another thing that is this a quadrature output for some system when it's counting the incremental encoder actually for one PA it separate four paes inside you can imagine for this small area it actually count this raising Edge this FL FL and this resing ede and this area so one p before now it actually count four times for that so it depends on the qual setting from your reader the incremental encoder reader in the Cs at 7200 the channel when we config the channel it also have this quar setting but usually if your system do not need that high resolution so probably you just select the normal way that means your incremental incoder reader will use the Rising age to count the counter and use a and b judge the direction you do not need to select this ACC qu to Second it depends on the system resolution you need okay so this is the basic idea for the incremental encoder you can read the detail on this page in this test system I'm using cus i7 1200 this CPU 1211 this small controller and it's pretty small and from the input of this controller here I'm using A and B from the incremental encoder connect to the input Channel 0 And1 that is the A and B from the incremental encoder and the incremental encoder I'm using that's the back of this incremental encoder it has one24 lines per Revolution and this incremental encoder mounted on this DC motor shaft here and from this gear box so the DC motor run a slower speed that is a 150 RPM speed and I can use the analog output use this module to control the speed of this motor and in this test I will run this shaft basically one revolution per second so we can verify after we read the incal encoder calculated the value then showing the revolution per second should show around one so this is the basic idea for this test all right let's go to seens system TI portal let me show how can we config using CS s7200 PLC and read the incremental encoder value and in my ti portal project I'm using i7 121 so my controller it has here so even this is a very low-end controller we know this is 11 the lower number on here the lower performance but it still have a six higho counters resources in this controller okay once we set up the hardware we drag this controller at here from the right side this device overview from here you can see the system will automatically assign the address and show the resources from this controller HSC this is high pass counter the first one is start from the 1,000 and to6 that means this controller give us six resources to check the resources for your controller and check out what the highp speeed this resources can do we can find the simens S7 1200 PLC system menu and then if you go to the chapter 1.1 here it shows high-speed counters we can see for my system 1211 see it has six resources inside and it can take 100K HZ which is very fast so and this is the beauty in you do not need to purchase any additional hardware and in this case I will use this resources one hicore one and our Jo will start from 1,000 when we read the data from this resources that come from the ID 1,000 ID means the D that is a double word double word that includes four bites so that's why it come from zero one to three so four BU here for reading the channel in named ID One S I will show how can we use this after let's go to the system Hardware properties double click this controller let's go to the high speed counter HSC this page we can pick the resources one actually you can pick one of them it doesn't matter because if flexible we can config which Hardware Channel belongs to which resources this just represent resources okay so we can pick the number one and check this enable Okay we enable this resources okay we enable this and the type of the counting so it includes four modes counter period frequence and the motion control and regarding this motion control I used another video shown how can we use the incremental encoder as the prision feedback and the prision access the techn knowledge object here we can config the motion control use this High House counter to read the incremental encoder but for the simple case most of cases we will select the counter personally I would recommend we select the counter even you do doing the frequent or period counting because you can imagine once you got a counter you can calculate everything you want for the frequence for the period or for the distance but once you select the frequence and after that in case you need to use frequence translate to distance that's is a little bit hard but for the counter that's is very fundamental once you got a counter you can do everything else I will use the next video to show once we receive the counter and how can we use the counter to calculate the speed of the motor translate from the counter to the speed Revolution per second in this video we mainly focus on how can we read the incremental encoder read the counter into the PLC and here the operation phase this is very important if you are using the very simple sensor just the one channel sensor so you can select this a single phase for example for one revolution maybe you count 10 poses you can select this a single phas but in this case I'm using the incremental encoder so I need to select this AB counter so this AB counter I need to use the two channels the one channel is a one channel is B so I can use this two channel to know which direction is running positive or negative and this full fourward that is for the C mode so most of the cases we will select this AB counter okay and initial coun in direction that count up or count down initially we can select this count up if you find once you set up system and once this motor start to run and you find this direction Go reverse then you can pick this countown and here it shows initial counter and high limit low limit basically we will leave all those as default if you do need change the preset value or comparison value we can use the program to set those value I will show how can we call the program after and the reference value that's also a important value most of cases we will use that some cases if you want to compare the counter to represent this roller reach to some certain distance and then you need to call the interrupt and using the interrupt control the signal turn it on or do something so we will call the event trigger I will explain this very shortly and for those synchronized input capture input and gate input you can read the detail from the s7200 that menu also you can read the application example from this example two and the three is using the hardware gate so it explained how can we use the capture and gate input okay one important setting here that's is this event configuration as I introduced from the reference value here so probably you can set a where high value that represent maybe 10 revolutions or maybe a certain distance for that once it come there so that time you need to Output one thing so you can use this event configuration you can turn it on and you can see here this event configuration represent the counter value equal to the reference value zero that means once you set a certain value at here this reference value so once the counter reach there it can output one thing so which channel you want to Output here we can let the system call the hardware interrupt so for example if I add one Hardware interrupt here so we can call this 40 okay so keep in mind here it can generate one thing if I click okay so the system will generate this OB 40 hardware interrup and then we can go back go back here so we can see the system generate this Hardware interrupt this is that name and its priority is higher than the ob1 the main cylic organization block so that means once the system count up and count Reach This value reference value it can automatically call this Hardware interrupt and in this interrupt and in this interupt OB 40 you can do the logic here or control the output for example you can fire the nozzle or you can fire the printer to turn down the tools so this comparison event this interrupt is much faster than the normal logic you do the counter data comparison okay this is event configuration and then we can come here the hardware input here that represent which Hardware Channel we can assign for this highspeed counter resources for the resources one we can use the Channel Zero and one the input 0.0 is for channel a and channel B we can connect to the 0.1 we can see the highest frequenc from this Hardware that's is 100k HZ okay here we assign the hardware Channel and after assign here we need to keep in mind one thing this 0.0 and 0.1 let's go to here still under the CPU properties go to the digital input here the Channel Zero and the channel one they are 0.0 and 0.1 so from here keep in mind one thing the channel this input filter the system will automatically assigned the filter at here keep in mind probably by default some cases the filter would be assigned as 0.1 milliseconds here it depends on the noise from the incremental encoder signals the system will automatically default will select 0.1 mlion seconds which is here so there's one reference table from a7200 menu if we go to chapter 6.6 configuring the operation of the CPU from this list it shows so basically this is recommend input filter time if you using the 100K HZ the filter time you need to set below 0.8 micro seconds probably we can follow this 3.2 so if we go back to the ti P keep in mind this is a micro this area this is milon seconds so here this is very low so we can select 3.2 or lower than this so probably we can pick the 0.8 micro this is a MC then they found so this is channel one we will set 0.8 microc we done the configuration we set this filter also we active this hypothesis one and we pick the Hardware Channel 0.0 and 0.1 for this resources and also we config this type this is counter and it's mode is a and b counter for reading my incremental encoder okay let's download this Hardware controller okay let's start the controller to read this input so we can open the ob1 and we can use is very simple Logic for example let's use this move the signal the counter come from the channel 1000 to read this 1,000 Channel we will type in ID 1000 okay this is the dward we can copy this value to a internal variable for example for the 1200 we can to use the internal memory we can use MD 1000 okay and Define this ch Channel as the integer okay we can go to the PLC tag and open all tags and here this ID 1000 this is our hscore the one this is incremental encoder Channel we can call it Inc and for the incremental data here this state typ we can switch to the the dent double integer okay once we got the integer we can calculate and this channel we can call that so our incremental encoder counter okay now we can download this program so we can click this download now we just Bo up this PLC so initial value is shows zero if I manually spin this motor and meantime we can watch this input I 0.0 and I by 0.1 and now if I spin this motor so we can see this two channel is flashing so means it's reading something there okay and the meantime we can see this value channel is changing there and my incremental encoder that's 1,124 lines per Revolution so now if I spin this motor we can see the counter value from this channel and I will run the motor roughly around one revolution 1 second okay so now I will start this motor so as we can see this counter is increasing and also we can see when the motor run in this direction this is CCW Direction though my counter is increasing that means this is now the positive direction from this channel if you find your motion Direction and your encoder the counting direction that Go reverse so you can go to the properties of this CPU and change this count up to count down or just go reverse that setting and keep in mind while while using the ab counter AB encoder here we cannot use the program to change the direction the only way to change this direction that is using this CPU properties and after we change we need to download the CPU properties and if you use the normal sensor so while you are selecting the single face then you can use the program to switch Direction because the direction can be controlled one digital input or the mass logic behind now we can read the data or read the counter value from this two channel input 0.0 and the input 0.1 that HSC the resources number one however so far we cannot control or especially some cases we need to initialize the value so how can we control that how can we use the program to preside the value on this counter then we need to use the program we need to call the function controlor HS as we can see we have a two function block here I will drag them out and we can do a very simple comparison so for this EXT I can name that 10 and for this simple HSC I can drag to here name the 11 we can let the system automatically generate this instant DB so we can see the EXT shows very simple looks simple but actually if you need to use that you need to create one structure UDT and inside the UDT there's one structure and then you can use that but for this simple controlcore HSC this is the original lency one it's output and input the all here so it's quite straightforward personally I would recommend you can use this lency one for the new learner it's very straightforward and how can we use this EXT again you can go back to the sems application this application is using this HSC EST and it cover these three application basically cover 90% scenarios so if you do need this ex you can directly use the function block from this application example you do not need to develop by yourself start from the scratch you just directly use this example okay and for the simple use we can use this legency one that's enough okay I will delete this new one and to use this HSC so this HSC this function block is used for switching the direction outside some comparison counter that's enough this is the functionalities of this function block okay and to allow this HSC function block to know which channel which resources is uh controlling so we can use this drop list and we we can browse the hi channel one here the local HIC channel one this is that resources channel one and here we can set the direction control command for example here we can use our internal memory 100.0 okay this is the direction so we can name this tag we can name that Dr in and the actual Direction the setting that come from here keep in mind this is a y this is integer so we can use mw102 so this is a new Direction value okay and for the CV and RV you can read The Help from this function block we can click F1 so here it shows CV and RV what does mean of them okay and please look at this detail okay this is a Direction but actually in this case this direction setting won't work that's because in the hardware configuration at here the in Direction specified here that turns gray that means we cannot use the program to change the direction we can only use this count up and count down to switch this direction this is special case I would like to mention because some people will like to use this change direction using the program to switch the counter Direction but once you use the A and B counter it doesn't allows you to do this if you use use the single sensor for example the single face so then you can see this direction selection use program internal Direction control but once you select this AB counter so the system will automatically switch to this mode the external mode it doesn't allows you to use the program to switch this counting Direction so you can speak the count up and count down but basically once you run one time you will figure out which direction that is a positive direction you need to run okay and other than this direction I will also program for setting the precite value for example if I program here this is CV enable and we can prepare the new CV value here keep in mind this new CV that the dent the double integer so when we use this we need to use MD one4 okay we can name that new CV then let me go to the PLC variable list double check the DAT type okay we can name this new CV and now we can download and after the download we can see the initial value that is zero so now we can preset this value this counter value if we go to this new CV here and if I set for example 1,000 prepare the 1,000 value here and the trigger this CV turn this on and the meantime we can see the output bz here it doesn't show any fog and then we can go back to the counter so we can see the counter Pride 1,000 this function is very useful especially for some cases you need to retain the incremental encoder value for example you can write the incremental incoder value to a retained DB and after the system restart you can load that retained incremental encoder value to this new CV here and loow the value retain value at here and the meantime trigger this CV and then this incremental encoder value channel can be loaded from that retain value this is very common way to use this CV to retain the encoder incremental encoder value to this channel back and now if I turn on the motor and then go back here we can see this counter is counting up all right this is a brief demonstration to show how can we implement the H the HSC the hos function for reading the incremental encoder using the C as 7 1200 PLC we using the buildin two inputs digital inputs I 0.0 and I 0.1 and use the hscore one the first resources of this High House counter and now we can read the counter and how can we translate the counter to the resolution per minute or resolution per second this is the rotary speed usually we can use this speed represent the con speed and the motor running RPM right and we definitely need the counter the some calculation way some cases we can use the properties setting to do this but personally I recommend we can use the counter use the mathematic way to program some simple logic to translate this that allows us to do something very flexible using the counter only so let's template Park here in the next video I will show how can we implement this MTH the simple Mass to translate this counter to motor speed all right see you in next video thank you for watching if you like this video please give me a thumb up if you like to watch more videos in my Channel Please Subscribe and hit the Bell thank you for watching