LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQmx output sluggish after a minute

Solved!
Go to solution

Hi everyone,

 

I'm running a VI with alternating analog output and analog input commands. The output is a custom waveform with a time period of 0.5 seconds.  After sending the wavefrom to the analog output, i sample data from an analog input channel for 0.05 seconds using DAQ assistant, then a repeat with the analog outptut wareform and so on.  The code is working great for several minutes, but over time the VI becomes very sluggish.  After about 4-5 minutes the output waveform period is about 5-10 seconds, the signal gets choppy and almost stops.  I suspect that there is an issue with a buffer perhaps....but that is beyond my expertise.  You will probably recognize my DAQmx output code as the standard Labview example code. 

 

I realize i'm using an older PC, but the same thing was happening to me with a new laptop.  Since everything works initially, i assume my hardware is capable of the task. 

 

Windows 2000 (pentium 4 1.8 GHz w/ 500 mB ram)

Labview 8.6

MAX 4.6

PCI-MI0-16XE-50

 

 

0 Kudos
Message 1 of 8
(3,610 Views)

Some things that I would like to comment on:

1. You should just create and close task once during your entire application run (they might be reasons why you might need to do that frequently in other applications, but it's not necessary at all in your application).

2. Try not to use express VIs; instead use native subVIs. You have done so for AO, so why not for AI? When you use DAQmx Assistant, remember it's opening and closing a task on every iteration, which is not needed at all.

 

Maybe these suggestions might not help, but it should speed up your application.

 

Also, try running both AI and AO just by themselves and see if you are getting the sames issues after a 10-min run.

Adnan Zafar
Certified LabVIEW Architect
Coleman Technologies
0 Kudos
Message 2 of 8
(3,591 Views)

Adnan, thanks for the suggestions.  By following your tips i think i found several logic errors in my programming and by removing the DAQ assistant, i think i've really upgraded my Labview understanding.  I have attached my revised code below (HeartBeat.vi) which is working well for me now.  However i've added 2 new problems that i cannot resolve.  Now that i'm not using the DAQassistant, i would like to use the SampleTime subVI to fix my loop time. Right now my loop speed varies from 560-600 ms.  I'd like to keep that more consistent.  I thought that was an easy fix, however when i attempt to add the Sampletime subVI (see HeartBeat_with_sampletime.vi), i get NaN.  Am i using this subVI wrong, no errors are reported?  Also, i would like to use my custom scales in this code, but if i attach a constant or control to the custom scale input of my Create Task subVI, i also get NaN (Heartbeat_with_customscale.vi).  I'm not receiving an error, so this is a challenge to debug. 

0 Kudos
Message 3 of 8
(3,549 Views)
Solution
Accepted by andyh

Hi andyh,

 

I wanted to clean up the code a little bit to make sure you get started on the right track.  If timing is a concern you should use HW-Timed operations whenever possible.  From what it sounds like you want to sequentially do the following:

 

    1.  Output a 500 ms waveform on AO

    2.  Acquire 50 ms of AI data

    3.  Modify waveform to be generated on next iteration according to AI result

 

 

The attached code should run at a consistent 550-560 ms per loop.  The important thing is that the AO and AI tasks are clocked.  Your waveform was 286 points so I chose an AO sample rate of 572 Hz to give a 500 ms waveform.  Once this task is comlpete, the AI task is then started.  1000 samples are clocked in at 20 kHz which will take precisely 50 ms.  There should be an extra 4-5 ms of overhead in the loop in between starting and stopping tasks.

 

EDIT:  Be sure to change the device names back to your own device (Dev6 was what you had called it originally).

 

 

If you wanted even more control of the timing you could use some sort of triggering scheme--however I'm not yet familiar enough with your application to offer any advice on this matter.

 

 

Best Regards,

John Passiak
0 Kudos
Message 4 of 8
(3,523 Views)

John,

 

Thanks so much for the revisions, i now have control over my loop rather than it controlling me.  And thanks to your proper use of error handling, i was also able to determine my problem with custom scales... must specify units!!!!  I think I'm now ready to get away from DAQ assistance entirely and convert all my data aquisition software to DAQmx.  Does anyone have a good example of efficient code structure when acquiring a large number of channels.  Do i only use one Task to collect 16+ analog input channels?  Can i input the channel names and scale names as a matrix?  I've spent some time searching for examples with no luck. Unfortunetly, most examples simply down to one channel to illustrate other issues.  I'm amazed that i can't find an example of setting up multichannel acquisition with DAQmx.

 

Thanks again.

0 Kudos
Message 5 of 8
(3,482 Views)

John,

 

Thanks so much for the revisions, i now have control over my loop rather than it controlling me.  And thanks to your proper use of error handling, i was also able to determine my problem with custom scales... must specify units!!!!  I think I'm now ready to get away from DAQ assistance entirely and convert all my data aquisition software to DAQmx.  Does anyone have a good example of efficient code structure when acquiring a large number of channels.  Do i only use one Task to collect 16+ analog input channels?  Can i input the channel names and scale names as a matrix?  I've spent some time searching for examples with no luck. Unfortunetly, most examples simply down to one channel to illustrate other issues.  I'm amazed that i can't find an example of setting up multichannel acquisition with DAQmx.

 

Thanks again.

0 Kudos
Message 6 of 8
(3,482 Views)

Hi andyh,

 

To acquire from multiple channels you can include multiple channels in the same task.  If you want them to have different channel properties (scale, range, etc.), you would need to call DAQmx Create Channel multiple times (this could be done in a loop). If the channels are to have the same properties, then you can use a single instance of DAQmx Create Channel and call something like Dev1/ai0:n to address multiple channels.

 

You'll also need to change the instance of DAQmx Read to N Channels N Samples.  This will return either a 2D array of DBL or a 1D array of waveforms, where each waveform is the data from a different channel.

 

 

The attached code shows one way to do this.

 

 

Best Regards,

John Passiak
0 Kudos
Message 7 of 8
(3,466 Views)

thank you again.

0 Kudos
Message 8 of 8
(3,464 Views)