LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

the difference between the asynchronous timer and multithread using

Jeremiah,thank you for your help.
Now I have another question.I am doing a multitask application.It's a data acquisition system.In the background the sampling rate is 0.01ms,I need to gain datas every 1ms.At the same time graph must to be shown and other jobs to be done.Can I use the asynchronous timer or multithreading instead of?What is the difference
between them?And which one would be better for my application?

thanks again.
yours truly
tracy
0 Kudos
Message 1 of 2
(3,363 Views)
Hello Tracy,
I would not recommend the use of a timer with that small of a timer resolution (1 ms). One millisecond is the granularity of the Windows system timer, so you will not receive reliable events every millisecond (occasionally other threads will get scheduled during this time). Timers generally become unstable when you get below 50 ms (it depends on the machine and what is running, some may be able to do 20 ms reliably and as faster machines become available this number will continue to decrease). In this case I would generally recommend a multithreaded approach with a polling loop. However, I like to put a sleep command (Delay() in CVI) into my polling loops so that the processor is made available to other processes. Unfortunately the smallest Delay() time is 1ms. Would it be possible to only read your data every 5 or 10 ms? I think this would be doable with the polling loop and a 1-2 ms Delay inside of it. You might experiment with increasing the thread priority of this polling thread to guarantee it runs without interference from other threads (you must use Delay() with this so that the high-priority thread will relinquish the CPU to normal threads). A good question to ask is how long does each poll take. Consider how often it is running and how much CPU time it takes up. Another question is do you really need the data every 1ms? If it is being displayed to the screen, we only need to update it 5-25 times per second. Because of the overhead associated with checking the buffer and reading from it, it is much more efficient to use a larger buffer and only read it every 20-200 ms. A good analogy would be if I drove to the store each day to purchase single use portions of laundry detergent. If I simply bought the super size of detergent, I would not need to go to the store every day. I could use the free time to do other things such as compute FFTs or display graphs (I am the CPU and driving to the store is similar to reading the DAQ buffer). If you really must read this buffer every 1 ms, you might consider a Real-Time extension for Windows that is offered by a third-party software vendor. These extensions often provide timer functions that offer higher resolution (microseconds) than Windows can normally provide. You must experiment to determine which of these solutions will work best on your specific system and configuration.

Jeremiah Cox
Applications Engineer
National Instruments
http://www.ni.com/ask
Message 2 of 2
(3,363 Views)