From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Analog and digital output synchronization with external sample clock

Solved!
Go to solution

Hello,

 

First of all sorry for my english, I will try to explain what I want to do.

I want my PCIe-6321 to send two custom signals (modified sawtooths) to a mirror controller. I want also to generate a trigger output with my card at the beginning of every sawtooth. Everything needs to be synchronized with an external k-clock signal at 100kHz. The idea is that every time the PCI receives an external clock trigger, it sends two analog output voltages and when it has received 1024 clock ticks it also sends a TTL trigger peak. What I am doing is first preparing the card and after that in a loop sending and modifing the output values of both signals and at the same time sending a Digital Boolean signal in every loop, therefore when it has done 1024 iterations of the loop I send a True event to the digital port. Attached you can see it.

 

The problem is that I don't know how to synchronize both. Can I use the sample clock just in the analog output? Can I use sample clock for both outputs or do I need to use the Counter Output? If don't know how to use it here.

 

If I am doing anything else incorrectly/improperly, I'd appreciate the feedback.

Thanks in advance,
Pablo

0 Kudos
Message 1 of 14
(5,207 Views)

Hello PabloEugui;

 

you can connect the external clock direct to the DAQmx Timing function then your AO and DO runs with 100Khz after this both are synchroniced thru the external clock to start synchron use the external clock also as an start trigger. The next step is now to generate the data for the output for the DIO like 1023 zero values then 1 high value.

 sample.png

 

Hope it helps

best regards
Alexander
0 Kudos
Message 2 of 14
(5,151 Views)

A brief followup to the answer from Duffy2007:

 

The posted code may or may not sync your AO and DO tasks, depending on when the external 100 kHz clock is or isn't present.

 

If you can control the external clock and not let it start until after both the AO and DO tasks have started, then the tasks will sync up just fine.

 

If the external clock is present before starting the code, your AO and DO tasks will likely be slightly out of sync.  This is because the config calls are allowed to execute in parallel.  However, they won't arrive at DAQmx Start at the same precise instant, but whoever gets there first will immediately see the pre-existing triggering and sample clock signal.  The other will likely follow closely behind, but probably off by some handful to 10's of msec.  For you, that's 100's to 1000's of samples.

 

Here are two ideas for handling the second situation:

1.  Set both AO and DO to trigger off a signal that you control in code, probably either an on-demand digital line or a counter output.  Make sure the triggering pulse cannot be issued until after both AO and DO tasks have been started.

 

2. Configure the Ao task to use the external 100 kHz clock as its sample clock.  But configure the DO task to use "/Dev1/AOSampleClock" as its sample clock (or something very similar, not 100% sure of the naming).  Be sure to start the DO task before starting the AO task.  Then whenever the AO task happens to start, its sample clock will be used by the DO task, keeping them in sync.  No trigger config is necessarily needed for either task.

 

 

-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).
0 Kudos
Message 3 of 14
(5,129 Views)

Hello

 

you are right. The interesting part is, when and how the external clock arrive.

 

test.png                  

best regards
Alexander
0 Kudos
Message 4 of 14
(5,126 Views)

I tried your program and tested the outputs with an oscilloscope. The analog outputs are fine, but there is no signal in the digital output. I have a custom program for building my signals, because I want to use a modified sawtooth. In this program I create my two analog outputs for controling the mirror and one signal made by 0 or 1 which will be my digital output pulse that I want to use as a trigger for a DAQ (see attached picture with both analog and digital signals) . A k-clock signal of a laser must control both outputs. The analog outputs work fine but as I said I don't see any pulse in the digital output signal. Should I use a counter for it? I had a similar program where I send true/false to a Digital Boolean output and with this I was able to produce controlled pulses but was not syncronus with the analog output.

0 Kudos
Message 5 of 14
(5,063 Views)

Hello PabloEugui,

 

can you please check, if the DIO lines and ports are correct.

best regards
Alexander
0 Kudos
Message 6 of 14
(5,060 Views)

Hi Alexander, I have check it and are correct. I have also check it with the Write_Digital_Channel.vi and it works. 

0 Kudos
Message 7 of 14
(5,057 Views)

Hello PabloEugui,

can you please try it with the port write function.

sample.png

best regards
Alexander
0 Kudos
Message 8 of 14
(5,053 Views)
Solution
Accepted by topic author PabloEugui

I don't know how but I've find the solution. I am generating more than one positive value (as I was triggering very fast maybe the oscilloscope was missing it). If I put the sample clock of the digital output to use the Dev1/ao/Sample clock it does not work but if I set it to use the same source as the AO (terminal where my external clock is connected), but the Start Trigger of the DO to be Dev1/ao/StartTrigger it works. I really don't know why but it does. 

Thank you very much for your patience and your help. I put here the final code.

0 Kudos
Message 9 of 14
(5,037 Views)

"It works but I don't know why" is a precarious position to be in.  I'm not so confident that you've actually arrived at your final solution yet.  Lingering concerns:

 

1. You refer to "triggering very fast", and seeing a difference in behavior when the DO task gets its sample clock directly from the external signal vs. getting it indirectly by way of the AO task.  I wonder if your external clock signal could be noisy and sometimes look like a frequency that's too high for the AO task to respond to all pulses but not too fast for the DO?  If so, your "solution" wouldn't keep AO and DO in sync with each other.  Nor for that matter with the legit pulses of the external clock.

 

2. There's a subtle potential for a race condition when you use the same edge of an external signal as both a start trigger and a sample clock.  Does the trigger circuitry activate the task quickly enough that the same edge can be used as a sample clock?  Or is the edge gone by that time, so the *next* edge is the first one used as a sample clock?

   I've not found a definitive answer to those questions, so I'm always careful to avoid using a common edge as both trigger and clock.

 

3. A related point -- I don't happen to know the timing relationship between the external trigger and the task signal "/Dev1/ao/StartTrigger".  A similar uncertainty or delay may arise from triggering the DO task off this particular AO task signal. 

 

4. I'm puzzled why you can't use the task signal "/Dev1/ao/SampleClock" as the external sample clock for your DO task.  Unlike my comments in #3 above, I *do* have lots of experience sharing sample clocks this way successfully.  If you can get to the bottom of this issue, you could potentially remove all the triggering completely and still have sync just by starting the slave task (DO) first.

 

 

-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).
0 Kudos
Message 10 of 14
(5,019 Views)