LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Executing Loops for Fixed Durations

Hello,

 

I would like to count the number of times an event occurs within a defined period (1000ms). I have tried to implement this with an Elapsed Time item (see the attachment).

 

Time Target, is set to: Get Start Time +  1000 (run for one second after starting)

Auto-reset, is set to: True

Set Start Time, is set to: 0 (uses the current time as the start time)

The output, Time Has Elapsed, is fed into the While loop. After one second of the VI executing, this line should become True hence the While loop terminates.

 

When I run the VI the loop never ends (I can continuously vary the gauge value). How do I correctly implement this delay?

 

Thank you

MCU

0 Kudos
Message 1 of 6
(4,128 Views)

Hi MCU,

 

If I were you, I'll use sequence structure.

Keep timing in the first loop.

Run for loop in second sequence.

Collec time in third loop, and minus the time in first loop.

You may refer to my attached screenshot for more information:

 

Message 2 of 6
(4,106 Views)

I think this may help you.

 

 

Balaji(CLAD)

 

Balaji PK (CLA)
Ever tried. Ever failed. No matter. Try again. Fail again. Fail better

Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
Download All
Message 3 of 6
(4,102 Views)

Hello,

 

Thank you very much for the help.

 

Regards

MCU

0 Kudos
Message 4 of 6
(4,051 Views)

MCU wrote:

I would like to count the number of times an event occurs within a defined period (1000ms). I have tried to implement this with an Elapsed Time item (see the attachment).

 

Time Target, is set to: Get Start Time +  1000 (run for one second after starting)

Auto-reset, is set to: True

Set Start Time, is set to: 0 (uses the current time as the start time)

The output, Time Has Elapsed, is fed into the While loop. After one second of the VI executing, this line should become True hence the While loop terminates.

 

When I run the VI the loop never ends (I can continuously vary the gauge value). How do I correctly implement this delay?


OK, your VI has two problems:

  1. There is no event structure, so it is a bit hard to understand what event you are trying to count. Changes in knob value perhaps?
  2. You are wiring the "elapsed time" express VI completely wrong. With each iteration, you are increasing the time target as "start time+1000" so the loop will never end. (The start time is a very big number, go probe it!) That feedback node makes no sense at all! The time target input is also in seconds, not milliseconds!. (It is difficult to tell what's connected to where in your image, especially since nothing is labeled. For better help, it is always better to attach a VI instead of an image).

Here's a quick draft of some code that counts how many times the knob changes value during one second, then stops.

 

(As othere have noted, there are probably more efficient ways using tick count, but let's use the "elapsed time" express VI for simplicity.)

 

Message Edited by altenbach on 02-07-2009 10:14 AM
Message 5 of 6
(4,025 Views)

Hi MCU,

    

Is your problem solved? If so please mark post (Whichever you think is the best solution for your query). This will help others facing same problem and looking for a solution.

 

 

Balaji PK (CLA)
Ever tried. Ever failed. No matter. Try again. Fail again. Fail better

Don't forget Kudos for Good Answers, and Mark a solution if your problem is solved.
Message 6 of 6
(3,876 Views)