From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

AO Generation Only Works in Highlight Execution

Hello all,

I am trying to write a sine wave of set frequency and amplitude to a tactile transducer to make it vibrate.  Previously, I have been starting a task, tracking elapsed time that it ran, and stopping it once it had run as long as I wanted it to (50ms).  However, this method of intermittently starting and stopping the waveform would cause the AO to hold the last value of the sine wave, which was usually non-zero.  The problem with this is when I would write the next waveform (starting at 0), the AO would drop abruptly to zero, causing a clicking noise in our transducer.  

 

Before I get into what I'm doing, here is some general info:

- Windows 7 PC running LabVIEW 2010

- AO Generation through NI USB-6211
- AO is configured to generate 5000 samples at 100k sampling rate (50ms min write)


In an attempt to work around this, I decided to write sine waves to the nearest half period to produce a duration closest to the one I want (e.g. if I want a 50ms of a 100Hz waveform, I would generate 5000 samples of a 100Hz sine wave at 100kHz, or 5 oscillations, with each oscillation being 1000 samples and 10ms in duration). If the sinewave could not fit a convenient amount of half-periods (e.g. 2.5 oscillations), I would pad the rest of the 5000 sample write buffer with zeros.  This way, I am sure that the AO channel was last sent zeros to avoid the clicking between waveforms.

PaddedWfm.PNG

Figuire 1: Example of generating nearest half period of waveform and padding with zeros.  1.5 Oscillations of 35 Hz waveform.

 

 

 

When I call my subVI which generates the waveform and writes it to the AO channel, it is not behaving as I would expect. If I do not highlight execution, it seems to be writing a very brief "blip" to the channel.  If I highlight execuption in the sub VI, it generates as expected.  I tried adding in a while loop with "Is Task Done" to prevent it from stopping the task until it was complete, but this caused it to generate the waveform many, many times, and the "Is Task Done" loop ran over 2000 times!
IsTaskDone.PNG

Figure 2: "Is Task Done" loop used to try to allow task to complete before stopping task.  This resulted in Waveform in Figure 1 being generated repetetively, instead of once.

 

I realize this is a lot of information, so let me know if I need to clarify anything.

 

Thanks!
Attatched Files:

StartleResponse_PPI_v4.vi - Main VI

UTIL Generate Pre Pulse v4.vi - Sub VI that generates and writes AO
UTIL Config Cont AO.vi - Configures the Task for the AO Channel

UTIL Calc n Osc.vi - Called by UTIL Generate Pre Pulse to computes nearest half period to match pulse duration

 

0 Kudos
Message 1 of 3
(2,471 Views)

When you use DAQmx write, it fills memory buffer. Generation is started with DAQmx start task. Then you immediately stop task. If there is delay due to highlight execution, it has time to generate once.

"Is task done" is not stopping the loop, because task is continuous, it is not done, it is always generating.

 

Change to finite generation. Then you can wait until task is done - to avoid polling in very fast loop (it does not have delay!), use "Wait task done.vi"

To speed up starting of the task, after configuration change state to "commit". Do not unreserve the task if you plan to use it again. 

Add clear task in the end of main.vi.

0 Kudos
Message 2 of 3
(2,422 Views)

Thanks! I realized it was set to "Continuous Samples" in the Config AO vi, and changing it to Finite Samples seems to have solved most of my issues.  What do you mean by "to speed up starting of the task, after configuration change state to 'commit'"?

0 Kudos
Message 3 of 3
(2,416 Views)