LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

creating an accurate stopwatch withing a loop containing daqmx read

Hey Im newish to labview and need some help. I am using a NI USB 6008 device to read in voltages from 2 different instruments. One is just a pressure gauge which outpts voltages ranging from 0 to 5 depending on the pressure. The other is a system of 2 switches that I put together. The idea is to use these switches to measure car speed. When driven over, each switch produces a different voltage, and using this I want to start a stopwatch when the first one is driven over and stop it when the second one is driven over. I need the timing to be as accurate as possible so that I can accurately meassure the speed of a truck ranging from 80km/hr to 100km/hr.

 

I have done this to the best of my ability so far, but the program I made is inaccurate. I have a DAQmx read and the stopwatch both in the same loop. The switches do work, however, it seems like they are only updating as fast as the DAQmx is reading or something. When I just try to hit the switches right after each other, i only get a few different stop times. I have the DAQ reading 100 samples a second at 1000hz.

 

So if someone could help me out, it would be most appreciated.

0 Kudos
Message 1 of 17
(3,232 Views)

Brubie,

 



brubie wrote:

. I have a DAQmx read and the stopwatch both in the same loop. The switches do work, however, it seems like they are only updating as fast as the DAQmx is reading or something.

 

So if someone could help me out, it would be most appreciated.


Yep- the while loop can only iterate after all the code in the loop executes.  what you need to do is place the stopwatch in its own loop.  Remember that you cannot use a wire to pass the booleans from one loop to the other because this would force the read loop to comlpete before the stopwatch loop started.  I would think that an event structure for the stopwatch loop would be the best way to go.  use the start and stop value change events and use a property node in the read loop to write property.value(signaling.)

 

I hope this helps

 

 


"Should be" isn't "Is" -Jay
0 Kudos
Message 2 of 17
(3,224 Views)

Hey Jeff, thanks for your input.

 

I tried to create the event structure. I tried to put the stopwatch in it. But im a little confused at the wiring for it. I created the 2 events for start and stop value changes, but im not sure on where to go from there.

 

Also, I added a property node in the read loop, but I cant wire anything to the properties. Im just using a DAQmx Write property node right? And Im a little confused on how values input to these properties would be transfered to the event structure.

0 Kudos
Message 3 of 17
(3,210 Views)

propnode.PNG

 

Right click the booleans and select Create>Property node>Value(signaling) to make the correct nodes.  each time your read loop writes these values a value change event is generated even if the same value is overwritten.  So, your stopwatch loop is going to need to read the current value and choose the right actions to take.


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 17
(3,206 Views)

hey, so I created the nodes with no problem. Since they were value signalling does that mean that they already correspond to the start and stop events?

 

How do I read the current value in the stopwatch loop? It gives me basic options of things like OldVal and NewVal, but those dont do anything. Im not sure exactly what should be going in the stopwatch loop. Before I had the stopwatch in a case structure, but now its in an event structure, so it needs to be altered, but I cant figure out how to change it so that it works.

 

Thanks again for your help so far.

0 Kudos
Message 5 of 17
(3,198 Views)

Brubie.

 

You already solved that one!  all you need to do is read the indicators inside the case event and perform the same actions you did while it was in the previous while loop.  

 

So your stopwatch function is: While - wait for event- see what action to take and take it - loop.  remeber to read Stop from a property node to synchronize the halting of both functions.

 

Good luck


"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 17
(3,195 Views)

Hey Jeff

 

So I tried to put together the full stopwatch loop, but there are probably some wiring and definately some logic errors. The program can run, and the stopwatch responds to the switches to a degree, but still does not run properly. I just cant make heads or tails of which values should be wired to which inputs.

 

Also, I wired the second stop to a property node, but it does not work. When I run the program the stop button just does not do anything. Is it the property node I have, or is it something wrong with the loop itself?

 

Ill attach what Ive done just so you can see.

 

Youve been a great help so far!

0 Kudos
Message 7 of 17
(3,188 Views)

Yep- its the wrong property node right click the node and Link to> Pane>"stop"

you are reading the "Stop" indicator and not the "stop" control so you stop the stopwatch loop for the wrong condition (always dangerous to have two front panel objects with the same name except for text case).

 

Also from the help on event structures

"Has one or more subdiagrams, or event cases, exactly one of which executes when the structure executes. The Event structure waits until an event happens, then executes the appropriate case to handle that event. Right-click the structure border to add new event cases and configure which events to handle. Wire a value to the Timeout terminal at the top left of the Event structure to specify the number of milliseconds the Event structure should wait for an event to occur. The default is –1, indicating never to time out.

so you need to add a timeout to exit the event, and hence the loop, if the user presses "stop" but no other events occur.

 

You're doing great!

 

As one more thing to consider, how could you improve defining the timing relationships in the loops?  Right now there are three threads in the read loop:

read>calc>write file

Elapsed time> write file

Get time stamp

These can execute in any order.

 

In the stopwatch loop you have two threads

Read property node

event structure

 


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 17
(3,179 Views)

Hey Jeff

 

So I switched the property node to "stop" and there was an error. The property itself I have set to value, is this correct? Like this, it says the var type is variant, which does not connect to the stop input.

 

I tried connecting a timeout of 10 seconds to the event structure. I knew it wouldnt be this easy because it gave me another error, haha. But it mentions that I need to provide a case to handle the timeout event. Do I do this inside the event structure, or do I somehow connect that to the stop input of the while loop?

 

As for the timing question you provided. Are you refering to some kind of sequence which will determine which thread will happen in what order?

0 Kudos
Message 9 of 17
(3,147 Views)

brubie wrote:

Hey Jeff

 

So I switched the property node to "stop" and there was an error. The property itself I have set to value, is this correct? Like this, it says the var type is variant, which does not connect to the stop input.

 

Check the mechanical action of the control------

 

I tried connecting a timeout of 10 seconds to the event structure. I knew it wouldnt be this easy because it gave me another error, haha. But it mentions that I need to provide a case to handle the timeout event. Do I do this inside the event structure, or do I somehow connect that to the stop input of the while loop?

 

Yes- you need a timout case it should do nothing

 

As for the timing question you provided. Are you refering to some kind of sequence which will determine which thread will happen in what order?

 

Yes- (hint error in- error out forces data dependancy)


You're getting there! (don't forget to use <ctl-h> to show the help)


"Should be" isn't "Is" -Jay
Message 10 of 17
(3,143 Views)