05-03-2010 12:08 PM
Solved! Go to Solution.
05-04-2010 04:49 PM
Hello CreviceDweller,
I would suggest using a Counter Input channel for this application. Typically an encoder has a set number of ticks per revolution, and you can use a Counter Input Count Edges task to bring in these pulses and then process the angle in your program, according to the number of ticks counted. There are DAQmx C shipping examples that will work with CVI. These examples are located by navigating to Start»All Programs»National Insruments»NI-DAQ»Text-based Code Support.
Best,
05-05-2010 09:04 AM
Thanks Adam,
I solved my problem using that idea with the addition of using buffered sampling and the discrete as a trigger. Committing the task to hardware also seems like a good idea but may not be required.
The setup code looks like this:
// Start an Encoder channel on counter 1 to monitor the angle of label detector PNP edges
status = DAQmxCreateTask("PNP Rising Edges",&pnpTaskHandle);
strcpy (chanString, devName);
strcat (chanString, "/ctr1");
status = DAQmxCreateCIAngEncoderChan (pnpTaskHandle, chanString, "", DAQmx_Val_X4, 1, 0, DAQmx_Val_AHighBHigh,
DAQmx_Val_Degrees, 4096, 0.0, "");
sprintf (chanString, "/");
strcat (chanString, devName);
strcat (chanString, "/PFI1");
status = DAQmxCfgSampClkTiming (pnpTaskHandle, chanString, 1000000, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 10
0000);
if (status < 0)
DAQmxGetErrorString (status, errString, 1000);
DAQmxTaskControl (pnpTaskHandle, DAQmx_Val_Task_Commit);
// Start the task
status = DAQmxStartTask(pnpTaskHandle);
angleTaskStarted = 1;
Reading the value looks like this:
status = DAQmxReadCounterF64 (npnTaskHandle, DAQmx_Val_Auto, 0, npnEdgeArray, 1000, &npnSampsRead, 0);
05-05-2010 01:48 PM
Hi CreviceDweller,
Glad to hear you got everything working, thanks for posting the solution.
Best,