LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

synchronization between counter positon and analog input

Solved!
Go to solution

Hi guys,

 

I got a problem by synchronizing the counter positon signal form a interferrometer and an analog sinous signal from function generator, in order to get the relationship between these two signal. The position of sample in my experiment is controlled by the electric field. And the strength of E-field is controlled by sinous signal from function generator. The sampling rate and number are setted same, and i used the aisample as the source of counter clock. Then start to aqcuire the data at the same time. But the result seems not always right, because sometimes the signal from interferrometer does not correspond to the right signal from function generator. I always got different shape in XY diagram.(please see the picture 1-4), and another problem is the erroer(in picture overwrite) happens all time when i run the LabVIEW VI below.

 

I wonder if the synchronization problme could be solved through LabVIEW program, or is it because the delay form the hardware device which i can change? I hope some one could give me some tips to solve these problems.  Thanks a lot.

 

sincerely

Laiiiiiiiiiiiiiiii

0 Kudos
Message 1 of 11
(3,348 Views)

First thing to fix is how you sequence the calls to DAQmx Start for the two tasks.  Swap them.

 

Reason:  your encoder task is "borrowing" the AI task's sample clock to use as its own sample clock.  +1 for sharing a sample clock to keep two tasks synchronized in hardware.  Inside your loop, you're requesting  the same # samples from both tasks.  +1 for managing the task reads to keep your data streams in sync within your app.

 

You've added a sequence structure to make sure you enforce the order in which the two tasks start.  +1 for that.   However, you *need* to start the encoder task first so it's already ready when you later start the AI task which produces both task's sample clock.  -1 for getting the order wrong.  But overall, you've done a good job doing most of the needed steps to maintain task & data sync.

 

There's one other possible subtlety though.  You start your encoder task with a claimed position of 0, no matter where it *actually* is within its oscillation cycling.  As a result, you can expect a DC shift in the encoder data from one run to the next.  It's a result of this unknown and likely varying difference between the encoder position at task start and the actual midpoint of oscillation.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 2 of 11
(3,291 Views)

Hello laiiiiii,

your vi with some modifications from included.

 

test.png

 

 

best regards
Alexander
Message 3 of 11
(3,279 Views)

Hi Kevin P,

 

Many thanks for your suggestions, i have followed your instrcution and correted the VI. Unfortunately, The problem is still there. Smiley Sad And I think you are right, the main issue should be the initial position of the counter, it is calimed as 0.  But i can not do anything with this setting, it is compulsive to write a number in this part of Vi, also in DAQassitant. So every time when i run the programm, the start postion of counter is always 0, but the start point of analog signal changed all the time.  I wonder, if i can tigger the anaglog input signal with a value, for exmple when the value of anaglog signal is 0 then start to acquire both signal. Is there some method to realize this function?

I hope you can give me some hints to solve this problem. Thanks a lot!

 

sincerely

Laiiiiiiiii

 

 

0 Kudos
Message 4 of 11
(3,271 Views)

Hello laiiiiii,

 

before you start can you do something like a reference move to find the home position and start from this point?

best regards
Alexander
Message 5 of 11
(3,268 Views)

Hi Alexander Glasner,

 

Actually there is no clear zero postion, I got this AquaB signal directly from the interferrometer, it is ok to have reset the zero postion of evrytime when i run the VI, but the problem is how can i also get a zero value of anaglog signal in the beginning to match this zero postion. I am trying to find a way control the start value of analog signal, but i dont  konw if i am in a right direction.  thanks a lot!

 

(Short description of my experiment:

An external electric field is applied on a smaple, which will have a strain under different strength of electric field. Electric field is controlled by a sinuous fucntion, which is also our analog signal here. When the anaglog signal is zero, means electric field is zero on my sample, and this postion could be claimed as a zero postion during each measurement.)

 

sincerely

Laiiiiiii

0 Kudos
Message 6 of 11
(3,266 Views)

Hello laiiiiii,

 

depending on the hardware you could use an analog trigger for the analog inputs as a start point for the measurement. A second option, in my oppinion, is to continous measurement  the signals and make some post processing to filter out the Information you want.

 

What hardware is in use?

best regards
Alexander
Message 7 of 11
(3,263 Views)
Solution
Accepted by topic author laiiiiii

Couple further notes on analog hardware triggering vs. post-processing:

 

1. If your data acq hardware supports analog triggering, you'll want to configure the encoder task to use an "Arm Start" trigger, which requires the use of a DAQmx property node to configure.  This way the counter "arming" which sets its count to 0 doesn't occur until the triggering event, which will be when the AI signal crosses 0.

 

2. Post processing should be a pretty straightforward alternative.  Remember that your two tasks' data arrays will be synced by index #.  So if you can find the 0-crossing of your AI data, the index can be used to get your encoder offset value.  Just subtract that offset from *all* the encoder data to normalize it to the right 0 position.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 8 of 11
(3,260 Views)

Hi Alexander Glasner,

 

Now i am using the PCI 6221 NI card. I have saw your VI, there is a arming start trigger, is that for the anaglog input trigger? and how to set a tigger value for anaglog input signal, can you give me some advises? Thanks again.

 

best regards,

Laiiiiiiii

0 Kudos
Message 9 of 11
(3,248 Views)
Solution
Accepted by topic author laiiiiii

Hello laiiiiii,

 

sorry for this, the PCI-6221 do not have an APFI Input on pin 20 of the card, so analog trigger is not supported on this device. In this case post processing seems to be the possibility for your application.

best regards
Alexander
Message 10 of 11
(3,239 Views)