bradp Posted September 24, 2008 Share Posted September 24, 2008 How do I make a timer in a script PLC? Link to comment Share on other sites More sharing options...
bradp Posted September 24, 2008 Author Share Posted September 24, 2008 open plc 1 L1 = sys.time + 0.01; while(L1 > sys.time) {}; p2 = p2 + 1; close Link to comment Share on other sites More sharing options...
bradp Posted September 29, 2008 Author Share Posted September 29, 2008 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 More sharing options...
bradp Posted September 30, 2008 Author Share Posted September 30, 2008 Attached is a file of timer functions that you can include in a project to give your code timer functionality. [attachment=1386:name] Link to comment Share on other sites More sharing options...
DT-Europe Posted November 7, 2008 Share Posted November 7, 2008 [quote=brad] Attached is a file of timer functions that you can include in a project to give your code timer functionality. [/quote] How or where do I include this file in the project? Link to comment Share on other sites More sharing options...
bradp Posted September 9, 2010 Author Share Posted September 9, 2010 They go under the Pmac Script Language\Libraries directory. Link to comment Share on other sites More sharing options...
Studebaker Posted October 4, 2010 Share Posted October 4, 2010 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 More sharing options...
bradp Posted October 4, 2010 Author Share Posted October 4, 2010 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 More sharing options...
Studebaker Posted October 5, 2010 Share Posted October 5, 2010 Great, I'll try that out tomorrow. Is there an explanation for why "pshm->Time" doesn't work? Is only part of the Sys. structure available in C or something? If so, is this described somewhere? Link to comment Share on other sites More sharing options...
Omron Forums Support Posted October 5, 2010 Share Posted October 5, 2010 One can also use Sys.ServoCount or Sys.PhaseCount if it is desirable to time applications in units of servo cycles or phase cycles, respectively. Link to comment Share on other sites More sharing options...
bradp Posted October 5, 2010 Author Share Posted October 5, 2010 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 More sharing options...
imandrew Posted September 19, 2014 Share Posted September 19, 2014 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 More sharing options...
steve.milici Posted September 19, 2014 Share Posted September 19, 2014 The sys.time structure element is floating point giving time resolution to microseconds. Just take the difference between your two events: P1=sys.time . . . P2=sys.time - P1 Note that you cannot write to sys.time. Link to comment Share on other sites More sharing options...
Recommended Posts