Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

help using quadratue encoder with NIdaqmx M series

looking for sample c++ code to read position from a quadratue encoder using an M series NI daqmx.
0 Kudos
Message 1 of 7
(4,055 Views)
Hello Pvag,

You can find the shiping examples for DAQmx in the following directory

C:\Program Files\National Instruments\NI-DAQ\Examples

If you want specific examples for counter position applications refer to the following folder:

C:\Program Files\National Instruments\NI-DAQ\Examples\DAQmx ANSI C\Counter\Measure Position
C:\Program Files\National Instruments\NI-DAQ\Examples\VisualC\Ctr

Also take a look at this KnowledgeBase for more ideas:

Location of ANSI C NI-DAQmx Shipping Examples and DAQmx Library File

Another good resource is the NI DAQmx C Reference Help, this is something that can be installed when you install the DAQmx driver. It can be found from the Windows Start>>All Programs>>National Instruments>>NI-DAQ (if you don't see it, you may need to install it)

These resources should get you started.

Regards,
  Sandra T.

Applications Engineer | National Instruments
0 Kudos
Message 2 of 7
(4,044 Views)
Hi Sandra,Thanks for your reply. In fact I am using on of the example codes you mentioned (measure position).
But the program specifies that the function used to read data from the encoder needs an external clock.
It suggests to use another program (conituous pulse) to generate a pulse to clok the operation, but it doesn't
give further details as to what frequencies, duty cycles, etc to use?
So as it is the program can not read the ecnoder...needs further hacking I believe, which doesn't help much if at all
for a person new to these applications.
I am looking for a complete sample code, something that would not need further hacking to work.
An yhelp will be apprecieted.
Regards,

0 Kudos
Message 3 of 7
(4,036 Views)
Hello Pvag,

With regards to your comments, the example requires an external clock because for buffered position measurement, an external sample clock is necessary to signal when a sample should be inserted into the buffer.  This is set by the Sample Clock Source control. 

If you don't want to buffer the application and just want to make single point measurements you can remove the the timing in the code, DAQmxCfgSampClkTiming. You will need to change the DAQmxReadCounterF64, so that it reads single points of data DAQmxReadCounterScalarF64. Check the NI-DAQmx C Reference Help, you will find the paramerters and return types for this function.

You are correct, we don't have code that does exactly what you need. It is hard to generate code for all our customers' specific applications.
I understand your frustration, I hope that at least these suggestions will get you started with your application. If you have specific questions about your application, post them here. I can assist you.

Regards,
   Sandra T.

Applications Engineer | National Instruments
0 Kudos
Message 4 of 7
(4,025 Views)
Hello Sandra,
Thanks for the clarification. I removed the timing in the code and changed the DAQmxReadCounterF64 function to DAQmxReadCounterScalarF64. My code is:

DAQmxErrChk (DAQmxReadCounterScalarF64(taskHandle,10.0,&data,0));
printf("Acquired %d samples\n",data);

where I use the print to output the current encoder reading is. The problem I get now is that as I spin the motor
I only get a discrete amount of values as output, they seem to fluctuate from 0 to a positive number to negative number
back to 0 and again...I am playing around with the "pulsesPerRev" parameter in the DAQmxCreateCIAngEncoderChan function since the motor that I am testing this with is conected to a gear box, but if I take into acount the gear reduction
in selecting the pulses per revolution I still get the discrete number of output.
Any ideas as to what am I doing wrong?
I would like to get an incremental value starting at 0 and growing as the # of revolutions increases
without reseting.
Thanks in advance for your help.
Best regards,

0 Kudos
Message 5 of 7
(4,018 Views)
Hi Sandra,
I just realized my mistake. I just had to use %f instead of %d in the printf command (data is a float). The program seems to be working now.
Now I would like to store the data in a file and also plot it real time. Are there any example codes that could give me pointers as to
how to accomplish these two tasks?
Thanks for your help.

Regards,

0 Kudos
Message 6 of 7
(4,005 Views)

Hi!

There are some examples
Continuous DAQmx & Graph BufferedContinuous DAQmx & Graph Buffered

http://pagesperso-orange.fr/philippe.baucour/download.html

 

WBR, Andrew
http://spamfinish.com
0 Kudos
Message 7 of 7
(3,676 Views)