Example Code

Measure Angular Position and Velocity with a Single Counter and No External Clock Using DAQmx

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

This example shows how to measure angular position and velocity with a single counter and a quadrature encoder.

 

Description

This example does not use buffered counter measurements and therefore does not require an external clock or another counter. This will not be as accurate as you can get with buffered counter measurements, since it is software timed, but it will do the trick in a pinch.

 

Requirements to Run
LabVIEW 8.6  (or compatible)
NI-DAQmx 9.0  (or compatible)

 

Steps

  1. Set up a Counter Input Angular Position task.
  2. Get an initial time in milliseconds before starting the while loop.
  3. Sample the count.
  4. Take the difference between the current count and the previous count, as well as calculate the time that has elapsed since the last measurement.
  5. Convert the time elapsed to seconds, and divide the change in position by the elapsed time to get velocity.
  6. Use shift registers to pass the current time and position measurements to the next loop iteration.

scfp11869.jpg

 

snippet.png

 

 

Tanya Visser
National Instruments
LabVIEW Group Manager

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

Comments
tajim
Member
Member
on

Dear TanyaV!

Thank you very much for providing a nice example! However!! Can you please help me on how to measure Angular Velocity and Angular Position while Counter Task is configured as Count Edges instead of Angular Encoder task!

Thanks!

Tajim

Tanya_V
Active Participant
Active Participant
on

Hi Tajim,

The example would work the same way except that you would want to convert the edges to degrees before doing the rest of your calculations. Depending on your end goal: either continuously knowing the position or simply knowing the change in position you will do your conversion at a different location. If you only want to know the change in position, take the value that comes out of the 1st division (representing difference in number of edges) and divide this number by the number of ticks/degrees to get the change in degrees. After this addition, the code can stay the same.

Hope this helps!

Tanya

Tanya Visser
National Instruments
LabVIEW Group Manager
Eluan
Member
Member
on

Hi,

Can you please convert this vi to labview 8.6

Tanya_V
Active Participant
Active Participant
on

I've posted the file in LabVIEW 8.6

Tanya Visser
National Instruments
LabVIEW Group Manager
hesham92
Member
Member
on

how can I Measure Angular Position and Velocity with by myrio

Tanya_V
Active Participant
Active Participant
on

Hi hesham92,

I'm not overly familiar with working with the myRIO. I would recommend posting your question to the academic hardware discussion forum.

Take care!

Tanya Visser
National Instruments
LabVIEW Group Manager
hesham92
Member
Member
on

thank you ,  I will do that

Hamed26
Member
Member
on

Hi, unfortunately when I run this file, nothing appears on the position and angular velocity waveform graph, but the only thing that I can see is the postion which appears on a numeric indicators beside the position graph. I don't really know what is the problem. please help me.

Tanya_V
Active Participant
Active Participant
on

Hi Hamed26,

Have you turned on highlight execution to see what data is making it to your graphs? Using probes and the debugging tools should give you more information about what is going wrong in your case.

Tanya

Tanya Visser
National Instruments
LabVIEW Group Manager
Hamed26
Member
Member
on

Thanks Tanya for your response. I will check that.
Actually I am using the same file you uploaded here, but I cannot see any signals (velocity or position), interesting point is that I can see them in the numeric indicator beside those graphs and they clearly show me changes in values, but there is no graph, I mean graphs are showing nothing. It seems that it only holds one data at a time, maybe I need to check the settings again.
Should that counter take 1 sample, or N samples ?

Tanya_V
Active Participant
Active Participant
on

It's looks like position and velocity should be charts, not graphs. Can you double check that they are still charts for you?

Tanya Visser
National Instruments
LabVIEW Group Manager
Hamed26
Member
Member
on

Thanks, I managed to fix the problem. How can I change the sampling rate and the numbers of samples I am taking? for example if I want a 1k Hz sampling rate, where should I define it?

Tanya_V
Active Participant
Active Participant
on

This is a software timed example, which means that the sampling rate is controlled by the loop rate. To increase the sampling frequency you'll want to adjust the input to the "Wait Until Next Millisecond Multiple" node. And you'll always want to only be taking one sample per loop iteration.

If, however, your device supports buffered counter measurements, this probably isn't the example you'll want to use. You can get much more precise timing using buffered counter measurements.

Tanya Visser
National Instruments
LabVIEW Group Manager
Hamed26
Member
Member
on

Thanks for your answer, Actually I have a NI cdaq 9178 chassis with 8 slots for different cards and have six NI-9215 cards and one NI-9401 and also one NI-9237 on it. I want to measure 6 voltages and 6 currents with those NI-9215 cards and one force measurent with NI-9237 card and one Angular velocity meausrement with NI-9401 cards. All of this signals should be measured at the same time, with the same sampling rate and same number of data points and time interval becasue I have to fed them into my estimation algorithms which really needs data matrix with the same dimentions for all of the signals.

Fot six currents and six voltages it is easy to synchronize them with the same sampling rate and data points by using a DaqAssistant block, and I can acquire the data for others tasks like load cell data and encoder at the same time when I Run my labview file, but I cannot get the same sampling rate and data point for all of them while I really need to do this.   

Tanya_V
Active Participant
Active Participant
on

We are quickly getting out of my area of expertise. I would recommend posting your synchronization question to the Multifunction DAQ forum. You'll get a better answer there.

Tanya Visser
National Instruments
LabVIEW Group Manager
Hamed26
Member
Member
on

Thanks Tanya_V

If I want to take more than one sample per each loop, and change the counter settings from 1channel 1sample to 1channel Nsample, how should can I change the shift registers for the loop?

What I really want to ask is that, is there any way that I can make some changes in this VI to make it work for 1channel Nsample data acquisition?