Example Code

Angular Position and Velocity of the Encoder with One Counter

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Hardware

  • Data Acquisition (DAQ)

    Software

  • LabVIEW

    Driver

  • NI DAQmx

Code and Documents

Attachment

Overview
The example is to demonstrate how to acquire the angular position and velocity of an encoder with one counter

Description:
This VI would show how to define the counter input of a pin and utilize it as the hardware for the acquisition of the angular position and the velocity. It also somewhat shows how to synchronize the the counters by wiring the error cluster of the function.

Steps to Implement or Execute Code:
To implement this example:

  1. Set the sampling rate and samples to read
  2. Run the VI
  3. (Optional) Turn on the Highlight Execution to see the flow of the VI

To execute this example:

  1. Install the required software.
  2. Connect the DAQ hardware that supports the Counter and AI features
  3. Confirm the connection with the MAX with TestPanel
  4. Open the VI and refer the Implement Steps

Requirements
Software
LabVIEW 2012 or compatible
NI-DAQmx 9.0 or compatible

Hardware
cDAQ with C series Counter and Analog Input Module

 

fp.PNG

 

bd.PNG

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

---

Peter Flores
Applications Engineer

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
ssingh1
Member
Member
on

Thanks for your posting. Can you please elaborate a little on how dummy AI task is used to synch two counters to the same sample clock?

Also please post a LV 8.6 or 8.2 version, if possible.

pflores
NI Employee (retired)
on

The AI task is used to generate a Sample Clock that can be used by the counter tasks. Since I am setting up a buffered coutner task, it needs a sample signal from somewhere else. The most popular options for generating this clock signal are from another counter, an AI task, or an AO task. Since I am already using my only two counters on the board, I chose to create an AI task for the sole purpose of generating a clock signal to be used by the two coutners. Both counters are sharing the same clock signal. This gives then a sample clock that is required and ensures that the counter readings are synched together.

Hope this helps. Here is another example that may be better documented.

http://zone.ni.com/devzone/cda/epd/p/id/6081

---

Peter Flores
Applications Engineer
ssingh1
Member
Member
on

Thanks for the explanation and the link.

cuem2k
Member
Member
on

Could you please explain more clearly how to use the sawtooth generation function to measure the velocity. Why do you use the initial phase at 180 deg with the off set 100, but not 0 deg phase with zero offset? What is the frequency of the sawtooth generation function affect the velocity measurement? I use your VI to mesaure the velocity of the DC motor throught 2500 ppr encoder, but the velocity is oscilated. It is not constant eventhought i supply a constant voltage to the motor. How can i measure angular velocity accuracely?

Thanks in advanced.

CueOminousMusic
Member
Member
on

For reference, error handling is disabled in this VI.  If you try to use the code in another VI without turning off automatic error handling or clearing the error (-200077 I believe), you might run into an issue with the DAQmx Timing VIs on the encoder tasks.  It still works if you ignore that though.

Hamed26
Member
Member
on

Would you please upload the modified file with just the bottom row task? I only need one encoder measurement and I deletd the the first two tasks but there were some errors, in relation to mismatch between data source and destination.