LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Turning digital output on for half second, off for half second.

Solved!
Go to solution

This is likely something simple to do, but I'm fairly new to Labview.

 

I just want to change my code attached here from having 3 boolean buttons to sending the digital output to on and off every half second while the program is running. Having the user be able to change the period(on for 2 seconds, off for 2 seconds, etc) from the front panel would be nice as well. I have done a small amount of research and am trying to decide to throw those 3 DAQassists into a timed loop or try to send the DAQassists a frequency generator of some sort.

 

If it makes any different I am using 2 old PCI-MIO-16E-4 (6040E) cards with BNC 2110 boards attached to those which have been working well so far. 

0 Kudos
Message 1 of 8
(4,368 Views)

A timed loop would work, but wouldn't be very responsive to changes inside the loop, considering the periods you are talking about using.  I would keep something similar to what you already have.  Use the elapsed time.  You just need to put the DAQ parts into a case structure so that they only execute when time has elapsed.  Use a feedback node to alternate true/false (instead of buttons). Also, check the current Set Run Time against the previous value (using shift register or feedback node) to reset the Elapsed time count, and set Auto Reset to true.  Don't stop the loop when time has elapsed, so it can keep running.

Message 2 of 8
(4,345 Views)

Here is a basic version that will turn the digital outs on then off every x seconds. This assumes the digital outs are in sync, all off or all on. You should be able to modify it easy enough if you need a different case.

 

Capture.PNG

Message 3 of 8
(4,324 Views)

StevenD,

 

When I run your code, the relays do not turn on. I think there is an issue with writing the data. The correct output lines are selected Dev1/port0/lines0:2. When I push stop I also get this error at the close task square even though I have the proper ports selected (0:2):

 

 Error -200524 occurred at Timed Valves.vi

Possible reason(s):

Write cannot be performed, because the number of channels in the data does not match the number of channels in the task.

When writing, supply data for all channels in the task. Alternatively, modify the task to contain the same number of channels as the data written.

Number of Channels in Task: 1
Number of Channels in Data: 3

 

I will keep messing around with my code and your code, I appreciate the quick response

0 Kudos
Message 4 of 8
(4,243 Views)
Solution
Accepted by topic author jtboik

I modified my original code using some of the elements from StevenD's code and got it to work. Using the Daq Assists in such a way is probably redundant but it's easier for me to understand. Having trouble understanding and getting the usual red DAQmx VIs to work together properly. Going to mark this as solved, I'll likely open a new thread if I have questions on different topics in the coming days/weeks. 

0 Kudos
Message 5 of 8
(4,220 Views)

Sorry, my mistake. You can change the channel name to dev1/port0/line0:2 to get the correct lines and change the DAQmx write to be single channel instead of multiple channels (I forgot DAQmx DO tasks are treated like a single channel if they are all on the same port). At the very least I would put your express VI's inside the case structure so you are not trying to write to the hardware every iteration of the loop, only when the value changes.

0 Kudos
Message 6 of 8
(4,202 Views)

Any idea how I can separate the on-time and off-time to be different, on for 1 second, off for 2, etc? Is it as simple as setting up another double x 1000 somewhere?

0 Kudos
Message 7 of 8
(4,179 Views)

You could change the "Time Delay (sec.)" to an array of values and keep the index on a shift register. The code I provided was pretty limited in scope. If you want a better architecture to handle different cases I would suggest looking at state machines.

 

State machine tutorial

0 Kudos
Message 8 of 8
(4,173 Views)