LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event timing at Specific time intervals

Hello,

 

I've been working on a project for about two weeks now and still cannot build a VI that meets my specific timing needs.  First, I will give a small background as to what my project entails:

 

I am designing a DAQ system to monitor UV detectors that our company manufactures for calibration purposes.  I am starting from the ground up by using simulated signals to get the code right.  I want to collect data points from my detector at a rate of 1Hz and sum them into half-hour dosages.  I plan to eventually create a subVI to moitor each detector and put them all together in one VI such that I can monitor up to 20 at a time using my NI PCI6225.

 

I am able to create a VI that will record data into an array and and print the sum and average to an .xls file after a certain interval.  (I use 5 secs in my example programming just so that I can verify that its working, but I will eventually bring this to 1800 sec).  Rather than recording for a fixed time interval once I run the VI, I need the VI to record data at specific CPU clock times (11:00, 11:30, 12:00, 12:30, 13:00...etc).  Here's an example of what I want the program to do:

 

Let's say the user turns this VI on at 11:17:00.000 AM.   The machine will first Initialize a 2x1800 array.  Then it will collect data from 2 analog inputs, Temperature and UV, at a rate of 1 Hz.  These values will be stored into each column of the array, one column per second.  Simultaneously, an indicator on the front panel will show the average temperature values in the array as well as the total sum of UV values.  Once the clock on the computer reaches 11:30:00.000, the program will record the average Temp and Total UV values to file (with date/time stamp).  Then, it will immediately reinitialize the 2x1800 array to default values (25 for temp and 0 for UV), and begin collecting data into the array at 1 Hz again.  This will continue until the clock reaches 12:00:00 PM, when the average temperature and total UV values are recorded and the array is reinitialized again. After that, Data acquisition continues again until 12:30:00, when the system records, reinitializes, and collects data until 13:00:00... and so on.


I've attached a sample .xls file of what I want the 'write to LVM file' VI to generate.  I've also attached my working VI as well as a subVI that performs some signal math. 

 

I know that this is a detailed question that probably does not have an easy answer using express VIs.  Thank you very much for your time in reading ans assisting with my code.

 

PS. I'm Running LabVIEW 7.0 and DAQmx 8.1.  If you are going to update my code using a Newer version of LV, can you post screencaps of all relavent wiring and case structures so that I can implement them easily w/o having to downconvert? 

 

Thanks,

Ben

 

0 Kudos
Message 1 of 16
(4,910 Views)

What is the question you are asking, Ben?  Your file that you are writing regarding all of the measurements contains all of that data that you requested.

 

Matt

0 Kudos
Message 2 of 16
(4,901 Views)

the .xls file I posted is not what my VI outputs, its just an example of what I want the output to be.

 

I guess I did not ask my question clearly enough.  How do I control event structures in labview such that they occur at fixed time intervals relative to the CPU clock (13:00, 13:30, 14:00, 14:30....etc)?  This is distinctly different than the way my VI currently operates; controlling events at fixed intervals since the program's executsion (13:07, 13:37, 14:07, 14:47... etc, assuming I ran the VI at 13:07). 

0 Kudos
Message 3 of 16
(4,894 Views)

Typically you do not use the event structure for timing.  It is primarily for responding immediately to asynchronous events such as a user clicking on a front panel button.

 

A more appropriate architecture might be a state machine.  One state can be a Wait state which checks the system clock against the scheduled time for the next task.

 

Lynn

0 Kudos
Message 4 of 16
(4,886 Views)

Lynn,

 

I don't think Ben is referring to user events but rather than a more general event such as some period of time passing.  Ben, since you are using large intervals such as these, you can trigger writes when the system clock converted to seconds is a multiple of 1800 (see below):

 

20265i9BF41BE4154551E0

 

 

Regarding the file output, as I said in my previous reply to a similar post here, I would suggest writing the values directly to a text file in the format you desire.  This will give you the greatest control over your output.

 

Cheers, Matt

Message 5 of 16
(4,879 Views)

Thanks matt, that was exactly what I needed. 

 

Unfortunately, with each breakthrough I find, a new problem is encountered.  Now I have encountered a new problem when trying to change the simulated signals to real ones collected with the DAQ assistant.    My code worked perfectly as I wanted when I used the 'simulate signals' VI, but now when I insert the daq assistant in its place (accompanied w/ 2 select signals VI's), the array is no loner filled with values. 

 

It seems like rather than initializing the array as I wish (0 for all UV values and 25 for the temperature ones), It initialized the array with a zero reading from each analog input channel (which results in the -25 temperature values).  It only records one value in the first column of the array for the 10 second interval, then reinitializes improperly, records one datya set in the first column, and repeats ad nausem.  

 

Should I be using the advanced DAQmx VI's rather than the express VI?

Do I need to reconsider my whole timing structure for using real signals?

 

How can I get Program B to behave like my Program A?

-Ben

0 Kudos
Message 6 of 16
(4,857 Views)

After playing around with my code, I realized that I needed to put a wait vi in the main loop, as the code wqas executing too quickly.  Now the code works correctly, except for one thing, the last data point never reached the array.  if you watch the front panel while the VI operates, it collects data as normal, except the 10th second point is never recorded into the array, and then it reinitializes and continues onward. 

 

Realistically, if I am collecting 1800 seconds of data, omitting one point is mostly negligible. Is there a simple way to fix this, or will I just have to omit a second of data collection from each interval?

0 Kudos
Message 7 of 16
(4,850 Views)

Ben,

 

The wait is not necessary.  If you want to execute at a rate of 1 Hz, simply use the DAQmx API explicitly as below:

 

20279i1EFDFEE65E68CCA6

 

Here the acquisition rate is set explicitly to 1 Hz and the read will sit and wait until a sample is available at each iteration resulting in a 1 s loop execution time (another option is to use the timed loop with the iteration rate set to 1 Hz).  In the mean time you can be doing things in parallel to this (not necessary in your case unless you add a lot of computations outside of what you put up, but nice none the less).  

 

I think that the reason you are dropping data has to do with how the acquisition proceeds - you have a wait placed on top of any wait that might be expected in the acquisition that you have set up (plus computations and file writing downstream).  Jitter introduced because of the operating system can also make the results non-deterministic (i.e. there is the possibility that you will drop more data down the line).  

 

I didn't execute the VI, but I am willing to bet that the loop iteration rate is a little longer that 1 s which means that you might drop a second here and there and thus only capture 9 values in 10 s (I don't see anything else wrong right off the bat, but I may be missing something).

 

Anyway, those are just some thoughts.

 

Cheers, Matt

Message 8 of 16
(4,843 Views)

Matt,

 

That API definately does seem to be a better method of acquiring my AI data for rigid timing requirements.  Now I just wonder how to implement the specific mathematics operations I need to perform on my signal.  I tried simply recreating my existing VI within the while loop in the API you recommended, however I can't quite get the desired result of my 'program A' in the post above. 

 

The program executes at I think it should (w.r.t loop iteration), when I use the 'Highlight execution' option, yet when I probe the data coming out of the 'DAQmx Read' VI, I'm getting all Zeroes. 

 

Am I implementing my code properly to get the desired data? (I need summation of UV data and average temperature data.  Individual points collected are not relavent to me). 

 

Or do I need to use a less complicated code?

 

Thanks,

Ben

0 Kudos
Message 9 of 16
(4,817 Views)

Ben,

 

It's unclear to me why you are getting zeros for the output - is the input terminal configuration correct?  Are the input limits for the voltages correct (I am guessing that at the range you have them set to the best resolution will be -5 to 5V so 0 to 2.5 is not necessary)?  Why are you using NChan NSamp instead of Nchan 1Samp?  Are you sure the device is properly specified?

 

These are just a few thoughts.  Everything else looks good - you haven't really changed anything.  Make sure that the read is not throwing an error.

 

Peace, Matt

0 Kudos
Message 10 of 16
(4,809 Views)