Step 7 - How to increment a data location?

russg

Member
Join Date
Aug 2012
Location
UK
Posts
275
Hi,

I'm learning lots about step 7 at the moment but still have a way to go.

What I want to do is count how many parts are made every hour on a certain machine. I know the best way will be to create a datablock and either send a count value from a counter or just add one to a DB location every time a part has been produced. I have already done this in a somewhat long-winded way, but I know I should be changing the data location with some kind of increment or pointer. I know there will be many ways of doing this so any ideas techniques will be appreciated.

To explain the process and what I want better:

-We have 3 presses making parts
-Every time a the timer has finished for the press to end it's cycle I'm currently adding +1 to the relevant press datablock location... e.g DB100.DBW0 [INT] for press 1
-I'm using a timer to run for one hour where it can allow the count to be added into the first datablock location
-once the hour is up it stops the count into that first DB location and activates another hour timer that allows +1 to be added into the next DB location eg. DB100.DBW2 (I've had to repeat this for every hour I've wanted to record)
-I want to be able to use the same count and shorter way of programming so I can automatically update the DB location once the hour is up, which will allow me to record this data for a very long time without adding countless numbers of extra lines. (I've written this in ladder btw, but do understand a little STL)

Thanks in advance for any help you can give me.

Russ
 
How many hours do you envisage counting over? You could read the system clock and use the hours part to index into the DB to decide which entry to increment.
 
As many as possible really. I'd like to develop this into a monitoring system displaying each hours production / parts count / downtime.....etc.... so reading from the systems clock would be a question I need to find the answer to at some point.
 
Increment location is quite simple if you use indirect addressing. I hope you comfortable with STL.
Code:
      OPN   DB  100     //Open DB you want to write to
      L     MW  1000    //hour 0,1,2 etc
      L     2           //for every hour word amount of data is writen to db
      *I                //word takes two bytes multiply hour by 2 to get correct address 
      SLD   3
      LAR1  
      L     MW  1002    //value to write to db
      T     DBW [AR1,P#0.0]//write to db for eg. mw 1000 = 5 and mw 1002 = 10, 10 will be written to db100.dbw10
DB100 data format is array [0..XX] of WORD
if you increase MW1000 every hour you can save as many data as your db can hold.
 
Last edited:
Hi ,
This is another example of reading the date and time of the system.
Regards.

Code:
// READ SYSTEM CLOCK

      CALL  "READ_CLK"             // SFC1
       RET_VAL:=#Date_Status
       CDT    :=#SYS_DATE_TIME

// SAVE REGISTRY BEFORE IF YOU USE FB

      TAR1  #TAR1_STORE
      TAR2  #TAR2_STORE

// HOUR DETECT & OFFSET INCREMENT

      LAR1  P##SYS_DATE_TIME
      L     LB [AR1,P#3.0]        // HOUR
      L     P#2.0
      *D    
      LAR2  

// DATA STORE

      OPN   DB  1000             // YOUR DATABASE
      L     #SOURCE
      T     DBW [AR2,P#0.0]

// RESTORE REGISTRY AFTER 

      LAR1  #TAR1_STORE
      LAR2  #TAR2_STORE
 
Increment location is quite simple if you use indirect addressing. I hope you comfortable with STL.
Code:
      OPN   DB  100     //Open DB you want to write to
      L     MW  1000    //hour 0,1,2 etc
      L     2           //for every hour word amount of data is writen to db
      *I                //word takes two bytes multiply hour by 2 to get correct address 
      SLD   3
      LAR1  
      L     MW  1002    //value to write to db
      T     DBW [AR1,P#0.0]//write to db for eg. mw 1000 = 5 and mw 1002 = 10, 10 will be written to db100.dbw10
DB100 data format is array [0..XX] of WORD
if you increase MW1000 every hour you can save as many data as your db can hold.

Hi, thank you very much for this. It's taken me a few looks at to understand it, but I think I've got it now.

I'm still very unfamiliar with pointers.... which I'm trying to read up about at the moment.

Thanks again
 
Hi ,
This is another example of reading the date and time of the system.
Regards.

Code:
// READ SYSTEM CLOCK

      CALL  "READ_CLK"             // SFC1
       RET_VAL:=#Date_Status
       CDT    :=#SYS_DATE_TIME

// SAVE REGISTRY BEFORE IF YOU USE FB

      TAR1  #TAR1_STORE
      TAR2  #TAR2_STORE

// HOUR DETECT & OFFSET INCREMENT

      LAR1  P##SYS_DATE_TIME
      L     LB [AR1,P#3.0]        // HOUR
      L     P#2.0
      *D    
      LAR2  

// DATA STORE

      OPN   DB  1000             // YOUR DATABASE
      L     #SOURCE
      T     DBW [AR2,P#0.0]

// RESTORE REGISTRY AFTER 

      LAR1  #TAR1_STORE
      LAR2  #TAR2_STORE

Hi, thanks for your reply. I think this will be very helpful for me, but I'm still yet to fully understand it. Does this have to be created in an FB?

I'll try and look at this more tomorrow to see if I can understand it.

Thanks
 
You can use it everywhere.

But if you use it in FB it good idea to save address registers before modifying them and before exiting FB restore to values you saved

These line save address registers to variables:
TAR1 #TAR1_STORE
TAR2 #TAR2_STORE

And these restore from saved variables:
LAR1 #TAR1_STORE
LAR2 #TAR2_STORE
 
Hi ,
This is another example of reading the date and time of the system.
Regards.

Code:
// READ SYSTEM CLOCK

      CALL  "READ_CLK"             // SFC1
       RET_VAL:=#Date_Status
       CDT    :=#SYS_DATE_TIME

// SAVE REGISTRY BEFORE IF YOU USE FB

      TAR1  #TAR1_STORE
      TAR2  #TAR2_STORE

// HOUR DETECT & OFFSET INCREMENT

      LAR1  P##SYS_DATE_TIME
      L     LB [AR1,P#3.0]        // HOUR
      L     P#2.0
      *D    
      LAR2  

// DATA STORE

      OPN   DB  1000             // YOUR DATABASE
      L     #SOURCE
      T     DBW [AR2,P#0.0]

// RESTORE REGISTRY AFTER 

      LAR1  #TAR1_STORE
      LAR2  #TAR2_STORE

What type of variable is SOURCE ?
 
Hello L D[AR2,P#0.0] ,
AR2 is used by the system to point to the start of data of the FB's instance DB, therefore once you alter AR2 you cannot use any IN's, OUT's, IN_OUT's or STAT's.
Therefore you can freely use AR1 and AR2 if in a FC!!
In this example , as you can see is used like FB , so is the "temp" variable.
 

Similar Topics

I am having a step7 v5.4 program where the blocks are encrypted and locked. And the manufacturer is stopped the support. Is there any ways to...
Replies
2
Views
175
Good Morning, Hoping someone with some Siemens experience can give me a hand with this one. Customer has a S7-200 cpu, which has a 6GK7...
Replies
0
Views
246
HI! HOW COULD I OBTAIN THE NAMES OF THE STEPS OF A ROUTINE IN SFC LANGUAGE IN STUDIO5000? Or is there a system variable that gives me those...
Replies
0
Views
339
I'm just trying to figure out the right method of adding a DO card to an existing rack. It's not the *next* open slot, but I have to move the AO...
Replies
5
Views
546
Hi Siemens Experts, I am hoping someone can shed some light on my issue. I have uploaded the code from a S7-300 (317-2PN/DP) using Step 7...
Replies
9
Views
668
Back
Top Bottom