简体   繁体   中英

How to avoid a Data Missed event in matlab when doing data acquisition from an NI board?

I am receiving DataMissed event(s) in matlab when acquiring waveform data (2 channels) and an analog input trigger (set up in pretrigger mode - negative delay value).

Here is the code:

sampleRate = 500000;
pretrigger = 8;
trigger_value = 0.6;
ai = analoginput('nidaq','Dev1');
ch = addchannel(ai,0:channels);
set(ai,'SampleRate',sampleRate);
requiredSamples = floor(pretrigger*sampleRate);
set(ai,'SamplesPerTrigger',requiredSamples);

%triggering
set(ai,'TriggerChannel',ch(channels+1));
set(ai,'TriggerType','Software');
set(ai,'TriggerCondition','Rising');
set(ai,'TriggerConditionValue',trigger_value);
set(ai,'TriggerDelay',-pretrigger);
set(ai, 'TriggerRepeat', 0);

set(ai,'LoggingMode','Disk');
set(ai,'LogToDiskMode','Index');
set(ai,'LogFileName',[filename '_01']);

waitTime = pretrigger * 1.1 + 0.5;

for k = 1:100
  start(ai);
  CurrentFile = get(ai,'LogFileName');
  disp(['Acquiring for ' CurrentFile]);
  while strcmp((get(ai, 'Running')), 'On')
    pause(1);
  end
  wait(ai,waitTime);
  showdaqevents(ai)
  disp(['Triggered ' CurrentFile]);
  while strcmp((get(ai, 'Logging')), 'On'); end;
  disp(['Saved ' CurrentFile]);
end

stop(ai);
delete(ai);
clear ai;

When running this code, I get Data Missed Events after the trigger event is received (using the showdaqevents(ai)). However, the Data Missed Events have a sample number of NA, so I'm not completely certain that they are coming after the trigger.

Here's an example of the showdaqevents output:

1 Start               ( 14:55:35, 0 )
2 Trigger#1           ( 14:56:02, 0 )      Channel: [3]
3 DataMissed          (    N/A  , 13959168 ) 
4 DataMissed          (    N/A  , 13959168 ) 
5 DataMissed          (    N/A  , 13959168 ) 
6 DataMissed          (    N/A  , 13959168 ) 
7 DataMissed          (    N/A  , 13959168 ) 
8 DataMissed          (    N/A  , 13959168 ) 
9 Stop                ( 14:56:03, 5 )

Looking into Data Missed Events in the matlab documentation , there are two explanations given:

  • The engine cannot keep up with the rate of acquisition.
  • The driver wrote new data into the hardware's FIFO buffer before the previously acquired data was read. You can usually avoid this problem by increasing the size of the memory block with the BufferingConfig property.

I've attempted to increase the memory available with the daqmem command, but I haven't found that to work. 500000 samples/second, 3 channels is about 90 MB total per trigger, and daqmem reports having over 360MB free (though the buffermode is set to Auto). I am wondering if I need to periodically call getdata(ai) in the while loop to clear the memory. The other possibility is that I am running at too high of a sample rate for the system?

The hardware:

  • Dual core CPU (Athlon X2 3200), 4GB of RAM, 500 GB SATA hard disk
  • NI PCI-6122

I should mention that the likelihood of getting a DataMissed event goes up the longer (in time) I let the system acquire before pressing the trigger.

Is there a problem with my data acquisition code (I'm most uncertain about having the pause in there in the middle of the acquisition)? The hardware? Is it something not to worry about? Is Visual Studio better for dealing with NI boards?

I don't have an answer, but I can tell you some of the steps I might use to debug. Noting the answers to these things in your original Q might also give the nidaqmx users on SO extra clues about your problem.

First, do you ever miss samples when using only a single trigger, rather than triggering 100 times?

Do you miss samples at lower acquisition rates?

How about if you change parameters to keep only pre-trigger samps? Only post-trigger samps?

Is logging the issue? If you forego logging to file and instead just read the data into a matlab variable as in this example from data acquisition toolbox docs, does that change anything?

How frequently are you missing samples? Once per run of 100 triggers? 100 times per 100-trigger run? Or kind of stochastically?

Wish I could offer more help with the code - I always use nidaqmx c api under linux and my application is a continuously-running thing, so I'm not familiar with the matlab toolbox or triggering.

FYI to you and the moderators - I think I may be breaking this rule: "Please make sure you answer the question; this is a Q&A site, not a discussion forum." I'm open to reprimand and correction in the comments section - thanks for letting me know the appropriate usage of the site!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM