LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Record time between two switches

Hello,

 

I have a system in labview that acquiries data from two pressure transducers for 10 seconds and write the data to a measurement file.

 

At some point during this 10 seconds a valve will be actuated. On top of the valve are two limit switches at either end of the valve travel to signal fully open and fully closed.

 

As the valve closes, the first switch will be released converting a boolean from True to False within Labview. When it finishes closing the second switch will be pressed, converting a boolean from False to True.

 

I would like to know the following:

 

- The time in milliseconds from when the VI started to the first switch change (i.e. valves starts to close)

- The time in milliseconds between the first switch change and the second switch change (i.e. duration the valve takes to close)

 

What is the simplest method to achieve this? Any sample code would be a great help. Thanks.

0 Kudos
Message 1 of 6
(3,278 Views)

@samfau2 wrote:

 

Any sample code would be a great help. Thanks.


I would say the same thing.  What have you tried?

 

There are a few methods and the one I'd go with would involve post processing the data.  The reason for this is you will have a log of all the data that was sampled.  And if your calculations are odd you can always bring up the original data.  So I'd make a DAQmx read, where it automatically logs to TDMS for the time you are sampling.  This will record the data for each sample, for each channel, and it will record the start times, and delta time between samples.

 

After the 10 seconds are over you can open the TDMS file, search for a rising edge on one channel, search for a rising edge on the other, subtract the indexes of those edges, to get the number between them.  Then multiple by the time between each sample.

 

Others may suggest a continuous sampling method where you get something like 1000 samples at a time looking for edges, doing something similar.

0 Kudos
Message 2 of 6
(3,272 Views)

Hi there,

 

Thanks for your reply and apologies for limited information. Your suggestion of post processing the data is very sensible.

I have been experimenting with tick counts and timestamps using event structures to capture the boolean change but I struggled to get the loops to operate properly amongst the rest of my code. As it is not precise when the event will occur the program was waiting for the change and delaying other elements of the program.

 

With regards to post processing, I imagine I could store the values into an array within labview and then write some code to identify the transistion after all the data has been captured. Is this what you had in mind.

 

Thanks for your suggestion!

Sam

0 Kudos
Message 3 of 6
(3,226 Views)

You do know about Event structures, don't you?  You can put both of the boolean values set by your switches in a While Loop containing an Event Structure with a Value Changed Event for each switch.  This loop does nothing (and takes 0 CPU time, to a first approximation) until the switch changes.  Did you notice that one of the Event Nodes on the left side is labelled "Time"?  This seems to be (I didn't easily find the Help that defined this value) the same as the value returned by the Time Count (ms) VI, so if you take a Time Count at what you consider Time = 0 to be, the Time node will give you the number of milliseconds that have elapsed since this Zero time (you need, of course, to do the subtraction).

 

In particular, read Time Count when the VI starts.  When your first switch changes (in the proper direction), Event Time - Time Count gives you the time in milliseconds to the first switch change.  When the second switch changes, its Event Time - Time Count gives the time in milliseconds to the second switch change, and subtracting "Second Time" - "First Time" gives you the duration the valve takes to close.

 

You can keep all of these values in shift registers in the (independent) While Loop that surrounds the Event structure, and when the second switch changes, you can "export" this value to your main loop.  A good method to do this is the Producer-Consumer Design Pattern, which you can find by clicking on the File menu, choosing New ..., From Template, Frameworks, Design Patterns, Producer/Consumerr Design Pattern (Events).

 

Bob Schor

0 Kudos
Message 4 of 6
(3,208 Views)

Yeah you're not going to want to use any timer function in your program.  Any tick count, or timer from within Windows is going to be flawed and full of jitter.  You are going to want to get your timing information from the DAQ hardware.  When you perform the read you can read the data as a waveform which I mentioned has the start and delta time between samples.  This should be in the TDMS log as well in the form of properties of a channel.  Using this calculate your time.

Message 5 of 6
(3,198 Views)

Yep, Hooovahh, you are certainly correct about the timing (what was I thinking?).  I must confess I've never "sampled" digital I/O on a non-RT system, but why couldn't you?  [That may actually have an answer ...].  If you did, you could look for and find the transitions, figure out the time from the digital Waveform (you don't need "absolute" time, only Time from Start, so if you start everything together and sample at 1 kHz, you'll get the time in milliseconds), and you'd be done.  Slick.

 

BS

0 Kudos
Message 6 of 6
(3,187 Views)