Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to switch quickly between finite analog output waveforms

I have an application using a USB-6341 to control a process machine.  One of the tasks is producing a predetermined analog output voltage waveform to control a heater cycle, which has two parts ... let's call them "A" and "B" (really ramp and soak, fwiw).  Usually waveform B should be run immediately after A completes, but occasionally A needs to be truncated (already hot enough), then B needs to run. 

 

I have tried a couple ways to make this happen, but I'm running into errors when I try to rewrite waveform B into the task.  I have been trying to do it using finite generation mode so that I can make use of the "DAQmx IsTaskDone.vi" to know when it is complete, since all of this is happening in one of several subroutine vi's that let the machine multitask with limited polling to each subroutine.

 

My wish list:

 

  • need to get the waveform changeover from A to B done without clearing the task, as the creation of the task is handled in a different portion of the application.
  • Switching from A to B should be fast both for the physical output (<.1 sec) and for program execution (Total duration of A+B is <30 sec, waveform dt is >.1 sec, 1.0 sec typ).
  •  Would still be nice to use finite generation because it makes the IsTaskDone polling so easy

One possible solution would be to write out A+B as a single finite task, monitor during "A" whether we need to cut it short, and if so, force the pointer of the output write buffer to jump to the beginning of "B".  Is that possible?  How?

 

I have tried to just stop the task and write a new waveform to DAQmx_Write.  It works once, but generates an error -200292.

 

I also tried stopping the task, calling DAQmx_Timing_(UseWaveform).vi with waveform B to get the buffer and sampling clocks reset for "B", then write the new waveform to DAQmx_Write.  Also works once, but generates error -200557 saying task must be stopped first.  Odd, since the DAQmx Stop was called immediately before DAQmx Timing ... maybe there is some latency waiting for the current sample to ouput before the state change?

 

Suggestions or solutions would be much appreciated

 

-tf

 

0 Kudos
Message 1 of 6
(3,437 Views)

One brute force method would be to use two AO channels, one for A and the other for B. Add an external analog switch and control it with a digital output  line. When you need to switch, start B and use the DO line to switch from A to B with the external switch. A can just run to completion or stop the task - since A is not longer connected to your heater control it does not matter.

 

Lynn

0 Kudos
Message 2 of 6
(3,433 Views)

I like your out-of-the-box thinking, but I want to do it without additional hardware.

 

-tf

0 Kudos
Message 3 of 6
(3,431 Views)

I'm most of the way there ... but getting some behavior that I don't understand.  Here's what I'm doing

 

  1. Create AO task (power level) and DO task (heater enable) (in top level vi, once at beginning of application)
  2. Append waveforms to get "A+B", same dt.  Wire this into DAQmx_Timing(UseWaveForm), set to Finite Samples
  3. Write waveform A to DAQmx_Write(Analog Wfm 1Chan NSamp), autostart = F
  4. When time to start, call DAQmx_Start for the AO task and do a single DO write on the DO task to enable heater.
  5. Loop A: use DAQmx_IsTaskDone OR monitor of process temperature (AI) to determine when to switch to waveform B.  When it is time...
  6. DAQmx_Stop for the AO task.
  7. Write waveform B to DAQmx_Write(Analog Wfm 1Chan NSamp), autostart = F
  8. DAQmx_Start
  9. Loop B: use DAQmx_IsTaskDone to watch for when waveform B is complete
  10. When it is, disable the heater with a single DO write to the DO task, and call DAQmx_Stop for the AO task.
  11. Loop back to #2 for the next heater run
  12. Clear the AO and DO tasks in the top level vi when the application exits.

This sequence gets me the physical behavior I need, without creating any errors or leaving the AO task in a bad state for the next time around.  But the one quirk is that the AO outputs multiple cycles of the waveform B.  The heater doesn't respond because of the digital disable line, but on the monitor line I have connected to the power level (AO) output, I end up with waveform B regenerating.  EVEN THOUGH DAQmx_STOP WAS CALLED!!

 

Can anyone lend some insight here?  Here's a visual of what's going on:

 

2014.05.30.1505 err Cap small.PNG

The light Blue line is a plot of what a simple A+B would look like.  The green is the temperature monitor of the thing getting heated, and the red is the monitor of the analog output being sent to the heater.  You can see that the early switch A-->B happens as desired when the green hits the threshold.  But why does the output continue from B to a second repeat of B even after DAQmx STOP?

0 Kudos
Message 4 of 6
(3,396 Views)

BTW, I tried throwing in a DoNotAllowRegeneration property node between the Timing setup and the first write, but then I end up with an error from IsTaskDone at the end when I haven't supplied any more data and it has completed the generation.  (err -200290)

0 Kudos
Message 5 of 6
(3,387 Views)

I'm not sure what else to suggest for you main setup - my instinct would have been to set the DoNotAllowRegenerationProperty. However, it looks like you can potentially address error -200290 by increasing the output buffer size.

 

From LabVIEW -> Explain Error:

 

"Error -200290 occurred at an unidentified location

 

Possible reason(s):

 

The generation has stopped to prevent the regeneration of old samples. Your application was unable to write samples to the background buffer fast enough to prevent old samples from being regenerated.

 

To avoid this error, you can do any of the following:
1. Increase the size of the background buffer by configuring the buffer.
2. Increase the number of samples you write each time you invoke a write operation.
3. Write samples more often.
4. Reduce the sample rate.
5. If your data transfer method is interrupts, try using DMA or USB Bulk.
6. Reduce the number of applications your computer is executing concurrently.

 

In addition, if you do not need to write every sample that is generated, you can configure the regeneration mode to allow regeneration, and then use the Position and Offset attributes to write the desired samples."

0 Kudos
Message 6 of 6
(3,338 Views)