LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Struggling to set a timer in my VI.

Solved!
Go to solution

"(Also, your innermost case structure seems to only differ by two constants, so the DAQ should be after the case structure.)"

I dont quite understand what you mean here. The DAQ has to be inside the case structure for both TRUE and FALSE structures no?

 

In the 'TRUE' case, it sets the voltage to the red light to 2.5V, and green light to 0V. 

In the 'FALSE' case, it sets the voltage to the red light to 0V, and green light to 2.5V.

 

There are two lights with separate power supplies, they can both be on at the same time if both supplied with voltage.

0 Kudos
Message 11 of 27
(537 Views)

Is it possible to do this in a state machine? Like won't a state machine stop recording the data to CSV if you for example press a button? 

0 Kudos
Message 12 of 27
(524 Views)

@lorc34 wrote:

In the 'TRUE' case, it sets the voltage to the red light to 2.5V, and green light to 0V. 

In the 'FALSE' case, it sets the voltage to the red light to 0V, and green light to 2.5V.

 

There are two lights with separate power supplies, they can both be on at the same time if both supplied with voltage.


In both case, you set both LEDs, just with swapped voltages. If you would place the two digital outputs after the case structure, you would only need one each, one for red (0 or 2.5V) and one for green (2.5 or 0V).

 

You don't even need a case structure:

 

altenbach_0-1717613244642.png

 

This will light red or green, depending on the boolean input.

 

 

0 Kudos
Message 13 of 27
(519 Views)

I think I know what you mean, inside the 'TRUE' case it would be a value 2.5 and a value 0, and inside the FALSE case, it would be the same, with only two DAQ outputs outside. I suppose I can do that. Or no case structure at all.

 

Regardless I am struggling to understand how to do the timer thing in LabVIEW. I cant even do it in a basic VI, excluding all the other crap.

 

lorc34_1-1717614451838.png

 


Here is my idea of it. I have implemented boolean buttons to act as the magnetometer data level and physical button push. When the magnetometer level exceeds, it gets the 'fail time'. Then it puts that into a shift register into the next loop to be compared to the current time. However, the value is still 'true' because this is the way I implemented the red light to be latched on until a button is pressed (GerdW gave me the solution to that). So therefore, it takes the old fail time and replaces it with the new one. I don't know how to have a variable where it is like 'okay the timer has started' and then, after the 30 seconds passed, it will have 'okay stop the timer'. 

Then have that variable as a condition for starting the 'fail time'. If the variable is set to 'okay the timer has started', then it wont overwrite the 'fail time' in my head this is easy with a python script, you just set a variable 'start_timer' = started, verus stopped and have an if statement dependent on two variables, one is 'red light on?' and the other is 'timer already started?

0 Kudos
Message 14 of 27
(508 Views)

@lorc34 wrote:

Here is my idea of it.


Sorry, we don't "do" pictures. Why not attach your VI attempt instead?

0 Kudos
Message 15 of 27
(481 Views)

See if this can give you some ideas....

 

altenbach_0-1717626860804.png

 

0 Kudos
Message 16 of 27
(487 Views)

Hi Altenbach,

 

I actually manages to implement what I have been trying to do, in a dummy VI. This uses an express VI. when the level is exceeded and then quickly back to normal, the light stays red, and the timer will reset the light. if the level exceeded stays on, it won't reset the red light. 

 

I am typing this on my phone via remote desktop so I can't look at your vi yet.

 

I will say I tried to implement this into the full VI (the one you looked at earlier) and it sort of works but has weird behaviour. instead of stopping when it hits 4 seconds and then starting at zero again if you hit 'level exceeded', it will start at like 8, or 12 seconds. despite only counting to 4. I think the DAQ assistant taking 1000 samples at 1000 hz, causing while loop iteration to be 1 second, may be messing with the express VI which is in the same while loop as it. I will attach that full vi tomorrow.

 

I have attached the dummy VI, the full VI is on a different pc I can't access but it works the same way, with the express vi just outside those two for loops, and the left shift register going to the select function you can see inside the inner for loop on previous VI.

0 Kudos
Message 17 of 27
(481 Views)

Hi lorc,

 


@lorc34 wrote:

instead of stopping when it hits 4 seconds and then starting at zero again if you hit 'level exceeded', it will start at like 8, or 12 seconds. despite only counting to 4.


IN your example VI the ElapsedTime ExpressVI is set to count upto 5s and then auto-reset to start counting at zero again.

This does NOT fit to the description of the behaviour!

 

Why did you configure ElapsedTime to count upto 5s when you need to wait for only 4s?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 18 of 27
(470 Views)

Hi Gerd,

 

Because the boolean output "time has elapsed" wasn't working for me so I had to do it manually with the "elapsed time" number output

0 Kudos
Message 19 of 27
(461 Views)

Hi lorc,

 


@lorc34 wrote:

Because the boolean output "time has elapsed" wasn't working for me so I had to do it manually with the "elapsed time" number output


  • Set the time target to 4s when you need a target of 4s.
  • Don't hide the ExpressVI in structures: it counts the time even when you don't call it (it maintains its start time and duration in shift registers!)
  • Switch off AutoReset and do the resetting on your own to start ElapsedTime in a way controlled by YOU.
Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 20 of 27
(456 Views)