Sign in to follow this  
Followers 0
Shamus

Function Blocks & Instance Data Blocks

8 posts in this topic

Hello All I have the following application and would like to be steered in the right direction. 10 motors having exactly the same i/o on the plant as follows. start (HMI button) Stop (HMI buton) Coil (dig output) Running (dig input) Tripped (dig input) Status (Int to HMI) Startup Timer (T??) TimerVal (S5TIME) In order to save programming time I want to call 1 function block but each call load it wth the related I/O etc of each motor. I've created a function block (FB100) and declared variables inside it INS & OUTS and a STAT value to determine if there was a start up fault. The status is used for a message on the HMI showing Starting, Stopped, Tripped & Startup Fault etc I then created an instance DB (DB100) and tagged it to the FB. In OB1 i type CALL FB100, DB100 and fill in the I/O for motor 1. I then type the same and type in the I/O for motor 2 and so on. I am having some problems with this so i suppose I'm asking am I doing this correctly?? Do I need to use a UDT??? Do i need differnt DB's for each motor?? The multiple instance description in the help is a bit confusing to me. Many Thanks For Your Time Shamus

Share this post


Link to post
Share on other sites
Hi shamus... Well if you wont to have dirrent state for your motorns then you cant use a instance DB for your FB100. This is how i would do... Create a FC100 and have your in and out as in your FB but instead of using Stat use the temp area for your memories/alarmtime/motorstate and so on... When your block is complete, make an UDT of your TEMP and then you can have a DB for all motors (for each motor just call the UDT). And also have 2 inputs in your FC100 that lets the block know witch DB you wont to call and the number of motor). Here is an example. Lets say that your Temp area for the motorblock is 6 bytes. And in your datablock the motor 1 starts at adress DB100.DBX0.0 To open the right datablock L #DBnr <- input at the block T LW 0 OPN DI [LW 0] to load the values from the first UDT L #Posnr <- input at the block (mabe 1, first motor, 2 = second motor and so on) L 1 -I L 6 <- Lenght of the UDT Area *I ITD SLD 3 LAR1 L DID [AR1,P#0.0] T LD 0 L DIW [AR1,P#4.0] T LW 2 Now you have the values for motor 1 in your block (DB100.DBX0.0 - DBX5.7, if it would be the second motor it would get DB100.DBX6.0- DBX11.7 And so on). Then process your code, set your outputs and so on. then you need to get your values back inside the datablock. L LD 0 T DID [AR1,P#0.0] L LW 2 T DIW [AR1,P#4.0] This reads the lockal stack back to the Datablock (6 bytes). So now you can have an endless numbers of motors that uses the sameblock (FC100) but can have diffrent values. (for checking the answer from the motor I wouldnt use a regual timer, have a second flank and a word in your UDT that you increase each second that the motor is running and you havent get the right runninganswer (input) and when the word is lets say equal to 8 (8seconds) then alarm). But this is just one way...but it works god /e Edited by edda

Share this post


Link to post
Share on other sites
Hi Shamus, If your FB works fine with only one motor, then all you need is separate DB for every additional motor. There is also other, a little bit more sofisticated way to achieve your goal. You can create STAT variables of type FB100 in other FB block. In code you simply call this variable like normal FB but without instance DB. It saves DB address space. Copy this code to STL source and compile it to see how it works. FUNCTION_BLOCK FB 100 TITLE = VERSION : 0.1 VAR_INPUT in1 : BOOL; in2 : BOOL; END_VAR VAR_OUTPUT out1 : BOOL; out2 : BOOL; END_VAR BEGIN NETWORK TITLE = END_FUNCTION_BLOCK FUNCTION_BLOCK FB 1 TITLE = VERSION : 0.1 VAR motor1 : FB 100; motor2 : FB 100; motor3 : FB 100; END_VAR BEGIN NETWORK TITLE = CALL #motor1 ( in1 := I 0.0, in2 := I 0.1, out1 := Q 0.0, out2 := Q 0.1); CALL #motor2 ( in1 := I 0.2, in2 := I 0.3, out1 := Q 0.2, out2 := Q 0.3); END_FUNCTION_BLOCK Edited by jacekd

Share this post


Link to post
Share on other sites
Look at post #16: http://www.plctalk.net/qanda/showthread.php?t=8253

Share this post


Link to post
Share on other sites
Can you post the picture here too, becuse you need to be a member at PLCS.Net to view it... Regards /e

Share this post


Link to post
Share on other sites
Shamus, An instance DB is a dedicated DB for each call to an FB, not for each individual FB itself. Therefore if you call the FB 5 times for 5 different motors, then you would need 5 different DB's. The instance DB will then store information on that specific motor, an FB is referred to as a block with memory, the memory is the DB, which stores the IN, OUT, IN_OUT and STAT data. When you called the same FB using the same DB, the second call over-wrote all the data stored in the DB by the first call. You would normally use FC's where you don't need to save the data, for an example, the FC is used to perform a calculation from IN parameters and transferred out in the OUT parameter and then used externally. You can do as edda stated and retrieve and save data in an FC, but this is extra work that is already carried out by the FB.

Share this post


Link to post
Share on other sites
Hi all, I've used Data Block in Siemens but still i can't underestand the difference between FC and FB well. Does any one happen to know about it? Regards

Share this post


Link to post
Share on other sites
An FC has 4 parameter types associated with it. IN - Where you pass data into the FC OUT - Where you pass data out of the FC IN_OUT - Where you pass data into the FC and you want to update the same data when you leave the FC TEMP - Internal temporary storage space which you must condition before use, it does not remember states from the last call. An FB has all of the above and additionally STAT - Internal memory that can remember the state from the last call. An FC has no DB associated with it. An FB has to have a unique DB associated with every call, in that DB will be stored the IN, OUT, IN_OUT and STAT parameters.

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