LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I synchronize an analog read task with 2 counter read tasks?

I am using the USB-6251 data acqusition unit and the SC-2345 module for signal conditioning. I am using 2 encoders; one interfaced to counter 0 and the other interfaced to counter 1 input of the SC-2345 using PFI-12 as the clock source to provide the sampling rate. This rate is 9600Hz. I am also measuring a load cell output into one of the analog channels.

 

I acquire measurement data and pass the arrayed data to a For Loop to process the values to derive motor velocity from each counter task and a torque value from the analog input task. The measurement/process loops execute for 30 loop cycles before the motor starts motion controlled via a case statement being true then stops when 60 loops is reached. I am trying to measure startup characteristics of a motor.

 

The problem I am experiencing is that after the initial 30 loops the analog read task has measured data points for processing as the motor starts motion while the counter read tasks measured data = 0 for a short time and then starts outputting measured data.The counter measurements do not start until approx. 140mS after the analog measurement.

 

How are these read tasks synchronized?  I have being looking at Labview examples and reading tutorials but I am not finding a solution. Any help would be appreciated. The code is attached; the read and counter tasks in question are on frame 3.

 

 

 

 

Download All
0 Kudos
Message 1 of 7
(4,482 Views)

You have to route the clock from the analog task to the countertasks to have them started at the same time. For the counter tasks use the DAXmx timing (sample clock).vi and wire the ai/sampleclok with the correct device name to the source input. Then first call the DAQmx Start.vis  for the counters and afterwards for the analog task.

This way the task will start sampling with the same clock and at the same rate.

Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
0 Kudos
Message 2 of 7
(4,465 Views)

I tried your suggestions and I do not see the position counter tasks synchronized with the analog task. However, I do consistantly receive "error -200019; ADC conversion attempted before prior conversion was complete. Increase period between ADC..." which may prevent the tasks from being synchronized. I am tracking down a problem which I believe exists with the external clock source of 9600Hz connected to PFI12 that works well for the position counter tasks but it does not work well for the analog read task. I proved this by creating a seperate VI with just the position counter tasks and another VI with just the analog read task. The analog read task consistantly errors with -200019; the position counter tasks work OK. 

 

You don't know of any special considerations needed for analog read tasks when using an external clock source?  If I run the analog read task with an internal timebase it works OK.

 

hhsatBeck    

0 Kudos
Message 3 of 7
(4,430 Views)

Hi hhsatBeck,

 

I created and attatched an example program that synchronizes the acquisition of two counter tasks and an analog intput task. I also tested this on a PCI-6251 and it behaved as expected. The counter tasks are buffered period measurements but could be changed to be another type of buffered measurement. When I say that these are synchronized, I mean that the acquisitions start at the same time using the same trigger, and that the sample clock used for each of these is the same. That means for the counter tasks that the buffered count value is updated at the same time that the analog input takes a measurement. The sample clock that I used was an external signal, tested with frequency values between 1kHz and 10kHz. 

 

Just to be clear, we have to use a buffered measurement in order to actually synchronize a counter reading with an analog input task if we want the term "synchronized" to mean anything. If you are just trying to count ticks then the values that you read from the count register will only be software timed and the frequency of the actual count will only be dependent on the counter hardware being updated by the encoders. 

 

For this VI to work properly I used the following hardware configuration.

 

  • 10kHz timing signal was routed to ctr 0 source and ctr 1 source. (This is used as the timebase to measure the buffered period)
  • AI timing VI source input (on front panel) set to PFI 8 which is actually ctr 0 src.
  • Encoder 1 pin A ==>ctr 0 gate (this is the period, or semi-period to measure)
  • Encoder 2 pin A ==>ctr 1 gate ("    ")


Maybe give this a try with your input timing signal and see how it works out. This shouldn't be too hard to incorporate into your code. I hope this helps out.

 

Chris W

High Speed Products Group

 

0 Kudos
Message 4 of 7
(4,400 Views)

Hi Chris W.,

 

Thanks for your suggestions on this synchronization issue. Your code example was written with Labview 8.6; I am using Labview 8.5. 

 

I didn't use much of the hardware change suggestions you made because I want to maintain the Position Measurement capability of the counter task. The M-series documentation indicates that the encoder phases(inputs) use PFI8(A) - PFI10(B) for one encoder and PFI3(A) - PFI11(B) for the other encoder, so therefore I couldn't use ctr0 source(PFI8) and ctr1 source(PFI3) as the timing source since these are required for the position measurement counter task.

 

I used your DAQmx Trigger suggestion and placed the analog read task in a seperate while loop from the counter read tasks. I also added a start trigger for the analog read task. These changes greatly improved the synchronization of the counter tasks to the analog task; the read task lags the counter tasks by approximately 32mSec.

 

I have attached the latest code. Please reply if you have any further suggestions to make this work.

 

 

 

0 Kudos
Message 5 of 7
(4,326 Views)

Hi hhsatBeck,

 

I'm sorry about posting 8.6 code. I have re-attatched the code in version 8.0 so you can see it and in case other people are interested. I didn't realize that you were using a position encoder when I wrote that VI, however, looking back at your original post that is apparent...oops. I have modified the VI so that it uses Linear position encoder tasks and an AI task. The encoder tasks are stil buffered so that the count values that are recieved from those are count registers are synchronized with the AI readings. I am using the model of "Buffered (Sample Clock) Position Measurement" shown in page 123/424 of the M Series User Manual.

 

http://digital.ni.com/manuals.nsf/websearch/2025C99AB0614F9E8625748000577B9A

 

With this revision I've changed it so that all of the tasks run off the aiSampleClock for timing instead of relying on an external signal. You can of course specify some other source if you'd like. This should take care of the AI lag.

 

Chris W 
0 Kudos
Message 6 of 7
(4,321 Views)

Hi Chris,

 

I still had an issue of the acquired data not being aligned(synchronized) per your suggestion. The acquired data became aligned once I placed the Start Tasks in a flat sequence and added in the Start Trigger for the analog task.

 

I have attached my code; the task setup is in sequence 3 of debugTorq_TwoEncoderVel with sync with data storage.vi

 

Thanks for all of your help.

0 Kudos
Message 7 of 7
(4,260 Views)