5/19/2011 11:43 AM | |
Posts: 30 Rating: (0) |
Hi,
I'm working on programming a PLC program in Step7. For wich I need to calculate an average value. First I have 144 samples in a DB8 and second I have 180 samples in a DB9. So I need a block wich can just say: ADD all the samples in DB8 and DEV them by the number of samples (= DB8.DBW12?). And the same for DB9. So I found a block that might do the trick at: https://support.automation.siemens.com/WW/llisapi.dll?func=cslib.csinfo&objId=39333121&load=treecontent&lang=en&siteid=cseus&aktprim=0&objaction=csview&extranet=standard&viewreg=WW I put the file in my program and I hit compile STL source file. When I do so I get 6 error's: E Ln 000026 Col 013: Syntax error at #RESET. E Ln 000027 Col 013: Syntax error at _001. E Ln 000034 Col 013: Syntax error at ;. E Ln 000043 Col 013: Syntax error at #BY_VALUE_CHANGE. E Ln 000044 Col 013: Syntax error at nmw. E Ln 000052 Col 013: Syntax error at ;. Now I don't know how to fix this and so I'm stuck at this point. I'm not a great programmer and I can only work with FBD and not with STL so if somebody would know a solution I would be very thankful. Thanks in advance. Kind regards, MatthiasV |
5/19/2011 12:15 PM | |
Joined: 3/21/2006 Last visit: 4/4/2024 Posts: 10228 Rating: (1181) |
Hello, For Step7 the right link is http://support.automation.siemens.com/WW/view/en/19345299 And another one - http://support.automation.siemens.com/WW/view/en/1021364 Best regards, Hristo Mihalev |
Last edited by: UMENCHO at: 5/19/2011 12:17 PM |
|
5/19/2011 1:15 PM | |
Posts: 30 Rating: (0) |
Thanks for the quick response UMENCHO. The second link you send me is the one I tried to use in the program but like I said I had 6 errors that I described in the above post. This one looks like the easiest way for me to program because It's for a project at school in wich I need to every step in the program. The first link looks a little hard for me. I can open the file but it doesn't allow a FBD view and only STL view. And like I said I reallydon't know anything about STL programming :s. Do you maybe know a way to make the second link work without the errors I'm having? Or is there a simple explanation for the first link that I could understand without any knowledge of accu, STL, ...? Kind regards, MatthiasV |
5/19/2011 1:25 PM | |
Joined: 3/21/2006 Last visit: 4/4/2024 Posts: 10228 Rating: (1181) |
My suggestion is to follow MM1234' answer. There everything is explained very well with details. Meanwhile if you have still troubles of course I could try to do compiling of source code on my PC and attch here the result. But really you can to do it alone. Just follow the MM1234. Best regards, Hristo Mihalev |
This contribution was helpful to4 thankful Users |
5/31/2011 12:59 AM | |
Posts: 30 Rating: (0) |
Sorry the attachment is in this post, I forgot it in the previous post! ps: the input in the program is a HART signal so I start by sending it to a DWORD (MD), I Unscale it to send the values directly to the output cards and also pass them forward to the DB8 table. After that I take samples every 10 min and store them in DB8. The table is used to calculate the average if I can fit in your program their. I repeat the same structure by taking samples (this time of the calculated average values) every 4 hours and then make a new average of those values. The two averages are send to outputs. That's a short reminder of my program and I hope it looks a little bit good and is not to wrong :s ps2: the place where the average has to come is filled with an ADD function and a DIV function just to mark the place where it has to come. So it might be easier to find. Kind regards, Matthias V
AttachmentMilieu_1.zip (243 Downloads) |
5/31/2011 3:13 PM | |
Joined: 10/7/2005 Last visit: 4/18/2024 Posts: 3003 Rating: (1046)
|
Hello MM1234 |
Cheers |
|
This contribution was helpful to1 thankful Users |
6/1/2011 10:50 AM | |
Posts: 30 Rating: (0) |
Hi I did what Fritz told me about the language part so that should be fixed now. In attachment you can find the full project to be opened in S7. AttachmentMilieuSTL.zip (222 Downloads) |
6/1/2011 10:55 AM | |
Posts: 30 Rating: (0) |
Hi, When I use addressing to DB8 I have to call it up first don't I? Just say: And do I have to do this in every block as well? Problems: AttachmentMilieuTXTfiles.zip (202 Downloads) |
6/2/2011 10:21 AM | |
Posts: 270 Rating: (53) |
Hello MatthiasV, unfortunately, I don't get to my PC with Step 7 today either. So, I did fix the code for your average value so it works as I proposed before and the way you need it. It loads the first value from the specified first element of the data block and then loads as many elements after it as specified, makes an average of them which is not rounded integer and then returns it back. That's for FC10, now regarding your FB3. The outcome of the FC10 is in the #RET_VAL, so you can assign that value anywhere you need. You should be able to save it into a data block as well as some temporary value and then save it anywhere you need. If you need to save the values in a manner you said, into a DB9, you should make a variable somewhere (that persists, perhaps save that into a DB) for the position where you are at and then just simply store it to that positions address - code is pretty much same as in the loop in FC10, you will not add, though, but just store somewhere and then increase the position. Last thing not to forget, calling of FC10. As I said, it returns in REL_VAL the average value. It has also one incoming parameter, which is values_to_average := P#DB8.DBX12 INT 1 and you dont have to worry about it, as long as the [12] is the number, where is stored the amount of elements in DB8 and the remaining elements are right behind it. So wherever you want to use this average on those values, just call it this way and specify the right way to handle the RET_VAL and you are good. AttachmentMatti_avg.zip (247 Downloads) |
6/3/2011 1:32 PM | |
Posts: 270 Rating: (53) |
Well, if you put it there, it should be ok. And yes. What I ment, though, is that your data blocks have default length after you did create them. Open DB8 and DB9 from your Simatic Manager the way you open OBs and FCs, etc., and set them proper length and then if you switch to data view, you can set there the 144/180 values also. What is good too, when you run your program, open the online DBs and check the values that are in, if they fit and stuff, just to see if things work.
I think that is the point of DBs, to store the values "permanently".
If you look at the attached picture (from help on FC84 ATT again), you will see that the required parameter is a pointer. So it shouldn't even let you call just DB8. Also, if you would somehow point on the DB but not specify where, then I asume it would take it at the start of DB (DBW0), which might contain anything (idk if you use it for something), as you start your values from DBW10.
Yes, I believe you can do this. I am not sure, though, if it doesn't open the data block (in case you had opened some other and would want to use it later). Either way, you can use OPN DB8 and then L DBW12(10) and it will open the DB8 and then load the word at 12th(10th) byte from currently opened DB.
It seems you got a bit confused here, which is no surprise, it could get pretty confusing. Anyway, I believe this answers the previous answer. I suggest you, when you are done with this and get some time, have a deeper look on stuff regarding addressing and pointers. It makes one wonder sometimes so just give it some time to "suck in" the concept into your brain. You can use for example this document to get better understanding of things (http://support.automation.siemens.com/WW/view/en/45531551), best would probably be, when you have time, to start from beginning and go through it page by page. |
Last edited by: MM1234 at: 6/3/2011 1:32 PMforgot the attachement... .]] |
|
6/3/2011 3:06 PM | |
Posts: 270 Rating: (53) |
Check that second attachement, there is example how your DB8 will look. Maybe I expressed it in not understandable way, but anyway it's not 5 elements total before the 144, but 5 elements before the two values for how many total and how many current elements you have and THEN the 144 elements. So, it's actualy not 6, but 7. You did the mistake everyone does and forgot about DBW0, that's why I stressed that it starts counting from 0. .) So check my previous attachement and I think it will be clear (/tf/WW/en/postattachments/download?attachmentId=20366&onlyInternet=False). As for the:
Read what I wrote before, check carefuly the examples and it should be clear how to initialize the value of a certain element in the DB. |
6/3/2011 3:29 PM | |
Posts: 30 Rating: (0) |
Oh yeah I see, that's actualy pretty easy! I put my hole program in attachment if you might be interested :-) Thanks again MM1234, I made a deal so I have a step7 even tomorrow, I only have to do the symbol table and some little changes so I guess I'll be done tomorrow. Thanks all! Kind regards, Matthias V AttachmentMilieuANYLANG.zip (193 Downloads) |
This contribution was helpful to3 thankful Users |
6/4/2011 2:51 PM | |
Posts: 30 Rating: (0) |
I tried to download it to the cpu. When I did that and started up the cpu (RUN) I get the red SF light on. It's something with OB1 or/and FC10 but I don't really get how it's fixable. Somebody mind taking a look at my diagnosis in attachment? The diagnosis from 06/04/2011 are my errors with this program. Kind regards, Matthias V AttachmentDiagnose.zip (165 Downloads) |
6/5/2011 8:43 AM | |
Posts: 691 Rating: (36) |
Dear MatthiasV You have to assign as P#DB8.DBX12.0 BYTE 10 ( BYTE any number) when you are calling the FC 10 Here is the error in your program |
6/5/2011 2:07 PM | |
Joined: 10/7/2005 Last visit: 4/18/2024 Posts: 3003 Rating: (1046)
|
Dear all it seems there's some confusion going on her so allow me to interruptand lets see if we can clarify a few things: This is normal behaviour by the S7 Editor and there's nothing wrong with this. The 10 Bytes of the ANY pointer will still be populatedwith the correct information. Sorry, but thisadvise is incorrect. This is true for some standard Siemens Blocks (see their online help if it applies or not), but not generally true. The ANY Parameter type can be quite a beast to handle, but - as the name suggests - accepts prettty much "ANY" datatype(e.g. BOOL, BYTE, INT, REAL etc., see Step7'shelp on it for more) and it is up to the programmer to decide which ones he wants toevalute. This would happen if the actual size value (DBW12 in DB8 and/or 9) has a value of 0 which then leadsto plenty of loops (the actual size value is the initial value for the loop counter) and exceeding of the DB range with the indirect access as AR1 is increased by 2 Bytes with every loop. The golden rule when using indirect addressing is: Make sure you have a range check of your index or pointer value in place. Correct, +D MUST be used. Even though variable #sum is ofDWORD type, usage of "+ I" will only give a maximum value of 65353 in it which may not be enough (only Accu1 L is added, see Step7 help for more). Last but not least, DB8 and 9 have the same structure as far as the location of the buffer related values is concerned. My idea of a somewhat simplified and more "robust" version of FC10 is: [code] VAR_INPUT Buffer : BLOCK_DB ; END_VAR VAR_TEMP _Sum : DINT ; _Loop_counter : INT ; END_VAR BEGIN NETWORK TITLE = OPN #Buffer; // Open Buffer DB L #_Sum; ERR: L 0; |
Last edited by: fritz at: 6/5/2011 2:37 PMFixed oopsie in range check logic Last edited by: fritz at: 6/5/2011 2:20 PMTried to fix the layout and usage of </div></div> </div></div> to correct hings, but preview does still look "funny" so I give up. Cheers |
|
This contribution was helpful to3 thankful Users |
Follow us on