From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Synchronize AI with Encoder

Hi, 

I want to synchronize three analog inputs with an encoder, so that I can relate the analog values to an encoder position (0-360 degrees). The encoder gives 360 impulses per revolution and has the z-channel.

My problem is that the encoder doesn't give me "continuous" readings, e.g., I get 1, 2, 4, 6, 7, 8, 12......degrees instead of 1, 2, 3, 4, 5,........degrees. I am using a USB-6216 for data acquisition.

Is there something wrong with my data acquisition set up, or is that a hardware problem???

 

Thanks, Thomas

Encoder Reading.png

0 Kudos
Message 1 of 8
(2,896 Views)

Your setup is incorrect. The problem you see is happening because you are reading the current value of the counter, but the encoder is looping faster than your software is. The reason it jumped from 8 to 12 is because in one loop of your software, the encoder spun 4 times. You need to set up your DAQ analog task to take an external trigger from your counter, so the hardware takes care of this all for you. You will also want to check that your USB DAQ can do this.

 

Anyways, look at examples in the example finder for acquiring data based off of an external trigger. There are lots. 

0 Kudos
Message 2 of 8
(2,887 Views)

Thanks, Greg. But I set up the sample clocks as external with the source being my encoder channel A input (PFI8). Is there another way to use the "external" sample clock?

 

Thomas

0 Kudos
Message 3 of 8
(2,876 Views)


@Thomasocholt wrote:

Thanks, Greg. But I set up the sample clocks as external with the source being my encoder channel A input (PFI8). Is there another way to use the "external" sample clock?

 

Thomas


Does the above imply it's still not working? Did you look through the example programs? Also, posting your code, or a screenshot, would aid in the troubleshooting. Finally, in cases like these I often run the sample program to see if I can get that to work. 

 

Here is a snippet of a sample program that does what you are trying to do. If you are still expecting to see your counter increment by 1 in software, it's not going to happen unless your encoder is going at relatively slow speeds, so I'd give up on that one Smiley Wink

 

0 Kudos
Message 4 of 8
(2,873 Views)

I attached a snippet with my code to my first post. Doesn't it show in the forum? Then I will repost or attach it.

 

Thomas

0 Kudos
Message 5 of 8
(2,860 Views)

Have you tried using the code I posted or looking at examples?

 

I think there are two issues here:

1. Are your analog inputs being triggered off the encoder

2. Do you still want to see the counter update on your screen every 1 encoder pulse (as I said before, this is just not going to happen and below I show why)

 

 If your encoder is spinning at 60 RPM, or 1 revolution a second, you are getting a pulse every 1/360th of a second. Your screen can't even refresh this fast, so of course you won't see it.

 

To check issues #1, the best way to test is to very slowly spin your encoder 1 revolution, and see if you get an array of 360 analog points.

0 Kudos
Message 6 of 8
(2,853 Views)

I should also add you will need a to use a start trigger based off the z line from the encder, then your clock based off of the 360 ppr pulses. Someone can probably draw up an example faster than me. Most encoder stuff I do has been

with FPGA not DAQmx

 

Attached is a sample program that ships with LabVIEW. Try running it.

 

0 Kudos
Message 7 of 8
(2,845 Views)

My encoder spins at about 10 RPM, and I get one reading from the AI for every encoder reading. I will try running the encoder very slowly, as you recommended, and see how that works, and then try the example you attached.

 

Thanks

 

Thomas

0 Kudos
Message 8 of 8
(2,830 Views)