09-14-2009 03:08 AM
I'm using CVI 8.5 to run my program.
1) Using Async Timer at interval of 2ms for data extraction from an third party pci card (using dll function for data capturing).
2) Async timer function also stored the 'time elapsed' in every events ticks into an array with a counter.
E.g Event_timer_ticks:
RecordedData[Cnt][0] = Time_elapsed;
Cnt++;
3) and displaying data on the GUI using UI timer at 50ms (or more) interval simulatanelously.
4) both the Async timer and UI timer have to run in 30sec when they starts.
When both timers stopped, the program will do a 'ArrayToFile()' to store my time and data into a file.
However, my recorded data file showed inconsistant timming, it seems to have some missing interval of 3 to 7msec in the array.
I have no idea what could be the reason of the missing interval? How can I resolve this?
Thank you.
09-14-2009 04:16 AM - edited 09-14-2009 04:18 AM
Hi Newbee_Gee,
it is not clear to me if you are facing a problem of "inconsistency " (i.e. data with non coherent values) or "non constancy" (i.e. variable intervals between samples). Nevertheless, I would try perform some tests in order to discriminate if someone is interfering in your process.
First of all, keep in mind that Windows cannot be intended as a real time OS: that means that every task is subject to the influences of other processes running in the system; this is true even for CVI Async timers, which are built on top of multimedia timers.
I would examine OS configuration excluding the most possible processes there are running concurrently with your application (antivirus, periodic backups, automatic OS updates, network mirroring if the PC is networked...), turn off the screen saver and ultimately try with the sole acquisition process excluding the data display timer. I would also investigate on that acquisition board: how much time will your calls to DLL functions take to execute?
09-14-2009 04:54 AM
have you ever heard of time quantum ? under this nuclear-physics-like name hides the amount of time an operating system allows a thread to run before giving hand to another thread.
let me explain further: a multithreaded operating system gives the impression of executing everything in parallel by executing a very small amount of one thread, then going to the next thread and executing another small amount of code, then to the next thread ... the operating system let a thread run for a specific amount of time before switching to another thread, this amount is called time quantum. most thread do not use the full amount of time they are allocated, because they are generally waiting for input from another thread: most threads on modern OSes are I/O bound.when a thread do not need its time quantum, it tells the system to switch to the next thread (on windows, this is done by a call to Sleep(), WaitForSingleObject()).
the time quantum has a system-wide default value which may be adjusted. it ranges from 5 to 50ms. what does all this mean, is that a standard timer on windows may not have a precision better than 5ms on modern fast computers, on older computers (less than 400MHz) the resolution was 50ms. the inconsistencies you are observing are due to another thread which uses its full time quantum because it needs to perform some operation, thus not letting your thread execute.
keep in mind that your timer is not designed to have such a low resolution. a preemptive multithreaded operating system is quite a beast and you cannot control every part of it.
now, for the interesting part, you can cheat... but this cheat comes with no guarantee. the Windows SDK defines a timeBeginPeriod() function which, although it is not documented, tweaks the time-quantum for the current application, allowing to have a timer resolution of 1ms. it will not miraculously cure your problem but it may help (it may also have no effect at all in your case). don't forget to #include <mmsystem.h> and to add winmm.lib to your project, and to call timeEndPeriod() when you are done. the effect is better observed when using Windows SDK functions: Sleep(), WaitForSingleObject() and CreateWaitableTimer().