Elapsed time between scans in S7-1215C

RonJohn

Lifetime Supporting Member
Join Date
Jul 2013
Location
NE Ohio
Posts
535
Good day all. I need to determine how much time has elapsed since the previous ladder scan in order to ramp a value based on time. I'm on my first venture into Siemens PLC programming, although I have worked with A-B products over many years.

When I have used Logix5k, there was the system clock tag with microsecond resolution that I could reference. I would be satisfied with millisecond resolution for my current application. Is there such a tag in S7? The only clock I have found in S7 are the clock memory bits and this won't do as they have 0.1s resolution.

I am using TIA Portal V13. PLC firmware is V3.0. My ramp will be in an FB which is to be called from OB1, if I understand correctly. Thanks in advance for your help.
 
s7 1200 use IEC timers as timers, clock memory bits are handy as general clock only (which are far superior than its predecessor s7 200) but if i am right there is variable in the main OB interface called OB_CYCLETIME that saves last cycle time
 
Thanks balash. My understanding is that OB1_PREV_CYCLE doesn't exist in S7-1200 PLCs. Do you know where I could look to find out?

One of my co-workers also suggested running the logic in a cyclical OB so that the logic executes at a fixed rate. This may also be worthwhile.
 
that would be useful caus cyclic OB will cause interrupt to do code in specified interval as long as code in cyclic ob is faster than cycle time.
prev-cycle only saves the last scan time which can vary depending on the code (jumps or similar parts of code, ie instructions, that could be skipped due to process state)

EDIT:
as for ob prev cycle i have to look on my business laptop
 
Thanks Mike. I wasn't aware of that function before today.

My only concern would be when/if the PLC clock changes, but I could put limits in place to ignore large or negative differences between current and previous clock value.
 
Code:
// Get the new Current Time
// Rd-Sys_T_return holds the status of the command
// Current_Time holds the output from the command
#"RD-Sys_T_return":= RD_SYS_T(#Current_Time);
// Subtract Current from Previous to get Time in ms
#Cycle_Time:= T_DIFF(IN1:=#Current_Time, IN2:=#Previous_Time);
As you say you have to allow for changes in the PLC time and I also allowed for crossing midnight, but as DTL includes Year/Month/Day as well as time I really didn't need to.
 
In the 1500 there is an instruction called RT_info that displays cycle time information. Depending on which mode you give it, it can give some pretty detailed info besides the main scan time. I'm not sure if that block is available in the 1200 or not.

For your application, it may be easier to call the ramp function out of a cyclic OB, which is code that is called at a set interval(2ms, 5ms, 100ms, whatever). It runs at a higher priority from the rest of the PLC code, to ensure it is called when it needs to be. However, it is important to make sure there is enough time left over for the main code to run. If you call the cyclic OB every 5 ms, and it takes 4ms to execute, your main program will probably take a LONG time to execute.

Reading the system clock would work as well, although as said, you would need to account for the time rollover.
 
Following up this thread, I placed my ladder in OB30 with a 10ms execution rate. This seemed to be the best method overall.

You can also look into function RUNTIME (see help).

Thanks for the pointer TurpoUrpo! I used the RUNTIME instruction to determine OB & FB scan times and it works very nicely. I'd recommend this method for the S7-1200.

In the 1500 there is an instruction called RT_info that displays cycle time information. Depending on which mode you give it, it can give some pretty detailed info besides the main scan time. I'm not sure if that block is available in the 1200 or not.

I don't see RT_info in the s7-1200 instruction list, although it could still be hiding somewhere. ;-)
 

Similar Topics

Hi everyone, I want to know if in S7 300, there is a standard watch or something like that to measure the elapsed time between two events. And...
Replies
1
Views
3,927
So I'm assuming this is a rounding issue somewhere, but I don't know for sure so I figured someone else would. Made an AOI that just gives me a...
Replies
12
Views
3,968
Hi group, I am trying to figure out how to calculate time elapsed during a power failure. If the PLC is off for more than 30 minutes, when the...
Replies
9
Views
2,276
I have some code that is going to trigger calculations to happen either when "A" happens, or every 1 second. For the 1second trigger, I am...
Replies
3
Views
1,627
For better or worse the project I am working on has specified several equipment elapsed time meters that are supposed to have their values...
Replies
7
Views
2,107
Back
Top Bottom