Using timer to return from subroutine

tss

Member
Join Date
Jan 2013
Location
Auckland
Posts
1
I have a subroutine which sorts a large list of numeric data. The problem is that for a sufficiently large dataset the subroutine will take so long to complete that the watchdog is activated.

So I'm trying to get around this problem by having a timer which lets the routine run for a second before returning to finish the scan and then going back in on the next scan and so forth.

But I've been unable to make this work. Any ideas? Here's what I've done:

Main:

...

---[]---SBR

...

SBR:

---[Sort done]---RET

---(Set timer)---[timer]------RET
....................................|
....................................-----(reset timer)

...
 
I don't think your making it your second [RET] Once you Return to Main then it continues from where it left. Then next scan the JSR starts back at Rung 0 of SBR. Before your 1st [RET] Set a bit and use bit for a conditional JMP to LBL at the beginning of SBR to jump what you have already solved. After LBL Reset Bit.
 
Last edited:
You would have to constantly examine the timer in order to get the timer "done" bit true, so if you put the Timer instruction inside the sort loop and set it for 0.2 seconds to begin a test and make sure that if it gets done you breaking out of the loop. Try that out and then monitor the actual scan time, adjust your time preset upward cautiously...is this PLC doing other things that are going to be affected by this scan hit?

What kind of hardware/software are you dealing with?

Normally, I would recommend taking it in many very small chunks so as to have a negligible impact on a machine's performance...having a 1 second scan time or two is unrealistic in many cases.
 
Last edited:
Use a counter in the sort loop
When the counter reaches x passes (tuned to suit the PLC scan time) exit the sort routine and remember where to continue the next sort from next scan

If there is a free running clock in the PLC capture its value on entry and compare the free running clock with the captured value to see how much processing time has been used

Check your sort routine is efficient. What is its Order? (http://en.wikipedia.org/wiki/Sorting_algorithm)

Rewrite your sort routine so that one sort is performed per scan (only possible if the results are not needed for some time)


Question - In the Control Logix can a timer Accumulator value update within the same scan (TON must be called many times)? does anybody know?
 
Question - In the Control Logix can a timer Accumulator value update within the same scan (TON must be called many times)? does anybody know?

the timer's accumulator will be updated whenever the TON "instruction" in the ladder is scanned/executed by the processor ...
 
As PLC's programs are designed to "SCAN" Cyclic it could be considered dangerous to hold beyond the max watchdog or extend it considerably it would be better to process some data then next scan do some more & so on until all data processed.
for example imagine polling through a data block 64k long & computing calcs on the data in a loop this would take too long
if possible set a pointer to the first word in the block,call the routine increment the pointer it within the routine 8 times then return. on next scan the pointer will point to n+8 and so on when the pointer gets to the last word in the block set a bit "calcs done" and set the pointer back to the start of the data use the "Calcs done" flag in your program if you need to have all data processed before doing something with it.
 
Where i have had complex data handling routines that can be split into sections then I put the first section at the bottom finishing with a latch. The first rung of this section begins with a NC contact of the latch.
The next section of the calculations is placed ABOVE the 1st section and is called by a NO contact of the 1st Latch. Again the setion ends in a latch, calling The next section in a similar fashion ON THE NXT SCAN.
This avoids the need to call the subroutine in stages with timers or whatever.
 
Remember that a timer is a computer instruction that operates on a memory address. You can program multiple TON instructions to access the same timer address multiple times in a single scan to update the time.
 
Where i have had complex data handling routines that can be split into sections then I put the first section at the bottom finishing with a latch. The first rung of this section begins with a NC contact of the latch.
The next section of the calculations is placed ABOVE the 1st section and is called by a NO contact of the 1st Latch. Again the setion ends in a latch, calling The next section in a similar fashion ON THE NXT SCAN.
This avoids the need to call the subroutine in stages with timers or whatever.
i really like the sounds of this method... :D
 

Similar Topics

What programming technique would use a bit position in a Timer's acc value? For example T4:0.ACC/1 using RSLogix500 in a SLC
Replies
14
Views
2,868
Good Afternoon , I have an older Panelview Plus and do not have the application . I'm in the process of re-doing the HMI application from...
Replies
11
Views
3,875
Hello, I am new to the forum. I have been using the Redlion Crimson 3.0 software for about 3 years. I have never had any luck pausing a timer...
Replies
3
Views
1,854
I have s7-1214c PLC and want to use timer in html file. for example; after 2 minutes, change tag_1 to 10.
Replies
2
Views
1,337
Need help a source code to make timer display into hour:min descending from a time of delay 1 sec base timer. Thanks
Replies
22
Views
5,893
Back
Top Bottom