LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Data Acquisition Advice

Hey All,

Upon becoming more with this environment I had afew questions I was wondering if you would be able to answer.

- What is the difference between the library and instruments
    I was trying to read in an analog waveform and found two methods.  One the old (labview way) where I define a task and start, read, stop it.  The other using the instrument file "daqmxio.fp"  where I use the function (NIDAQ_newchannelAI). Is there any difference?

- How would I implement a double buffering scheme in CVI?
  Does the DAQmx do this for me or would I have to implement it through code somehow?

Cheers,
tdk
0 Kudos
Message 1 of 13
(5,060 Views)
Hi tdk,

1. You should definitely use the method of Creating, Configuring, Starting, Reading and Stopping a task.  This is typically the best and easiest way to accomplish your measurements and is the way that you will see employed in the DAQmx examples.
NI-DAQmx Shipping Examples in LabWindows/CVI 7.0

2. It's all handled by the drivers, so if you just set up your measurement as in the examples, then all of the buffering will work correctly with no additional work on your part.
0 Kudos
Message 2 of 13
(5,034 Views)
Hi Otis,

Thanks for the reply.  However, I think I may need some more help if you don't mind.

Background
First, I'll discribe what I'm trying to do.  I'm using CVI to control a laser modulator, and I'm using the NI 6024E DAQ card in tandem with a GPIB card.  We were using a high speed digitizer, which didn't work because we have to go to low frequency (~0.01 Hz).  The experiment is simple.  I am monitoring two signals: (1) Input to Modulator (control), and (2) Output of Detector.   For the control, I'm just doing a sign sweep from 0.01 Hz to ~2000Hz.  At each frequency I dwell for so many loops so that I can get a good average of signal (2) which is on the order of millivolts. 

CVI implementation
Right now I'm just working on reading in signal (2) at the extremes, low(0.01Hz) and high(2000Hz) frequencies.  To simulate signal (2) I'm just using a func generator.  Anyways, I built the CVI using example "ContAcq-IntClk.prj" since I want to use the clock on the DAQ board for the timing.  Since I am using this pre-built example, I assume that I am creating the task correctly (ie. creat, start, read, stop, clear).  The only modifications I made to the example were: Instead of looping continuously, I specify how many loops from the GUI (~500); After PlotY, I average the signal with the array from the previous loop (using a temporary array called data_temp[]).  Note, this works for freqencies that aren't near the extreme.  However, I get problems at the extremes.

Extremes
At 2000 Hz, I want my sample rate to be ~10 kS/s and store 1000 S.  This corresponds to ~ 4 periods.  However, when I run the code at these settings the execution returns an error "DAQmxReadAnalogF64 is trying to read data that is no longer in the buffer."  I need to fix this.
At 0.01 Hz, I sample slow ~10 S/s and store 100S.  However when I run this code it says that I'm sampling too slowly.  I was looking at the specs for the 6024E and it didn't list a minimum sampling rate so I thought I could take it as low as I wanted.

Sorry for the length question, but if you can shed any insight plz do.

Thanks,
tdk
0 Kudos
Message 3 of 13
(5,020 Views)

Hi tdk,

Ah, I see that the problem is not really in how you are acquiring the data, but the rates at which you're acquiring.  First off, the typical timeout for a Read function is 10s, so if you are reading 100 Samples at 10Samples/s, that means you'll likely get the timeout error.  Your options are to increase the timeout or to try reading at a faster rate.

The 2nd problem appears to be when you are running at 2000 Hz, you want to read 10kS/s of data and log 1kS to disk at a time.  This means 10 reads/s; however, it looks like the buffer is overflowing, so are you really returning the data that quickly?  It could be that the problem is that the logging to disk is taking longer than you think, which means that a buffer is overflowing and then you've got a problem.

My biggest question is how are you trying to change the sampling rate and the output signal?  The best way I could think of would be to set up a waveform in your AO buffer, then to use a counter to generate a variable rate pulse train.  You can also use that pulse train for your analog input and viola; you've got changing IO rates on both your AI and AO.  Just make sure that you're not reading slower than once per 10s and not faster than about 10 times/s.

The other option would be to keep stopping and restarting the task.  This method could mean that you have breaks in your data though, so it's not as ideal.  The first method though means that you have to have a linear relationship between the AI and AO.  If you were using LabVIEW I could whip up a few examples for you right away, but I'm not as quick with CVI, maybe if you let me know more about how you want your measurements to be done I could make up a bit of pseudo-code for you.

0 Kudos
Message 4 of 13
(4,994 Views)
Hi Otis,

Thanks of the reply.  Here are afew more thoughts and questions:

>>The 2nd problem appears to be when you are running at 2000 Hz, you want to read 10kS/s of data and log 1kS to disk at a time.  This means >>10 reads/s; however, it looks like the buffer is overflowing, so are you really returning the data that quickly?  It could be that the problem is >>that the logging to disk is taking longer than you think, which means that a buffer is overflowing and then you've got a problem.

 - If I'm reading 10kS/s and logging 1kS, doesn't that mean I'm just reading for 1/10th sec.  I don't quite understand what you mean by 10 reads/sec.  I figured the buffer was not overflowing but that DAQmxReadAnalog was trying to read data that had already passed.  Is my understanding correct?  If it is, then that means the program isn't executing fast enough to sample data (which seems weird since these settings don't work for the example, ContAnalog-IntClk.prj, which only plots data[] after the read).  I would think the computer and card would be capable to handle this since I'm running off a PIII and I'm only sampling at 10kS/s.  Note: I am not logging the data in the (for) loop. I output the sampled data after N averages.     

>>My biggest question is how are you trying to change the sampling rate and the output signal?  The best way I could think of would be to set >>up a waveform in your AO buffer, then to use a counter to generate a variable rate pulse train.  You can also use that pulse train for your >>analog input and viola; you've got changing IO rates on both your AI and AO.  Just make sure that you're not reading slower than once per >>10s and not faster than about 10 times/s.

- As for now, I have been changing the sample rate and output signal manually, using a GUI and func gen.  Later this will be done programaticallly, with the use of the GPIB NI-488.2 card (will be controlling the func gen).   If I'm doing it this way it seems that it doesn't matter how I'm setting up the AO.  The AI would be independent and I would still have to be able to average the waveforms  at the settings specified before.

>>The other option would be to keep stopping and restarting the task.  This method could mean that you have breaks in your data though, so >>it's not as ideal.  The first method though means that you have to have a linear relationship between the AI and AO.  If you were using >>LabVIEW I could whip up a few examples for you right away, but I'm not as quick with CVI, maybe if you let me know more about how you >>want your measurements to be done I could make up a bit of pseudo-code for you.

-  Yeah breaks in the data would definitely be problematic since I'm trying to average the waveforms.  I suppose I could still get it to work by triggering it somehow but that could be more complicated than I'd like. 

Thanks, and let me know if you have any ideas - tdk
0 Kudos
Message 5 of 13
(4,978 Views)

Hi tdk,

Okay, let's break up that last reply into 3 parts and answer each 1 accordingly:

  1. It seems pretty weird that not even the example will run.  Can you go into MAX (Start > All Programs > National Instruments), and go to My System > Devices and Interfaces > NI DAQmx Devices > Your Device and right-click to reset the board.  When you're done doing that, right-click on the board and open a Test Panel.  Try running the Analog Input in Continuous Mode at a rate of 10kS/s and reading 1kS at a time.  If this works for you, try running your example again.  Both should work in essentially the same manner and I'd like to make sure that the board is working as expected in MAX before diving into the code.

  2. Okay, so you're changing the frequency by updating the information with an external instrument, so chances are it won't be a completely smooth transition.  Most likely more of a stepwise response in frequency change.  That should be find for the method that you wanted to employ for acquisition.  If your circumstances were different I knew a trick that might be cool, but you won't need it in this case.

  3. Creating new tasks is really going to be the only way to go on this one since you want to change the sampling rates and read sizes and other parameters.  You have to stop the task, create a new one and restart it with the new characteristics.

I know this is a lot to handle.  I'm thinking that it might benefit everybody if you could call in to NI (866-ASK-MYNI) for support.  It doesn't sound like the overall system will be too complicated, it sounds like the biggest problem right now is making sure that both sides of this post understand what is going on and the best way to tackle the issue.  If you have plenty of time, then we can keep shooting post back and forth, but it might behoove you to speak directly with one of our engineers on this one.

Regards,

Message 6 of 13
(4,949 Views)
Hi Otis,

Thanks for the advice, I will call NI soon if I continue to have problems.

I reset the board and tried again but it didn't work.  It is strange that it DOES work from the test panel but not from CVI.  But I imagine the test panel was built using labview.

As a general note, could you tell me how you might go about acquiring a waveform and averaging it in CVI?  Does it make sense to read the data in an array and average the arrays.  Of course I was working with ContAcq-IntClk.prj as a starting point but if you know of a better way to read data I'm all ears.  (By the way, I can get the code to work if I call DAQmxGetReadAttribute() prior to DAQmxReadAnalogF64() and read ALL_SAMPLES in the buffer rather than a specific number, sampsPerChan).  However this method, gives me limited control in how many samples I want to record (ie. I won't have a fixed size of array but rather one that deviates from it.  Thanks.

Cheers,
tdk
0 Kudos
Message 7 of 13
(4,930 Views)

The best way to acquire and average would be to acquire an array of data and then take the average of that array.  It seems weird that it's not letting you read a defined number of scans.  Out of curiosity if you read the available scans are the samples being returned about what you would expect considering your sampling rate?

This definitely has something to do with either CVI or the way it's being programmed.  Just in case maybe your project got corrupted I'm going to include the example that's on my machine as an attachment.
Attachment found here: C:\Program Files\National Instruments\CVI80\samples\DAQmx\Analog In\Measure Voltage\Cont Acq-Int Clk

Message 8 of 13
(4,907 Views)
Hello Otis
 
 
0 Kudos
Message 9 of 13
(4,862 Views)
Hello otis
I am trying to generate two analog signals simultaneously to control a linear stepper motor using Labwindows/CVI  7.0 software in conjunction with DAQ card PCI-6024E for all my experiments. I have created two global Daqmx channels in NI-Max (one for AO and one for AI - Please also state if its better to add tasks in Max or in project). I added Daqmx task for analog output voltage in Labwindows-CVI. I could not proceed as i get link errors.

I am also using ContAcq-IntClk as my example program but could not go past the link error for debugging stage.

I Have been reading through your replies in the Labwindows/CVI section and seem to get an idea of what could have caused the link errors as follows,
>> 2 Project link errors 
Multiply defined symbol '_WinMain@16' in modules 'DAQTaskInProject.c' and 'ContGen-IntClk.c'.

Multiply defined symbol '_WinMain@16' in modules 'ContGen-IntClk_Fn.c' and 'ContGen-IntClk.c'.

I checked for function declarations in the .h files and made sure not to initialise values there. But i got lost in the process and decided to write to
you because most of the files (from example 'ContGen-IntClk' ) are software generated ones.

I think the problem is with the error handling function. I see the need for it to be declared global using #define as the scope of it has to be across all
function in the programs. But when i got around the problem by first declaring it in .h file with int type as argument along with putting the code for
errorchecking in the .c file i get a compiler error as "undefined label Error" strangely.
I must agree iam not an expert user of LabWindowsCVI . Please advise if there is any initial setup or changing build/environment options to be performed before i run any CVI programs. And again please brief about Instrument files? Do i have to define an instrument file for my DAQ card before i proceed. When do i have to define Instrument I/O  task? I take it this menu item is different from Creating Daqmx task. Iam attaching project files if it helps to answer my request better. Any help in this query is much appreciated.
 
Many thanks in advance
Laksh.
0 Kudos
Message 10 of 13
(4,862 Views)