Technical Forum

STEP 7 / STEP 7 Lite

S7 programming average

Erstellt von MatthiasV am 19.05.2011 11:43 (62 Antworten)

« Vorheriges Thema Nächstes Thema »
«1234567» Seite 5 von 7 (63 Objekte)
  05.06.2011, 12:00
Beigetreten am: 15.04.2009
Letzter Besuch: 29.05.2013
Beiträge: 648
Bewertung:
Bewertung: Herausragend [3,21 von 5 / 29 mal bewertet]. (29) 
Bewertung: keine [0 von 5 / 0 mal bewertet]. (0) 
MatthiasV wrote:
Ok, so I just have tot change the first one into 0.0 instead of 8.0

And I know I have to use the pointer, any idea why it changes by itself?
It's with the FC10, with the ATT and FIFO pointer. Everytime I use p#DB8.DBX10.0 at the ATT and FIFO it changes to DB8.DBW10 without the p#.
For the FC10 it's the same I put in p#DB8.DBX12.0 INT 1 but I get DB8.DBW12 when I push return.

Kind regards,

Matthias V


Don't write P3DB8.DBX 12.0 INT 1

Write Either BYTE or BIT in place of INT

ANY Datatype does recognize INT in it. it just gets either BYTE or BIT

Niranjan
Top
  05.06.2011, 12:13
Beigetreten am: 30.03.2011
Letzter Besuch: 23.06.2011
Beiträge: 30
Bewertung:
Bewertung: keine [0 von 5 / 0 mal bewertet]. (0) 
Bewertung: keine [0 von 5 / 0 mal bewertet]. (0) 
Ok, sorry for the questions. I get it.

But what Shar says about FC10 is that the mistake in my program than? Or what is he saying?

I have a JUMP function in the OB1. When my input value is 0 (probably caused when it's not giving any signal i guess) then I tell it to set MW16 to 35°C, if the signal is off for 30 seconds the program doesnt go through FB1 to FB6 and JUMPS to FB7. In FB7 it will activate an alarm.

And about the OB's of the FB's that I mentioned and the pointer code p# ( and INT 1) that falls of and changes DB8.DBX12.0 in to DB8.DBW12 any idea how that might come?

Sorry for the questions.

Kind regards,

Matthias V
Top
  05.06.2011, 12:37
Beigetreten am: 30.03.2011
Letzter Besuch: 23.06.2011
Beiträge: 30
Bewertung:
Bewertung: keine [0 von 5 / 0 mal bewertet]. (0) 
Bewertung: keine [0 von 5 / 0 mal bewertet]. (0) 
Thnx for the info Shar.

What you indicated in the picture.

Am I correct that it's all about the first indication? That it has to be p#0.0 and the rest of the indications are correct right? Or not?

Sorry for my nobish programming skills :s

Kind regards,

Matthias V
Top
  05.06.2011, 13:09
Beigetreten am: 15.04.2009
Letzter Besuch: 29.05.2013
Beiträge: 648
Bewertung:
Bewertung: Herausragend [3,21 von 5 / 29 mal bewertet]. (29) 
Bewertung: keine [0 von 5 / 0 mal bewertet]. (0) 
MatthiasV wrote:
What you indicated in the picture.


I indicated to correct that places. Just compare your code and the code in the pic

MatthiasV wrote:

Am I correct that it's all about the first indication? That it has to be p#0.0 and the rest of the indications are correct right? Or not?


I didn't get you. Please explain.



=== Edited by Shar @ 6/5/2011 1:10 PM [GMT ] ===



Niranjan
Top
  05.06.2011, 13:19
Beigetreten am: 30.03.2011
Letzter Besuch: 23.06.2011
Beiträge: 30
Bewertung:
Bewertung: keine [0 von 5 / 0 mal bewertet]. (0) 
Bewertung: keine [0 von 5 / 0 mal bewertet]. (0) 
Oh ok I see.

At the first indication you say it has to be a WORD I understand that it has to be a WORD.

The second and third indication are about changing W to DBW.
Could you maybe tell me why that's necessary here and not aht the first indication?

Kind regards,

Matthias V
Top
  05.06.2011, 13:32
Beigetreten am: 30.03.2011
Letzter Besuch: 23.06.2011
Beiträge: 30
Bewertung:
Bewertung: keine [0 von 5 / 0 mal bewertet]. (0) 
Bewertung: keine [0 von 5 / 0 mal bewertet]. (0) 
And what I forgot at the first indication.

It says to point to p#8.0.
Why is it 8.0?

If I see the whole first part of the FC10 it is like this: (If i'm not seeing it all wron here)

It loads p##values_to_average so it loads the beginning of the table = DB8.DBX10.0 right?
It loads AR1
It loads the word from AR1 at place 2.0 so that's the second word = entries in table = DB8.DBW12?
It transfers that to #elem_count
It loads word 4.0 so thats DB8.DBW14 = first sample in the table?
Then it transfers that to #db_num what I don't really understand..
And opens DB #db_num I guess that has to be DB8 or DB9 in my program so I don't get it why it says [AR1, P#4.0] and not just DB8 or DB9

after that it loads WORD [AR1, P#6.0] what you changed into 8.0. But what this does is not really clear.

Kind regards,

Matthias V
Top
  05.06.2011, 13:33
Beigetreten am: 15.04.2009
Letzter Besuch: 29.05.2013
Beiträge: 648
Bewertung:
Bewertung: Herausragend [3,21 von 5 / 29 mal bewertet]. (29) 
Bewertung: keine [0 von 5 / 0 mal bewertet]. (0) 
MatthiasV wrote:
The second and third indication are about changing W to DBW.
Could you maybe tell me why that's necessary here and not aht the first indication?


Because you are reading the data from the Opened DB ( DB 8 and DB9)

Earlier it was WORD.

ANY Datatype contains the initialization not the values.


Your Values_to_Array Variable is of ANY Datatype, Which just contains the initial data ( from where to read and what length etc.)

when you are calling FC10 in other Blocks , you parameterize like P#DB8.DBX12. BYTE 100 which means from DB8 access the data from DBW 12 or DBX 12.0 or DBB 12 or DBD12  of total length of 100 ( which means upto DBX/DBW/DBB/DBD 112)

so your FC is just reading the values from the Assigned DB. THats why OPN DB command is wriiten to access the DB

Niranjan
Top
  05.06.2011, 13:40
Beigetreten am: 15.04.2009
Letzter Besuch: 29.05.2013
Beiträge: 648
Bewertung:
Bewertung: Herausragend [3,21 von 5 / 29 mal bewertet]. (29) 
Bewertung: keine [0 von 5 / 0 mal bewertet]. (0) 
MatthiasV wrote:
And what I forgot at the first indication.

It says to point to p#8.0.
Why is it 8.0?

If I see the whole first part of the FC10 it is like this: (If i'm not seeing it all wron here)

It loads p##values_to_average so it loads the beginning of the table = DB8.DBX10.0 right?
It loads AR1
It loads the word from AR1 at place 2.0 so that's the second word = entries in table = DB8.DBW12?
It transfers that to #elem_count
It loads word 4.0 so thats DB8.DBW14 = first sample in the table?
Then it transfers that to #db_num what I don't really understand..
And opens DB #db_num I guess that has to be DB8 or DB9 in my program so I don't get it why it says [AR1, P#4.0] and not just DB8 or DB9

after that it loads WORD [AR1, P#6.0] what you changed into 8.0. But what this does is not really clear.

Kind regards,

Matthias V


Hope the attached file will help you to understand the ANY Datatype

Dateianhang: ANY.jpg  (12 Downloads)

Niranjan

Top
  05.06.2011, 14:07
Beigetreten am: 07.10.2005
Letzter Besuch: 19.06.2013
Beiträge: 2367
Bewertung:
Bewertung: Exzellent [4,26 von 5 / 615 mal bewertet]. (615) 
Benutzer mit speziellen Fachkenntnissen, die einzelne Konferenzen betreuen
Bewertung: Exzellent [5 von 5 / 1 mal bewertet]. (1) 
Dear all

it seems there's some confusion going on her so allow me to interrupt and lets see if we can clarify a few things:

MatthiasV wrote:
(Edit: in relation to ANY type Paramter of FC)  ... I put in p#DB8.DBX12.0 INT 1 but I get DB8.DBW12 when I push return.
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 populated with the correct information.  

shar wrote:
You have to assign as P#DB8.DBX12.0 BYTE 10 ( BYTE any number) when you are calling the FC 10
Sorry, but this advise is incorrect. 

shar wrote:
ANY Datatype does recognize INT in it. it just gets either BYTE or BIT
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's help on it for more) and it is up to the programmer to decide which ones he wants to evalute.

MatthiasV wrote:
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.
This would happen if the actual size value (DBW12 in DB8 and/or 9) has a value of 0 which then leads to 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.

MatthiasV wrote:
But in the loop you allways add by INT (Edit "+ I" instruction is used) so won't you get a #sum that is outreached and has to be added DI way?
Correct, +D MUST be used. Even though variable #sum is of DWORD 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:


I hope this helps and that I didn't miss any outstanding questions (and apologies if I answered questions that were already answered, this thread is starting to get a bit convoluted)




=== Edited by fritz @ 6/5/2011 2:37 PM [GMT ] ===
Fixed oopsie in range check logic

=== Edited by fritz @ 6/5/2011 2:20 PM [GMT ] ===
Tried to fix the layout and usage of to correct hings, but preview does still look "funny" so I give up.


Cheers

fritz

The advice and opinion given in this thread is that of the author and does not necessarily reflect the views of I S Systems Pty Limited.
To find out how I S Systems can help you with your automation needs please visit www.issystems.com.au.
Top
Für diesen Beitrag bedankt sich:
  05.06.2011, 14:28
Beigetreten am: 30.03.2011
Letzter Besuch: 23.06.2011
Beiträge: 30
Bewertung:
Bewertung: keine [0 von 5 / 0 mal bewertet]. (0) 
Bewertung: keine [0 von 5 / 0 mal bewertet]. (0) 
Hi fritz,

Thanks for the reply I think I get your programming.

1 note about it: at point 11

You say Load 0 and you see if it's bigger then DBW12 right?
Doesn't this have to be

L 1;
L DBW 12;
>I ;

And then the error handling, so you go to error when the limit is exceted <1 or > max size.
So if it's lower then 1 it will send 0 to output so the FC10 doesn't give an error and makes it all work?

I think I get it except the part at point 11 that I said above.
Thank you!

And Shar you to for the help about ANY I never saw that before.

Kind regards,

Matthias V
Top
«1234567» Seite 5 von 7 (63 Objekte)
Aktionen