LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to implement this code in labview

Hi

 

What is the best way to implement this code in labview programming.

 

I have an analogue input which triggers a boolean light when it reaches a certain voltage. but at the same time i would like it to enable two other outputs one for a set period of time and the other stay on until another statement becomes true.

 

For example

 

case 1:

 

Set output high

Delay(2000ms)

Set output low

 

Case 2:

 

Set output high

If statement 2 is true

then set out put low

if not then repeat until statement is true

 

Thanks for your help

0 Kudos
Message 1 of 8
(3,285 Views)

Repeat what?

 

What is statement 2?

0 Kudos
Message 2 of 8
(3,275 Views)

lol I started to explain myself further and just answered my own question about the second case so we dont need to worry about that one at the moment i will try it later. My main problem is finding the function that will turn something on for a certain period of time and then turn it off.

 

for example

 

If voltage is greater than 1 ->  light turns on  -> delay 2 hours -> light turns off

 

But during that 2 hours even if the voltage drops below 1 it wont turn the light off.

 

mainly just looking for the right delay function that can delay that section of the program for 2 hours whilst the rest of the program is still running. im guessing it will have to go into some sort of a contained structure. Still getting used to all the functions on labview 😞 !

 

Thanks

0 Kudos
Message 3 of 8
(3,264 Views)

You could use a state machine which has a "Wait" case - in this case you can poll an Elapsed Time Express VI, or use a functional global variable (FGV) to query whether or not the time has elapsed.

 

If it has not elapsed, stay in the "Wait" case.  If it has elapsed, or another condition occurs, move to the appropriate case.


Regards,

Peter D

0 Kudos
Message 4 of 8
(3,253 Views)

Hello,

 

I have attached a piece of code that I have written to do what I believe you require. The time that the VI waits for can be adjusted by changing the constant wired to the Wait (ms) function. This VI is very simple and only uses a numeric constant as an input but you could modify it quite easily to fit into your code.

 

Regards

David B
Applications Engineer
National Instruments UK
0 Kudos
Message 5 of 8
(3,251 Views)

Hi David,

 

The code you posted will work, although note that the front panel becomes 'unresponsive' - as changes in the controls are only read once per iteration.  The wait function is an example of an execution timing VI, however if we want to do software timing (like a 2 hour wait) - we should use software timing VIs.

 

Check out the following example (note we can stop execution during run-time):

 

SoftwareTiming.png


Regards,

Peter D

Message 6 of 8
(3,243 Views)

this looks like what i was looking for i will have ago at it later and get back to you guys.

 

thanks for the quick reply

0 Kudos
Message 7 of 8
(3,223 Views)

No problem, I look forward to hearing how you get on!

 

Created a related community example showing the key difference between the two types of timing.


Regards,

Peter D

0 Kudos
Message 8 of 8
(3,214 Views)