LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

coding a repeat cycle timer or intervalometer

I'm a beginner Labview user and want to write a simple 'repeat cycle timer' program.  Sometimes called an intervalometer the function is to constantly repeat an on/off output to cycle something.  It seems like it should be a simple project using nested loops and lv time functions but for some reason I'm not having much success.  I've searched for examples but haven't been able to find one and was  hoping someone could point me to or provide a simple example.  I want to be able to enter values for the on and off times for the output as well as the number of total cycles to do.  I'm using VISA to write the on/off condition to a relay board on a com port.  My LV version is 8.0.  Thanks, Mike
0 Kudos
Message 1 of 7
(4,181 Views)
Hi Mike,

Take a look at this VI I just wrote. I think it accomplishes the basics of your task.  Specify "on time", "off time", and number of cycles and the VI toggles.  It also has a LED indicator to give visual confirmation that the value is toggling.  The only thing you should have to change is the VISA resource name and the string constants used to toggle the relay.

Cheers,
Spex
National Instruments

To the pessimist, the glass is half empty; to the optimist, the glass is half full; to the engineer, the glass is twice as big as it needs to be has a 2x safety factor...
0 Kudos
Message 2 of 7
(4,174 Views)

Thanks Spex.  That is so much simpler than how I was trying to go about it with nested loops and adding or subtracting start time from current time etc.  Didn't think to use the Wait function.  Should be able to adapt it easily.  Thanks again.

Mike (who is feeling a little DOH)

0 Kudos
Message 3 of 7
(4,168 Views)

A question about the 'wait' function in your example intervalometer.vi.  Doesn't the wait (ms) function pause vi execution?  If I have other logic running, for example a manual switch matrix to turn outputs on/off,  won't the wait (ms) function prevent these manual outputs from operating until the two wait functions have finished? 

Mike

0 Kudos
Message 4 of 7
(4,148 Views)
Hi Mike,

The wait function will only pause VI execution if it is in series with a portion of the VI.  If you look at the attached VI, "Waits in Parallel.vi", you can see that the two loops act independent of each other with seperate loop times because the waits are not dependent on each other.  Also, the loop that contains a series of waits executes at the speed of the longest wait, but the booleans can toggle at the same time the loop is "waiting" because the wait and the toggling are parallel. 

In the first Intervalometer example, if you had additional code inside of that while loop, that code would appear to wait on the "wait" fuction because that code is only executed once per wait.  Alternatively, you could take a look at the "Intervalometer2.vi" attached to see how the code could be modified to execute a nested loop at a faster rate.  That nexted loop could operate your switch matrix.  Another alternative would be that you could add a parallel loop to handle that switching at a faster rate. 

In summary, Wait(ms) does not inherently pause execution of an entire VI.  LabVIEW uses the data flow model to determine when each node will execute (a node executes when all of it's inputs are available).  When using a Wait function in a loop, generally, that function operates in parallel with the rest of the code in the loop, but the wait is the "slowest" part of the code so it dictates the loop rate.  You can use frames and Wait to dictate a pause between fuctions because a frame will wait for all code in the frame to execute before it.  I think the Waits in Parallel VI attached demonstrates this idea.

Cheers,
Spex
National Instruments

To the pessimist, the glass is half empty; to the optimist, the glass is half full; to the engineer, the glass is twice as big as it needs to be has a 2x safety factor...
Download All
0 Kudos
Message 5 of 7
(4,138 Views)

Dear Spex

 

Thanks for your effort to upload the program, I am trying to use the ON OFF program for my solenoid valve however my DA is National instrument 6008 and I have connected my signal to DO1, would you please help me modify your program or could you please modify it for me so it can activate the valve through 6008 please.

 

THANK YOUUUUUUUUUUUUUU

 

EHSAN

 

 

0 Kudos
Message 6 of 7
(3,649 Views)

Hi Ehsan,

 

you have to replace the VISA functions by DAQmx functions. Instead of outputting strings you just output the boolean signal...

 

- Have a look at the exampleVIs comng with LabVIEW to learn how to use the DAQmx functions...

- Did you notice the age of this thread?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 7
(3,639 Views)