LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

External Sample Clock timeout

Hi,

 

I'm attempting to program up a Met One 010c cup anemometer which sends out 11V pulses whose frequency correlates to wind speed. I've written the following program Met One 010c-3b.vi which works when there's no sample clock and outputs data to the graph and to the write measurement to file VI. 

 

However the timestamp on the file only occurs intermittently (every 130 recorded samples if i recall correctly)  and i've been advised to put a sample clock in between the create virtual channel and start VI to make the timestamp occur every sample. However doing this i get errors that first tell me I have to use an external clock, making the clock external then gives the timeout error 200284 after the read function. I expect this is because the wrong source has been selected for the external clock on the timing function.

 

I don't fully understand how the external clock works and i assume i need to set up which ever port i select as an external clock?

 

I have read through the following

 

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P8XsSAK&l=en-US

 

           -> how do i  verify that the start trigger is configured correctly? (i know my program doesn't have one)

           -> how do i verify the external timing is configured correctly?

 

https://www.ni.com/en/support/documentation/supplemental/06/learn-10-functions-in-ni-daqmx-and-handl...

 

https://www.ni.com/en/support/documentation/supplemental/06/timing-and-synchronization-features-of-n...

 

 

I tried to implement some of the diagrams indicated in the last link (eg Figure 2 & 3) but when i went to select the source for the analogue output I was given no available options. I have the NI 9205,9213,9403,9423,9215 sitting on a cDAQ 9178, so none of these do analogue output. Does this mean i can't use an external clock? 

 

Thanks for the help, i know this is a simple question but i'm getting nowhere fast.

 

Kind Regards

 

Orfeo

0 Kudos
Message 1 of 9
(3,323 Views)

Hi Orfeo,

 

Are you missing data points all together or are you just missing the time stamp? Also, what type of file are you writing to (text or TDMS)? I'm not sure that this is necessarily a problem with needing a sample clock, as there is no need to make the rest of your application conform to an external clock just to get accurate timing info.

 

If you are missing data points all together, I suspect this is due to the time taken by that Write to File express VI inside your while loop. Express VIs are very general purpose, which can make them a bit slow and cumbersome (especially when they're used in loops). Essentially what is happening every time you call this Express VI is your file is being opened, written to, and then closed on EACH iteration of the loop which can cause problems. By using more specific VIs (open/create/replace file, write to text file, close file) you can open your file once before your loop, write to it repeatedly inside your loop, and then close your file once after your loop executes. There is a good example of how to do this in the LabVIEW example finder. To get to it, navigate to the help tab in LabVIEW, select "Find Examples," and search for "Write to Text File.vi".

 

If you choose to write your file to a TDMS file, what happens is a time stamp is taken at the first sample and last sample, and all points between are given a "delta t" value to represent how much time has passed since the initial sample was taken. 

 

Let me know if this helps you resolve your issue.

 

Courtney L.

Applications Engineer

National Instruments

 

Message 2 of 9
(3,309 Views)

Thanks for your help Courtney,

 

I had a look at the Write to Text File.Vi you suggested and i tried to implement it in my program. It appears to be almost working. The formatting of the strings is stuffed up so that i'm getting an ever increasing number of columns in my data (see attached text file). Can you advise me where i've gone wrong?

 

An example of the file is below

 

24/11/2011 11:21:54 AM     2.32     2.14
 2.62     2.11
 1.81     1.49
24/11/2011 11:21:54 AM     2.36     2.32     2.14
 2.62     2.62     2.11
 1.82     1.81     1.49
24/11/2011 11:21:54 AM     2.40     2.36     2.32     2.14
 2.59     2.62     2.62     2.11
 1.76     1.82     1.81     1.49
24/11/2011 11:21:54 AM     2.43     2.40     2.36     2.32     2.14
 2.55     2.59     2.62     2.62     2.11
 1.73     1.76     1.82     1.81     1.49
24/11/2011 11:21:54 AM     2.53     2.43     2.40     2.36     2.32     2.14
 2.48     2.55     2.59     2.62     2.62     2.11
 1.69     1.73     1.76     1.82     1.81     1.49

 

 

I assume i've just not got my tab delimintors in the right place? or perhaps i need end of line qualifiers?

 

I would also like to have the timestamp more accurate, down to the milisecond. I see the format time string VI has an option to format the string %<digit>u which should do this but it appears to just paste the <digit>u in the string. We are wanting to sample data at 10-20 Hz and record the time of the samples. For one instrument these samples will be done simultaneously.

 

 

Thanks again

orfeo

Download All
0 Kudos
Message 3 of 9
(3,307 Views)

Hey Orfeo,

 

I modified the Write to File example to look a little bit more like what you're trying to do. I have this test file working fine but it's a lot simpler than yours. I fiddled with the time format string and discovered that the correct format for the digits isn't %<#dig>u but rather %#digu, for example for 3 digit fraction you would write %3u. 

 

Take a look at what I attached - it should at least solve the millisecond bit. Let me know if this helps or if you make any progress and in the mean time I'll keep trying to figure out the funky increasing column problem.

 

Courtney L

Applications Engineer

National Instruments

 

0 Kudos
Message 4 of 9
(3,285 Views)

You are getting ever growing text files because you are writing out the array data that you are building the new data points into.

 

You should only write out the new data from that iteration to the file.  Only use the data arrays that are built in and stored in the shift registers for the graphs.

Message 5 of 9
(3,283 Views)

Yep. You'll notice you have repeating data values in the log. Ravens Fan's recommendation should fix it.

0 Kudos
Message 6 of 9
(3,270 Views)

Thanks Guys,

 

I am a tad busy at the moment but i will implement these steps in a few days, Raven Fan's reasoning sounds sound .


Thanks both to Raven and Courtney.


Orfeo

0 Kudos
Message 7 of 9
(3,267 Views)

Hi,

 

I implemented your advise and i've got the VI up and running. It writes my measuremnts to file at a rate of 10 Hz. I wanted to write them at 20 Hz but found that it would only give me 12 Hz when i set the wait function to 50 ms. I assume this is because the loop is unable to sample that quickly? or the loops is getting caught up on the write measurement to file instructions. Can you think of a way of alleviating this? This is not vital here but it will be for another instrument. I have seen examples which had the write text to file outside the while loop which i assume frees up some processing time? Should i consider this? I'll be planning to record samples at 20 Hz for an extended period of time 8-24+ hrs, am i going to run into any memory problems?

 

Also, i wanted to implement a header for the write text to file instruction, while i see there are some examples online i can't see where the details are for the header. Can you advise how i add a customisable header to my write text to file instruction?

 

thanks again

orfeo

0 Kudos
Message 8 of 9
(3,250 Views)

Hey Orfeo,

 

So I took a look at your VI... Since you're only trying to sample at 20 Hz I would be very surprised if it was the Write Measurement To File that was the bottle neck here. One thing to try would be writing to TDMS format instead of a text file. This write is a lot faster than the text file write, and the file is a lot smaller. Also, you aren't limited by maximum row constraints in Excel or Notepad for large amounts of data (this was 65,536 rows in Office 2007 and has since been increased to about 1,000,000 rows in the newer versions). Your VI would essentially remain the same, but you would replace the text file VIs with their TDMS equivalents (TDMS open, TDMS write, TDMS close).

 

If you switch to TDMS and are still having time limitations, it could be something else. You could take out the file write functions altogether and benchmark your loop iteration time with this example VI:

 

https://forums.ni.com/t5/Example-Code/Benchmark-Loop-Iteration-Time-with-Tick-Count-Timer/ta-p/35008...

 

Once you have a benchmark time, then you can add back in the file write functions and see how much of an impact they have in terms of timing. It looks like the "met one multiplication" VIs implement matrix multiplication. On each iteration of your loop, your array is growing so this will take longer and longer. The later iterations will be much slower overall. For memory/time management, it may be advisable to estimate the eventually size of your array (ex, 20 samples/sec x 8 hrs x 4 channels) and pre-allocate this space by initializing your array to be a certain size.

 

I hope some of this is helpful! I will try to work on a better array header example for you tomorrow.

 

Courtney L

 

0 Kudos
Message 9 of 9
(3,236 Views)