LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

measure phase difference between two pulse trains or an encoder A-B phases

I want to measure the phase difference or shift between the lines A-B of an incremental encoder to check that is 90º as a test to another purpose. I've tried with "Extract single tone measurements.vi" and other vi's like this but it doesn't work. Please, could you help me? Thank you very much.
0 Kudos
Message 1 of 2
(3,592 Views)
Three ideas:

1... Use CTR GROUP CONFIG to set up two counters.
Use CTR MODE CONFIG to set up MODE 3 (Count Continuously), using an internal clock timebase.
Use CTR Control to start the counters.

Periodically:
Call CTR BUFFER READ to check the backlog of readings waiting.
If backlog > 0, call CTR BUFFER READ to read that many readings
The readings are basically timestamps of the transitions of A and B signals. Figure the phase difference by where the B transition is, in relation to two consecutive A transitions.

You need a really clean signal to get past NI's persnickety front end circuit. 0 to 5 V CMOS is OK, TTL won't do it reliably.

2... Run the A and B signals into two channels of a DAQ card (or reduce the voltage and wire into the audio input port if you have stereo input).
Record enough samples to get at least one cycle of each encoder line (A and B).
Perform an FFT on each channel.
Pick out the highest magnitude peak from the spectrum (will be fundamental frequency).
Pick out the phase corresponding to that peak (for each channel)
Subtract the two phase numbers. Remember that each phase is relative to the start of the recorded block, and so doesn't mean anything by itself (unless you synchronize the trigger start).

3... Run the A and B signals into two channels of a DAQ card (or reduce the voltage and wire into the audio input port if you have stereo input).
Record enough samples to get at least one cycle of each encoder line (A and B).
Search thru the data for two 0-->1 transitions on the A channel. Remember the sample number where they occurred.
Search thru the data for a single 0-->1 transition on the B channel. Use the sample number of the B transition as a proportion of the interval between the two A transitions.

My experience with optical quadrature encoders is that they vary quite a bit. One manufacturer made a cheap model that varied +/- 60 degrees from the 90 degree ideal, as it went thru one revolution. Another mfgr made one that varied less than 5 degrees.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 2 of 2
(3,592 Views)