Exceeding cycle because of a loop for searching in a DB

rick-brinkman

Member
Join Date
Dec 2012
Location
Overijssel
Posts
21
Hello all,
I am using in Step7 a FC that searches through a database. I am doing this with address registers. Running through the database and finding values works fine. But when the database is to big the searching takes too long (i.e. running through the loop “Lus” takes longer than the cycle time). With as result that my PLC jump into stop with error “Stop caused by time error” (event ID: 16#4568), cycle time exceeded. See my program code below:
---------------------------------------------------------------------------------
// Search DB for stamnumber
OPN #DB_NR_Stamnumbers //Open DB
LAR1 P#0.0 //Load AR1 with pointer value
L DBLG //Load Length of DataBase
Lus: T #LV_loopcount // times to run through loop
L DBW [AR1,P#0.0]
L #StamNr //Load ACCU_2 with #StamNr
==I
JC M001 // Value Found? Jump to m001
+AR1 P#2.0 // Plus an offset of 2.0


L #LV_loopcount //Function Loop does:LV_loopcount - 1
LOOP Lus // Run again through loop
JU M002 //Value not found


//Stamnumber found
M001: NOP 0
// Do here something if “stamnumber” is found
JU END


//Stamnumber NOT found
M002: NOP 0
// Do here something if “stamnumber” is NOT found
JU END


// End of function
END: NOP 0
---------------------------------------------------------------------

To solve this problem I guess I should remove the Loop and call the FC not once but every PLC cycle (i.e. Checking one DBW per cycle time). In my opinion, to accomplish that, I have to store the value that is in AR1 but I have no idea how.

Or is there a better/easier solution?

Thanks in advance!
 
1. Is the other things in the PLC time sensitive if not raise the cycle time monitor.

2. Did you monitor when the PLC went into stop if this is the case maybe the PLC is in Test mode instead of Process mode Test mode monitors every loop and can raise the cycle time when monitoring In process mode you set a limit for how much the cycletime can raise when monitoring..

3. What PLC is it? I have a 317 cpu wich loops through up to 1300 dint compares several times in a cycle without problems..
 
First of all, momentarily I’m using a Siemens PLC S7-300 CPU 314IFM.
Second my PLC was indeed in Test mode.
Last.. I prefer not to increase the cycle time monitor.

When I change my PLC to process mode and I try to test my program again (with a VAT table). I immediately get error "Modify (33:53418): (D0AA) Time limit exceeded in processing operation.
 
// Store AR1:

TAR1
T myAR1Store // the store must be a doubleword

//Restore AR1:

L myAR1Store
LAR1

And remember you must know that the pointer is initiated (valid).


Kalle
 
Last edited:
Coding error waiting to bite you.

Code:
L DBLG

Loads the length of the DB in bytes, but you are scanning for ints. I'm surprised you have not had an address error unless you have always found the item in the database.

You need to halve the loop count.
 
First of all, thanks a lot for helping!

I will short summarize why my problem occurred, for those who are interested or are dealing with the same issues:

The reason why my cycle time exceeded was because I was monitoring the loop. In the monitor mode the cycle time really increases.
Now my program code works, the PLC can easily run through the loop 200 times to compare 2 integers. which mister "Bara Hence" already told.

Also I had some counting and addressing errors, which as mister "L D[AR2,P#0.0]" mentioned.


So Lets just post my program code:
-----------------------------------------------

// Search DB for StamNumbers
L 0
T #LV_loopcount //Reset
OPN #DB_NR_Stamnumbers //Open DB
LAR1 P#0.0 //Load AR1 met pointer waarde
Lus: L #LV_loopcount
L DBW [AR1,P#0.0]
L #StamNr
==I
JC M001 //Stamnumber found jump to M001
+AR1 P#2.0 // Plus a offset of 2.0
L #LV_loopcount
L 2
+D
T #LV_loopcount
L #LV_loopcount //Load LV_loopcount
L DBLG //Load lenght of DB
>=D // True if all DBW's are compared
JC M002 //Stamnumber not found
JU Lus


//Stamnummer found
M001: NOP 0 //Do here something if StamNumber found
JU EIND


//Stamnummer not found
M002: NOP 0 //Do here something if stambumber not found JU EIND


//Einde macro
EIND: NOP 0

-----------------------------------------------



However, one problem I have isn’t solved yet.
When I change the "initial value's" in a Database and then save and download the database to the PLC, then the actual values won't change after a reset of the PLC.
In other words: If I view the PLC online and open the database I see the changed values but the actual values remain the same to the old initial values.

So my question is, how can I let the PLC take over all initial values of a DB when I restart the PLC
 
The Initial Values of a DB are set in stone the first time you save the DB. You can change them afterwards as much as you like - it won't have any effect. If you export the DB as a source file and open it in Excel you can also see why.

Fortunately there's a very simple way to solve the problem:

Modify the Initial Values in your DB to the new values you want to have. Create a new DB - for example DB 999 - then copy all the data from the original DB into the new DB. (To copy the data click with the mouse on the "Adress" column of the first entry, then hold the shift key down and click on the last entry row.) Now copy the data using "CTRL-C", highlight the default entry "DB_VAR" in the new DB and use "CTRL-V" to copy the data from the original DB. Now save the new DB.

Now just close both DBs, erase the original DB, being sure not to click the box to delete the Symbol, and rename the new DB (here DB999) to the original DB's number. Now download the DB to your system and after switching off and back on you'll now have your new Initial Values.

Alternatively, you can edit the Initial values in the appropriate part of the Excel table, reimport the file and recompile it, but that's a lot more work!
 

Similar Topics

While I resolved my other issue, I am having some trouble adding tags to the Historian. Right click on application in FTView Studio, Add...
Replies
1
Views
4,687
Hello PLC friends. I've been going through a saga of diagnosing and fixing an old PLC setup that I inherited. I am learning as I go. Initial...
Replies
14
Views
326
Hi everyone. I have an issue with an Allen Bradley PLC model 1769-L30ER. This PLC had a previous program with a different IP address but when I...
Replies
4
Views
506
My Panelview plus 700 HMI stopped working and I replaced it with a new one. Moved the sd card from the previously installed panel to this one and...
Replies
16
Views
972
Hi everyone, I recently put in a 1769-AENTR, and where it is installed has had a couple power outages. Every time when the PLC comes back online...
Replies
3
Views
680
Back
Top Bottom