01-28-2015 12:22 AM
how to create a stop watch program using CVI.
using what function, i only know using timer() to do a counter
is there any ready function? can share if you have other method
i need to know the current program run time in hhmmss and is real time display for user to see
Thanks
01-28-2015 01:41 AM
Hello, chris_chua!
You might want to check out some CVI samples that ship with LabWindows/CVI. These are typically located in the C:\Program Files (x86)\CVI<version>\samples\ folder:
Best regards!
- Johannes
01-28-2015 01:46 AM - edited 01-28-2015 01:49 AM
These are rally two different questions but if you are using a timer in your program both of them can be addressed in the timer callback.
While inside the timer callback, the time from the last execution of the callback is received in eventData2 parameter, while eventData1 parameter holds the timer from the very first execution of the timer: if the timer starts together with the program, this second value approximates the program execution time.
To get the values, cast them into a double variable:
int CVICALLBACK timerCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) { double tscn, ttot; tscn = *(double *)eventData2; // Time from LAST timer callback ttot = *(double *)eventData1; // Time from FIRST timer callback // Other code here return 0; }
Depending on the precision you expect, you can implement a countdown by accumulating tscn variable until expected time has elapsed: this will introduce an approximation error that as of my experience is negligible for long intervals (order of magnitude of hours or minutes).
With these limitations, this method is simple and fast and does not implies neither a dedicated timing hardware nor special coding like the use of performance counters and so on.
This method can be ported to asynchronous timers, thus gaining better stability and independency from the user interface events.
01-28-2015 05:55 PM
thanks yet similiar to that
01-28-2015 05:58 PM
Thanks im using a stop watch to calcalate the program run time. dont know whether using a counter and a timer() is a good choice of doing this
example
00:00:01
00:00:02
01-29-2015 02:07 AM
Did you already coded something base on previous answers or you implemented some function on your own? Can you post your code?
02-01-2015 05:59 PM
not started yet im still thinking what is the best way of writing
02-02-2015 02:13 AM
OK, in this case you should set your precise requirements in terms of total time to measure and the precision you want in this measurement. Starting from this you can decide whether a software-only solution fits your needs.
Stop watch is a very generic concept: in a very rough aproximation, if you want to measure the time spent by a program that integrates a user interface where the operator sets up some parameters and then starts a function and so on (that is, order of magnitude of minutes or hours) then a software-oly solution can be enough and you have been given several hints in previous posts.
If on the other hand you want to measure times in the order of seconds with high precision than you will need to add some timing hardware to get this goal.