LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

cvi-how to create stop watch program

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

 

0 Kudos
Message 1 of 8
(6,133 Views)

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:

  • The <samples>\userint\timer sample application uses a timer callback, which is periodically invoked at user-defined intervals.
  • You also might want to refer to the <samples>\utility\clock application, which is actually something very similar to what you want: a clock display. This application displays a digital clock. You can expand the source code to fit your needs and implement a stop watch utility.

Best regards!

- Johannes

0 Kudos
Message 2 of 8
(6,121 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 3 of 8
(6,117 Views)

thanks yet similiar to that

0 Kudos
Message 4 of 8
(6,090 Views)

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

0 Kudos
Message 5 of 8
(6,089 Views)

Did you already coded something base on previous answers or you implemented some function on your own? Can you post your code?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 8
(6,075 Views)

not started yet im still thinking what is the best way of writing

0 Kudos
Message 7 of 8
(6,049 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 8 of 8
(6,034 Views)