Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Simulate quadrature encoder output: two pulse trains w 90 degree phase shift with M Series

Hi all,
I'm trying to simulate the output of a quadrature encoderwith an M Series (USB-6210) in LabVIEW. Naturally I found that I couldn't do atrigger delay on one counter output as I supposedly can do with a 660xboard. However, I have found two resources that say I can generate twopulse trains of the same frequency with one train phase shifted by 90degrees:
http://digital.ni.com/public.nsf/allkb/26CCE4F74DACFD1886256DCF006B011A
http://forums.ni.com/ni/board/message?board.id=40&message.id=908&query.id=101879

Themain idea of both of these is that you generate 2 pulse trains of thesame frequency, one from FreqOut and the other from Ctr0. Then youapply a single pulse from Ctr1 which will gate Ctr0 and offset it by 90degrees.

Now both of those refer to E Series, but I've simulated an E series and I can't get that one to work either.

Butbefore I get to implementation, I'm skeptical about this solution ingeneral because it seems that it will only phase shift the first pulseof one of the pulse trains, whereas all the other pulses with be inphase with the other pulse train. I've used the power of my keyboard tocreate pulse trains below. You will need to supply the power of yourimagination. First are the two pulse trains ungated and in phase withthe same frequency:

Pulse Train 1 (freqout)     ____----____----____----____----____----____----

Pulse Train 2 (ctr0)         ____----____----____----____----____----____----

Now we will see the Gate from ctr1 and the result when it is applied to Pulse Train 2 (ctr0) below

Gate (ctr1)                    ______--------------------------------------------

Resulting Pulse Trains:

Pulse Train 1 (freqout)     ____----____----____----____----____----____----
Pulse Train 2 (ctr0)         ______--____----____----____----____----____----

AmI thinking incorrectly here? The first pulse in pulse train 2 willindeed be shifted by 90 degrees, but the rest won't, which certainlywon't help in simulating an encoder output which should look like this:
Phase A        ____----____----____----____----____----____----
Phase B        --____----____----____----____----____----____----

I've looked around but I can't see any cases where anybody's actuallyimplemented this and shown some code. Has anybody tried this?
I would welcome any feedback on the above, especially if somebody has some LabVIEW code.
Thank you!

0 Kudos
Message 1 of 5
(5,231 Views)

Hi JamesDean,

             Because this can be done with an E-series, it can be done with an M-series, because essentially all you need is 2 counters and a Freqout line, which your device has.

 

Regarding your fears that this method will only affect the first pulse, and then the other pulses will be in phase:  the frequencies of the counters are set to be the same, so the only thing that the Gate pulse does is make the second pulse train start later.  This way, you're not cutting in half one of the pulses (as your picture shows), but rather you are starting the first pulse of the second counter later.  

 

The links that you posted are some of the best resources we have. Although someone is bound to have done this before, we unfortunately have no record or code for it.  I believe that you could modify the example Gen Dig Pulse Train-Dig Start.vi to include your Freqout and other counter.  You would need to somehow trigger your second counter off of a digital pulse from your Gate, and then set your two counters to use the same frequency.  I've also been playing with this code, but don't have anything yet that works or is worth posting- if I get this worked out though, I'll be sure to post the code for you on the new NI community . I encourage you to try it out, and post to the community as well if you get something working.  Have a good one!

aNItaB

Applications Engineer

 

 

0 Kudos
Message 2 of 5
(5,212 Views)

Hi JamesDean,

I have successfully programmed what you are asking for. The wording of the documents you pointed to are a bit confusing. Ctr0 will actually be triggered off the pulse coming from Ctr1, it will not be gated, which is the situation you described.

 

I'll clean up my code and submit it to the Developer Zone Community. I won't be able to do it until early next week as I will be out of town.

 

Hopefully that will help you out!

 

Brian Spears

NI Certified LabVIEW Developer

NI Certified Professional Instructor

Message 3 of 5
(5,199 Views)
Hello,
I've attached "Quad Encoder Sim.vi" below. I've actually hooked the code up to some devices and checked it again and it looks like it doesn't behave exactly as I expect it would, though it does meet most of my expectations. What is does do is create two pulse trains of the same frequency on channel A and B, where one of them is offset by 90 degrees, which is the output of the encoder that it's intended to mimic. However, the problem is that it's not outputting the frequency that I think it should be outputting. I've set it to divide down the 100kHz timebase by 16, which should give a frequency of 6250 Hz. But instead, I'm seeing a pulse train on each channel (A and B) of 12500 Hz.

I tested it two ways. I first used the shipping example "Meas Angular Position-Buffered-Cont-Ext Clk.vi" and modified it to create "Measure Encoder Frequency.vi" attached below. I added on to the example program to give me the frequency by creating a simple 1Hz pulse train with the other counter and using that to latch the measurements. I used a 6210, and all the pins and default values in the VI are correct for that device. The measured "encoder frequency" gave me an output of 1.38 MHz, which is obviously far too large, as I'm expecting to see 62500 Hz from the simulated encoder.

I decided to make "Measure Encoder Frequency.vi" simpler and modified it to create "Measure pulse train Frequency.vi" attached below (so that it's more similar to the installed example "Count Digital Events-Buffered-Continuous-Ext Clk.vi" ) The idea is just to measure the frequency of one of the pulse trains coming from the simulated encoder. I simply read the frequency of one of the pulse trains coming from "Quad Encoder Sim.vi" by using the same technique of creating a 1 Hz pulse train with the other counter on the device and latching the measurement. When I do that, I get 12500 Hz for each of the pulse trains as I mentioned above, even though I'm expecting 6250 Hz.

I've played around with all the values of the controls and indicators for my VIs. The only ones that change the final values I'm getting are the decoding type and the pulses per revolution which both make sense. I've left these both at X1 and 1 respectively (since the encoder is simulated and essentially only has 1 pulse per revolution). The connections I made are shown below, where I used a 6215 for the (simulated) "Encoder" and a 6210 for the "Counter". I connected Ctr0 out to ctr0 A and frequout to ctr0 B.

Encoder    
Ctr0 out PFI 12 pin 89
freqout PFI 14 pin 93
     
     
Counter    
ctr0 A PFI 0 pin 1
ctr0 B pfi 1 pin 2

Now that I'm looking at this again, I'm quite curious as to why it's behaving as it is. Any ideas from the community?
Thanks for your input!
Brian Spears
Message Edited by B Spears on 03-03-2009 05:03 PM
Message Edited by B Spears on 03-03-2009 05:03 PM
Message 4 of 5
(5,166 Views)

Hi Brian, 

I'm curious if you get the same result when you use a property node to set the frequency as well.  Also, are you only seeing this for the 6250 output, or is every pulse train double the frequency that it should be? I noticed that there was a CAR filed on a slightly similar issue a while back for a previous version of DAQmx/LabVIEW, however, if you're only seeing this for the 6250 Hz signal, the two could be related.  The program looks great though- thanks for posting it!!

aNItaB

Applications Engineer

National Instruments

0 Kudos
Message 5 of 5
(5,139 Views)