LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use a timer together with an event.

Dear All,

 

Today I tried all day to accomplish someting with labview, but I didn't succeed. Perhaps you can help me.

The problem is as follows. 

I have an event structure inside a while loop. The events are all triggered by booleans. Those booleans initiate

for instance some pumps or  other apparatus. The time-out is put at 200ms and inside the time-out structure 

are some GET function (for instance to obtain the values of some balances and to do some calculations with those obtained values.

 

Now I would like to be able to start an experiment. This means by pressing a boolean initiate the experiment. This experiment involves 

the starting of a timer and after every 10 minutes, the obtained/calculated data (from the time-out) structure should be written to a .xls file.

I'm not able to programm this part of the program. My first problem is that I need an event (triggered by a boolean) that start a timer. This timer should run always (independant of other events) until stopped by another boolean. After every 10 minutes this timer should initiate (with a boolean?) the data writing to a .xls file.  Can this be done by resetting the timer after every writing event?

 

So I have multiple questions, but my main question is how to build an event which is trigger by a boolean and then initiates an overall timer.

 

Thanks! 

 

Bio

 

0 Kudos
Message 1 of 12
(11,467 Views)

Bio,

 

Look at the Producer/Consumer (events) Design Pattern  (File >> New... >> VI >> From Template >> Frameworks >> Design Patterns).

 

I think using two loops will give you a more versatile program.  One loop has the event structure and the buttons, while the other does the work.

 

Lynn 

Message 2 of 12
(11,454 Views)
Also check out the Elapsed Time function, which provides an easy interface to measure elapsed time without using an event structure.
Jarrod S.
National Instruments
0 Kudos
Message 3 of 12
(11,424 Views)

Thanks guys for your replies. I tried your suggestions, but I'm still not able to get it right.

The problems are:

-Or the timer is waiting in the event until the time is passed. In this case I cannot reach/open other events, because the timer event is waiting.

-When using two loops, then the timer already starts at the beginning of the program. In this case I don't have any control of the timer.

 

To summarize my problem again.

I would like to start a timer by pressing a button. While the timer is running (counting down or up), I should be able to address other events. After the desired time is elapsed a boolean should be send to another event (writing certain data to a excel file).

 

Thanks for all your help 🙂

 

Best regards,

Dennis
0 Kudos
Message 4 of 12
(11,402 Views)

Dennis,

 

Please post what you have tried so far.  It is hard to guess what you might be doing.

 

Certainly you do not want to put the timer inside the event case, or even in the same loop.  This was the reason for my suggestion about the producer/consumer design pattern.  The only thing in the event loop is the buttons and a queue.  The timer starts when the command queued by the event is dequeued in the consumer loop.  If you can possibly have multiple devices running simultaneously but with different timing, things can get messy. But still very feasible.

 

Lynn 

Message 5 of 12
(11,399 Views)

here is the zip 🙂

 

 

0 Kudos
Message 6 of 12
(11,373 Views)

OK.  That worked.

 

You have made all the mistakes self-taught beginners with LabVIEW make, except that you apparently have a pretty good idea of what you want your program to do.

 

1.  LV is a dataflow language.  This means that any node which has all its inputs satisfied can run and once started any node runs to completion before another starts.  In your event case the timeout case will execute 200 ms after the loop starts (assuming the user did not push a button before that).  The Waits in the sequence frames mean it will be at least 555 ms before the timeout case completes.  200 ms later is will run again, if not other event has occurred.  Furthermore, you do not know whether the Waits will run before or after the other code in each od the sequence frames because there is no data dependency between the Waits and that other code.

 

2. A matter of style: It is recommended that front panels and block diagrams do not exceed one screen size.

 

3. Local variables violate the dataflow paradigm and are almost always unnecessary.  The WIRE is the variable.  Connect things via wires not local or global variables.  You will also need some shift registers.

 

4. Sequence structures are almost never required.  One exception: Single frame structures around something like the Wait function which does not have error clusters for dataflow.

 

5. Look at the Producer/Consumer Design Patterns which come with LV.  File >> New.. >> VI >>  From Template >> Frameworks >> Design Patterns..  The events version will be useful.  Also learn about state machines.  That architecture is versatile, powerful, adaptable, and much more likely to get you to where you need to be with your program.

 

6. The events will all be queued up in the internal event queue.  It just takes a long time for your program to get to them.  I like to keep the code in every event case simple enough that it executes before the user could get to the next button. The queued message handling in the Producer/Consumer takes care of this.

 

7.  You probably should have an event for Stop experiment.  It would send a command to the consumer loop to shut down all pumps, close files, and any other "cleaning up" which needs to be done before stopping the program.

 

This may seem like a lot, but you have most of the pieces.  Some re-arrangement and re-organization will help a lot.

 

Lynn 

Message 7 of 12
(11,342 Views)

Thanks for your advice! I will look into your suggestions.

I already took a look at the consumer/producer structure, but up to now I cannot understand it fully. 

Tomorrow, I'll spend more time to get acquainted with this kind (the right kind) of programming.

 

Thanks!

Dennis

0 Kudos
Message 8 of 12
(11,316 Views)

Dennis,

 

I would not go so far as to call it the "right kind" of programming, although it is often a very useful kind.   Many different approaches can be used to solve a particular problem.

 

The general idea of the producer/ consumer architecture is to have two independent, parallel loops.  The producer loop acquires or generates data or commands.  The consumer loop processes the data or commands from the producer loop.  Typically the loops run at different speeds, although the consumer must be able to keep up on the average to avoid a buffer or queue overflow.

 

Lynn 

Message 9 of 12
(11,293 Views)

Hi Lynn,

 

Today I used the time to try to programm with the producer/consumer structure. It's however not working and I think that I'm not on the right track.

Could you please have a look at this zip file (front control 3 is the main Vi).  I also don't know how  to incoorporate the timer.

 

All your help is appreciated 🙂

 

Thank you in advance,

Dennis

0 Kudos
Message 10 of 12
(11,276 Views)