Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

USB-6008 Digital Triggering

I am using the NI USB-6008 and NIDAQmx to acquire data from a laser source.  I want to use the digital triggering functionality with PFI0 but have been unable to get it to work right.  When using the Test Panels... functionality of Measurement & Automation Explorer the digital counter is able to detect the edges correctly.  Because of this I don't think that the problem has to do with whether or not the incoming signal adheres to TTL specs.  Below is code I copied from a program I wrote to test this functionality.  It sets up the task and then goes through a loop taking data.  In the loop the data acquisition begins with the trigger.  I manually send the signal to trigger the task start and then press enter to continue with the program.  The task never triggers causing the Read to timeout with status code -200284.  Please let me know if you have any ideas.

 

Thanks!

 

Matt

 

int _tmain(int argc, _TCHAR* argv[])
{
int32 error = 0;
TaskHandle taskHandle = 0;
int32 read;
float64 data[1000];
char errBuff[2048]={'\0'};

DAQmxErrChk (DAQmxCreateTask("", &taskHandle));

DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai0", "",
DAQmx_Val_Cfg_Default, -2, 2, DAQmx_Val_Volts, NULL));

DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle, NULL, 1000, DAQmx_Val_Rising,
DAQmx_Val_FiniteSamps, 1000));

//DAQmxErrChk(DAQmxSetReadOverWrite(taskHandle, DAQmx_Val_OverwriteUnreadSamps));

int i = 0;
cout << "Beginning data acquisition loop.\n";
while(1)
{
//DAQmxErrChk(DAQmxStartTask(taskHandle));
DAQmxErrChk(DAQmxCfgDigEdgeStartTrig( taskHandle, "/Dev1/PFI0", DAQmx_Val_Rising));

cout << "Send trigger then press enter.\n";
cin.ignore();
Sleep(1000);

cout << "Read data.\n";
DAQmxErrChk(DAQmxReadAnalogF64(taskHandle, 1000, 5, DAQmx_Val_GroupByChannel,
data, 1000, &read, NULL));

DAQmxErrChk(DAQmxStopTask(taskHandle));

++i;
cout << "Loop number " << i << "complete.\n";
}

Error:
if (DAQmxFailed(error))
DAQmxGetExtendedErrorInfo(errBuff,2048);

if (taskHandle != 0)
{
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
}

if (DAQmxFailed(error))
printf("DAQmx Error: %s\n",errBuff);

return 0;
}

0 Kudos
Message 1 of 3
(3,142 Views)

Hey Matt,

 

I was thinking about the project the other day on my way back to Austin.  The only way you are going to get micrometer resolution is to hvae some sort of encoder feedback on the motor.  Even if your timing were perfect or near perfect, there are still a few uncertainties you would be unable to get rid of.  One would be the operating system jitter, which would mean a delay of anywhere between 1 and 20 ms between commands like the ones you're talking about.  Another uncertainty would be the fact that stepper motors can slip and miss a step occasionally. Each of these isn't a huge deal if you're talking what you can see with the naked eye, but when you start talking micrometers, it could become a pretty big deal.

 

If there's no time in the scope of this year's project to do that, you can likely still get some resolution, depending on the accuracy of the motors and the stage.  

 

As far as your code, it looks like you set up the trigger but don't actually start the task after that.  It should follow the pattern Create, Configure (timing, triggering, etc), Start, Read, Stop(if desired, then you can restart) and Clear.  Have you seen the examples?  It looks like you might have, but there are a set of examples that can usually be found here: C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples.   I think a specific one for this case might be: C:\Users\Public\Documents\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage\Acq-Int Clk-Dig Start Ref

 

Hope this helps.  Let me know if there's more I can do.

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

Thanks Andrew! 

That was the problem.  I was thinking that the DAQmxCfgDigEdgeStartTrig call would have it start waiting for the trigger and start the task from that.

 

0 Kudos
Message 3 of 3
(3,090 Views)