LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQ write issue on nested loop

I have an application which uses DAQ read/writes (see attached vi file). I apologize for the massive block diagram as this is a first attempt (rushed also) at LabView coming from a PLC/HMI/SCADA background. It was only when I was done that I was informed that I could use "sub vi".

 

The application in detail reads gas flows and LabView controls a valve through a PID block (located close to the center bottom of the block diagram). There is another PID (close to the center) which reads from a concentration signal and controls another equipment. The output of each PID is sent to the DAQ read/write which is configured to work with NI-USB-6009 to send the final signals to both the valve and the other equipment.

 

The user will enter a number in minutes as the duration of each iteration. The user will then enter the total number of iteration of the application. The inside loop evaluates for the duration of each iteration and ends its loop. The outside loop stops LabView after the final iteration. There is some logic located on the top left area of the block diagram which compares the iteration and a STOP pushbutton if the user wants to end both loops (and thus LabView) before the final iteration. 

 

Everything works while current iteration < number of iteration (and while STOP is not pressed). The moment when current iteration = number of iteration (or STOP is pressed), I place both PID to FALSE so that I can write an arbitrary value to (1) place the valve at a postion, 66.0 = Valve Position SP and (2) send a zero value to the other equipment, 0.0 = Oz Gen Output SP. The PID to FALSE is located on the top left area and the 66 and 0 writes is located outside both loops on the bottom of the block diagram.

 

The problem is that LabView does show on the front panel that both 66 and 0 was at least sent to the correct variable but the signal from DAQ read/write did not seem to get through the NI-USB-6009 the moment an attempt to stop LabView happens. The valve did not go to 66% open and the other equipment did not go to 0.

 

Any ideas?

 

P.S. The time delays were my attempt to make sure the writes to the local variables happen before LabView stops. 

 

0 Kudos
Message 1 of 2
(2,239 Views)

Hi vlad24,

 

The issue here is that your local variables are being written to 66 and 0 after the main loop has stopped running. This means that, while the front panel indicators update, the DAQmx write function does not run again. This is why the values do not get through to your DAQ device. Try running your code with highlight execution on (the lightbulb directly to the right of pause on the block diagram). This will show you the program's dataflow as it operates. You should see this behavior, that the values are not passed back through to the DAQmx writes. 

I would recommend you make the following changes in order to enforce the behavior you want. First, get rid of the case structure that performs the final update to these two controls. Then, move the DAQmx Clear Task and Error Handler VIs outside of your For loop. Right click on your timed loop and "add shift register." Then, wire the error wires to the shift registers on either side of your loop. Outside of the For loop, add another DAQmx Write VI into the dataflow before your Clear Task, and set this to write the single point out that you want. Be sure to right-click on the tunnels for the DAQmx task out and error on the right side of the For loop and select "disable indexing." Use the build array function to add in this last point to your array of previous values that are being sent to Excel. Right click the build array function and select "concatenate inputs," which will place it at the end. This setup should allow for this last point to be written out. I have partially implemented these steps to show what I'm talking about. See the attached image.

 

There are a couple things you might consider when writing future code. First, the For loop/timed loop combination could potentially be replaced with a simple While loop and the Wait (ms) function. You could implement simple logic to have the loop stop when a button is pressed or the iteration count reaches a certain level. Secondly, the execution speed of your code is slowed down considerably when you create and clear a DAQmx channel with each loop iteration. Consider creating the channel before the looping begins and clearing it after the looping ends.

 

Please let me know if this helps and if there is anything I can clarify.

 

Best regards,

 

 
Matt J - NI Tools Network
0 Kudos
Message 2 of 2
(2,192 Views)