Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

synch analog inputs with angular encoder

Can some one please help me on this. Ive been at this for weeks now with out any joy. Im trying to synch my analog Inputs with my encoder input. I have tried everything. I have used the ai sample clock as the source for my encoder as stated in the tutorial for m series synch (http://zone.ni.com/devzone/cda/tut/p/id/3615). Have looked at all the examples and tried different trigger configurations with no succsess.  My motor position data is approx 80ms ahead of my analog data every time. If i delay the encoder start by 80 ms they nearly line up but i want them to start at the same time. I am using labview 8.2 and a m series usb 6218 cheers
0 Kudos
Message 1 of 11
(5,299 Views)
Hello,

I have taken a look at your code and at first glance I don't see anything particularly wrong with it.  I have created a much simpler application that should help us troubleshoot where your problem is.  My code is below and was written in LabVIEW 8.2.  It synchronizes an analog input with a counter angular encoder task.  Now, I have saved my results in the application graph for you to look at.  You can see my results.

For this setup I connected a square wave to my counter0 source and to an analog input.  Every pulse on the counter should show up at the same time on the analog input.  This way I can easily see if the encoder task is synchronized with the analog input.  In the setup I am only graphing if when a pulse occurs.  To make it easy for me to see when the encoder detects a pulse I am subtracting out old values.  For example if the encoder measures 0, 0, 0, 0, 15, 15, 15, 30 then I would plot 0, 0, 0, 0, 5, 0, 0, 5.  In this case the rising edge of every pulse I see on the analog input I see a the encoder count too.

I also used digital signal that was not periodic to test that everything was working correctly, and sample for sample it was.  I have posted a picture of this below.  Would you be able to generate a digital pulse externally or with a free counter on your board and run a similar test.  This will determine if the problem is with the hardware, your external connections or your software.  If using an extra counter to product a pulse train and running my example produces similar results to what I receive your hardware is working correctly.



Regards,

Jesse O.
Applications Engineering
National Instruments

Message Edited by Jesse O on 08-17-2007 02:30 PM

Jesse O. | National Instruments R&D
Download All
0 Kudos
Message 2 of 11
(5,282 Views)

Hi Jesse,

Thanks for your speedy reply. I wasn't too sure on what you meant in the last post so i tried a few tests out. You said connect a square wave to counter0 and Aio. I was a bit confused as the counter0 is two inputs A and B so here is what i did.

First i conected the motor encoder to Ctr0 A to Pfi0 and B to Pfi9

I then used the software which came with the motor to j the motor at 1 RPM from this i get ticks on both A and B 90degrees out of phase. Correct?

1) I then wired A=Pfi0 to analog input and excuted you vi. The pules are in Synch Please see image attached.

2) I repeted the same but this time on B=Pfi9 these are not in Synch???? I thought they should as its the same pulse train 90 out of phase???

3) Next i repeated the steps but this time used external square wave on the analog input generated by a frequency generator and the encoder conected as normal. Not in Synch

4) Finally I removed encoder completly and just sent the generated squarewave to both A and Analog input there in Synch.

Repeated for Ctr1 A=Pfi3 and B=Pfi10 same results

I then Spliced you code into mine as the trigger source but still no joy. I have sent some images for you to have a look

Thanks again for your help

Regards

Michael  

0 Kudos
Message 3 of 11
(5,262 Views)

just looking at your image again compared to mine when i said there in synch they seem to start at the same time but dont overlap like your image?

 

Michael

0 Kudos
Message 4 of 11
(5,258 Views)
Hello Michael,

First, thank you for trying that code.  It is a little hard for me to run your code since there is a lot of extra code. 

The image I posted, and the code I submitted was from two different versions of code.  The images from your encoder and the pulse train where exactly what I would expect and match the default data in the graph that I posted.  I think the big thing we saw from the tests is that we know the counter and the analog are triggering correctly off your encoder.  If there was a delay in starting either you would see this.  Are you able to use a finite or continuous analog input example (or external hardware) to measure both your motor voltages and the encoder?  By doing this we can see if the counter signal is being generated at the same time as your expected voltages. 

As for the signal coming from the square wave generator, the data was not what I would expect.  Can you provide more information on the setup you used?  What was the signal generator, what was the frequency used and is the output of the generated isolated or does it have a connection to earth gnd?

Regards,

Jesse O.
Applications Engineering
National Instruments
Jesse O. | National Instruments R&D
0 Kudos
Message 5 of 11
(5,252 Views)

Hi Again

 

I am still having problems with my application. I have tried altering my code but end up with the data output each time?

 

I have attached a screen shot and my latest code of my new triggering setup.

 

In this I am using an external source for both the analog and encoder inputs. I have wired port 1 line 3 to pfi1. PFi1 is the trigger source for both. After initializing the line goes high and data acquisition commences. There for the first sample from both should be lined up and all them after that. Correct?

 

I have also placed the write digital output line in the while loop and manually controlled this with a push button. When i run the vi no data is acquired until I press the button sending the line high which is what i believe i should expect.

 

So both tasks don’t start until the trigger source is active high. So they should be in synch.

 

However I am still getting the same data every time. The encoder data trails the Analog by approx. 1100 samples each time. I am using a Brand New M series USB device so i am not sure whether this is a hardware or software issue.

 

I can’t see why its out of synch if Acquisitions starts at the same time?

 

Could you please have a look and see what you think

 

Kind regards

 

Michael

0 Kudos
Message 6 of 11
(5,206 Views)
Hi Michael -

I think Jesse proved that this isn't an issue with the triggering system.  Both your Encoder Input task and your Analog Input task are running simultaneously.  So instead of troubleshooting the code (which is most likely fine), let's investigate the signals that you're trying to test.

Please create a two-channel Analog Input task and connect both the voltage signal and one of the encoder phases to these two inputs.  This way, you can watch the raw signals and see whether they're coming in to the DAQ device at the same time.  Please post the results.
David Staab, CLA
Staff Systems Engineer
National Instruments
0 Kudos
Message 7 of 11
(5,192 Views)

Hi

After some tests I have found that for some reason the encoder data always commences with rubbish data.

If my encoder reading is 6 degrees i get 1000 zeros before this data. If i change the no of recorded samples to 2000 i get 2000 zeros 100 = 100 and so on.

I jogged the motor so it was rotating and then started my vi hence the encoder reading should have no initial zeros? This explains the offset I have been receiving in my data

I reset the DAQ device at the very start of the vi so I don’t know why this is happening? Is there a way to flush the buffer so that this invalid data can be erased and the true values recorded?

 

Thanks again for your time and help

Regards

Michael 

 

0 Kudos
Message 8 of 11
(5,172 Views)
Hi Michael -

We're completely unable to reproduce that behavior here.  Which version of the DAQmx driver are you using?  If it's not the latest, I recommend trying an upgrade in case that fixes the issue.
David Staab, CLA
Staff Systems Engineer
National Instruments
0 Kudos
Message 9 of 11
(5,144 Views)
I am using Ni-DAQmx 8.5 with Labview 8.2.
 
Here is an example I jog my motor so the position increases / degrees. Stop the vi and reset the device. I then start the vi with data recording . I seem to be getting the last samples from the buffer before the encoder initializes to zero? In the picture I am recording 5000 samples at 10Khz. If i change to 1000 samples i get the last 1000. 100 = 100 and so on. I am a bit confused as reseting the device should flush the buffer correct?  
 
 
 
 
0 Kudos
Message 10 of 11
(5,141 Views)