From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to reset a while loop based on a value change event?

Solved!
Go to solution

Hello all,

 

I'm working towards a labview program that sends voltage out of a laptop via USB 6008, the voltage is amplified by an op-amp, then it comes back into the laptop. I've created a working circuit and program, but my current challenge is how to reset the average of the voltage values coming into the laptop after the user changes the numeric control (which controls the voltage going out). In other words, I need to be able to reinitialize the sum and iteration count to 0 every time this occurs.

 

I've looked up resetting of iteration counters via shift registers, but I'm not sure that would work in this case, but I'm also not sure how to reset the sum of an array (if possible). I've spent a good deal of time reading these forums and tutorials from various sites, so I think that it can be done with the proper nesting of case structures, event structures, and while loops, but I'm not sure how. I'm new to LV, just started learning it mid-January, so any help is appreciated.

 

Thanks in advance,

 

Graeme

0 Kudos
Message 1 of 5
(3,755 Views)
Solution
Accepted by topic author gBlaskov

You just need the single event structure with the right cases.  Use the Timeout case to get your new values and find the average (set the timeout to 100ms and get rid of the Wait (ms) function).  Keep the sum and the number of items in shift registers.  Wire these value through each event case.  In the Control:Value Change event, just set the values back to 0.  Then add a Stop Button Value Change event to stop your program.

 


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Download All
Message 2 of 5
(3,745 Views)

Thanks so much! This works perfectly. I've been working on understanding event structures recently because I felt like they might be the solution!

 

However, I'm not sure I understand what the "timeout" case does yet. I thought timeout case was used for situations in which the value doesn't change over a certain amount of time, so the structure would just "time out" and stop.

 

Upon further reading I suppose the structure waits 100ms for a value change, and if there isn't one, then it continues with the current case?

0 Kudos
Message 3 of 5
(3,706 Views)

Think of the timeout as an event in itself.  If the event structure is reached an there is no event in the event queue, then it waits up to the given timeout.  Once the timeout is reached (because none of the events the structure was registered for was generated), then the timeout case will run.

 

In the given code, the timeout is sort of setting the rate of the While loop.  The event structure can only run one event case per call to the event structure.  This is why it is in the While loop (to keep processing events).


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 5
(3,683 Views)

Thanks again! You have a really clear and concise way of explaining things!

0 Kudos
Message 5 of 5
(3,679 Views)