LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

quadrature encoder synchronize sample

Solved!
Go to solution
Using a USB-6251 to measure a quadrature encoder, i would like to determine the angle that an external discrete changes state.  I tried connecting the discrete to a DIO input and using CVI PC code to read the encoder angle when the change of state occurs.  The problem is the latency of the PC code which adds up to 4 degrees (with variability) to the measured angle.  An ideal solution might be to trigger a measurement into a buffer within the USB-6251 when the discrete changes state, then read the value into the PC at a later time.  Is this possible with the USB-6251?
0 Kudos
Message 1 of 4
(3,659 Views)

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,

Adam
Academic Product Manager
National Intruments
0 Kudos
Message 2 of 4
(3,630 Views)
Solution
Accepted by topic author CreviceDweller

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);

0 Kudos
Message 3 of 4
(3,617 Views)

Hi CreviceDweller,

 

Glad to hear you got everything working, thanks for posting the solution.

 

Best,

Adam
Academic Product Manager
National Intruments
0 Kudos
Message 4 of 4
(3,601 Views)