LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

continuous data acquisition with external digital trigger

Hello

I have E6025 Card. I want to acquire 1000 sample whenever external digital trigger happens. (About 100HZ) unfortunately, I can only get the first 1000 samples. How can I do it continuously?
I am looking for the solution in C.

Here is part of code I am using

Thanks

 

 DAQmxCreateTask("acq",&m_DAQtaskHandle);

DAQmxCreateAIVoltageChan(m_DAQtaskHandle,"Dev1/ai0","",DAQmx_Val_RSE  ,-10.0,10.0,DAQmx_Val_Volts,NULL);
DAQmxCfgSampClkTiming(m_DAQtaskHandle,"",200000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps ,1000);

DAQmxCfgDigEdgeStartTrig(m_DAQtaskHandle,"/Dev1/PFI0",DAQmx_Val_Rising);
 DAQmxRegisterEveryNSamplesEvent (m_DAQtaskHandle,DAQmx_Val_Acquired_Into_Buffer,m_spectrumSize,0,EveryNCallback,this);

 

int32  EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData)
{
  .............. 
DAQmxReadAnalogF64(taskHandle,pDAQ->m_spectrumSize,10.0,DAQmx_Val_GroupByScanNumber, data,1000,&read,NULL);
  ..............
}

0 Kudos
Message 1 of 7
(4,320 Views)
Hi knowhow,

The  best way to accomplish this application is to use the following code flow:
 
++++++++
Steps:  
1.  Create an analog input voltage channel(s)
2.  Set the rate for the sample clock. Additionally, define the sample mode to be finite and set the number of samples to be acquired per channel.
3.  Define the parameters for a Digital Start Trigger.
4.  Commit the settings into hardware by using the DAQmxTaskControl (taskHandle,  DAQmx_Val_Task_Commit). This allows for very efficient restarts
 
Loop {
   5. Start acquiring data: DAQmxStartTask
   6.  Use the DAQmxRead to measure multiple samples from N Channels on the device. Set a timeout so an error is returned if the samples are not returned in the specified time limit
   7. Stop the task: DAQmxStopTask
}
 
8. Call DAQmxClearTask to clear the Task after the acquisition is complete.
++++++++
 
I hope this helps.
Garrett H
National Instruments
0 Kudos
Message 2 of 7
(4,300 Views)

Hi, Garrett

 

Thanks for the info.

 

I didn't try DAQmxTaskControl() before and I found that overhead between stop and restart a task is about 30 ms. ( in another word, I can not response to the external trigger with frequency more than 30 HZ.)

 

I will try this DAQmxTaskControl() to see if there is any difference.

 

0 Kudos
Message 3 of 7
(4,287 Views)
Also, an even more efficient way of doing a retriggerable task is to use a counter to generate your analog input sample clock. Take a look at this example.
Garrett H
National Instruments
0 Kudos
Message 4 of 7
(4,282 Views)

Hi Garrett,

I tried to use retriggerable counter (ctro)as my AI sample clock. I use another counter (ctr1)and routed to PFI0 to emulate the
external trigger.

but I got error like "DAQmx Error: The specified resource is reserved. The operation could not be completed as specified.
Task Name: couterOutTask "

Look like I can not use two counters at same time ?

here is what I did


// use ctr1 and routed to PFI0 as external trigger

 ret = DAQmxCreateTask("trigger",&m_TriggertaskHandle);
 ret = DAQmxCreateCOPulseChanFreq(m_TriggertaskHandle,"Dev1/ctr1","",DAQmx_Val_Hz,DAQmx_Val_Low,0.0,10.0,0.5);
  ret = DAQmxCfgImplicitTiming(m_TriggertaskHandle,DAQmx_Val_ContSamps,1000);


//  configure my ctr0 as sampling clock
 char counterSource[50]="/Dev1/Ctr0InternalOutput"; //AI Sample Clock
  char counterChannel[50]="/Dev1/ctr0";    //Counter used to Generate Pulses

  DAQmxCreateTask ("couterOutTask", &counterTask); /* Create a task for analog input */
 
  // create an counter output channel named coChannel 
  DAQmxCreateCOPulseChanFreq (counterTask, counterChannel, "", DAQmx_Val_Hz,
        DAQmx_Val_Low, 0, 200000.0, // sampleing clock  rate
        0.5);
       
 // create the clock for my counter output task      
 DAQmxCfgImplicitTiming (counterTask, DAQmx_Val_FiniteSamps, 1000);


 //Configure counter output Trigger
  DAQmxCfgDigEdgeStartTrig (counterTask, "/Dev1/PFI0", DAQmx_Val_Rising);
  DAQmxSetTrigAttribute (counterTask, DAQmx_StartTrig_Retriggerable, TRUE);

Any ideas ?

Thanks in advamce !

0 Kudos
Message 5 of 7
(4,232 Views)

I followed the example (http://zone.ni.com/devzone/cda/epd/p/id/2345 ) 

Instead of busy looping to read the data I tried to use EveryNCallback  function to read the data when data is ready. But it seems that call back function only got called for the first time.

Any ideas ?

Thanks

0 Kudos
Message 6 of 7
(4,214 Views)
Hey knowhow,

I've attached an example in ANSI C that demonstrates how to use the EveryNSamples event.  I hope this helps!

Erik J
Applications Engineer
National Instruments
0 Kudos
Message 7 of 7
(4,175 Views)