Jump to content
OMRON Forums

PLC timer


bradp

Recommended Posts

  • Replies 12
  • Created
  • Last Reply

Top Posters In This Topic

Another way to do this same thing is to use the new ability of subroutines and program calling from a PLC program. In this case you can have the timer function as follows: open subprog timer (time) local EndTime; local count; EndTime = Sys.Time + time; do count++; while (EndTime > Sys.Time); close Then you can use this from a PLC program as a one-line function call as follows: open plc 1 callsub timer (3); // make a 3 second delay p2 = p2 + 1; close
Link to comment
Share on other sites

  • 1 month later...
  • 1 year later...
  • 4 weeks later...
Brad, I tried to write a simple timer in C, and I used the system time that you were using in your example above: "Sys.Time" Of course in C I wrote it like this: "pshm->time" Since according to my training notes the Sys is implicit when accessing it through the pshm pointer. Anyway, I received an error telling me that the structure SHM has no member named "Time". Can you advise me on how I should have done this?
Link to comment
Share on other sites

There are some threads that show an older way to do this (http://forums.deltatau.com/showthread.php?tid=106&highlight=fclock). But now you can use the C API function GetCPUClock() which returns the clock in micro seconds. This is described in the C function help from the IDE Help Contents area.
Link to comment
Share on other sites

The explanation is that some structures actually call functions to nicely report data in the script language. Sys.Time is one of these. You can look into RtGpShm.h but the easiest way to see this is to use the IDE help.
Link to comment
Share on other sites

  • 3 years later...
What if instead of counting down, I want to count up? I have an application in a Geobrick where I need to time how long a process takes and then write that time to a P-variable so I can display it on an HMI. I think I can mock something up by writing Sys.time (or sys.runtime) to one variable at the start of the process, a different variable at the end, and writing the difference between the two to my P-variable, but that will only get me accurate to within a second. First, am I thinking correctly that this will work? Second, is there another, better way that will get me accuracy to the tenth or hundredth of a second?
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

×
×
  • Create New...