08-02-2010 09:20 AM
Hello,
I met a problem when I tried to use wait until next ms function to control the period of the loop.
I use Labview2009 now. I wrote a VI to sample the current values at 100Hz and then store the samples in a text file. The currents are sampled once in a loop and then wait for next 10ms to begin the next loop. After 360,000 loops (should be an hour), it will creat a new file to store the new samples in the following an hour.
I left the VI runs on CompactRio for the whole weekend. The result I got is shown in the picture below:
24 files should be created in one day. While there were only 3 files created in the firest 24 hours ( from Fri 16:00 - Sat 16:00). And after that it worked very well.
When I checked the first three files (created from Fri 16:00 - Sat 16:00), I found that it didn't sample at 10Hz. It sampled at the frequency of about 20Hz (sometimes 18Hz, sometimes 19Hz).
I am confused by the problem a lot. What may cause it didn't work in the first 24 hours and worked after 24 hours? And How could I fix this problem?
Thank you very much!
08-02-2010 09:33 AM
Without your code, this is a very difficult question to answer...
08-02-2010 09:35 AM - edited 08-02-2010 09:36 AM
You need to show us some code!
This cannot happen in a single loop, but can easily happen if you have e.g. stacked loops or sequences containing multiple wait statements.
Also have a look at these old threads:
Synchronization problems during measurements (using while loop)
accurate timing between events
If accurate timing is important, use a timed loop. Your incorrect times are faster, so I don't think there is a problem with the inner code taking too long.
08-02-2010 09:57 AM
Were you writing these files to a LAN? If so, maintenance on the LAN (typical for weekend) could have presented problems with saving files.
08-02-2010 10:04 AM
Thank you for your reply. Here is my code in attachment.
Thank you very much.
08-02-2010 10:07 AM
Thank you for your reply. Here is my code in attachment.
It works very for creat a new file every 10 minutes. But it fails when I tried to make it to creat a new file every one hour.
Thank you very much.
08-02-2010 10:07 AM
Thank you for your reply. Here is my code in attachment.
It works very for creat a new file every 10 minutes. But it fails when I tried to make it to creat a new file every one hour.
Thank you very much.
08-02-2010 10:19 AM
One big problem. You are obtaining a queue reference on every iteration of your innermost For loop, and never close it.
Your queue should be obtained outside of all your loops, and closed after your loops. Otherwise you will eventually run out of resources.
08-02-2010 10:22 AM
You probably have some race conditions. The way you determine the inner while loop termination seems dangerous and not very deterministic.
08-02-2010 11:10 AM
Thanks for the reply. When I tried to move the obtain queue function out of the loops, the element data type cannot be matched. The type inside the loop is 1-D array, while the type outside the loop is 2-D array. How can I make them be the same type?
Thanks a lot!