Example Code

Synchronize Analog Output Sample Clock With TTL Pulse Count

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Hardware

  • Data Acquisition (DAQ)

    Software

  • LabVIEW

    Driver

  • NI DAQmx

Code and Documents

Attachment

Overview
The example is to demonstrate how to generate a 2D raster pattern of the analog output within the DAQ hardware

Description:
The code is intended to sweep an analog output across a 2D raster pattern.  On each tick of the sample clock, we use a counter to measure the number of TTL pulses that occurred during the "pixel" of the Analog Output.  This is a technique often used for imaging purposes (e.g. X-ray Photoelectron Spectroscopy).
*Note: there is a separate version of the code intended to work with the 621x DAQ devices--they implement the buffered period measurement slightly differently (they automatically discard the first sample).  All other M and E series devices should use the standard version of the code.

Steps to Implement or Execute Code:

To implement this example:

1. Set the value of the parameters as needed
2. Run the VI
3. (Optional) Turn on the Highlight Execution to see the flow of the VI

To execute this example:

1. Install the required software.
2. Connect the DAQ hardware that supports the AO features
3. Confirm the connection with the MAX with TestPanel
4. Open the VI and refer the Implement Steps
 

Requirements
Software
LabVIEW 2012 or compatible
NI-DAQmx 16.0 or compatible

Hardware
cDAQ with C series Analog Output Module

 

fpm.PNG

 

bdm.PNG

 

**This document has been updated to meet the current required format for the NI Code Exchange.**

John Passiak

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
John_P1
Trusted Enthusiast
Trusted Enthusiast
on

Version 2: Fixed a bug with the "zero indexing" of raster pattern.

John Passiak
John_P1
Trusted Enthusiast
Trusted Enthusiast
on

Version 3: Modified code to function properly in the case that the software plot takes longer than the actual acquisition (i.e. samples being queued up).

John Passiak
John_P1
Trusted Enthusiast
Trusted Enthusiast
on

Version 4/5:  Added compatibility for USB 621x devices.  The code had to be slightly reworked to account for the 621x devices automatically discarding a sample in the buffered period measurement.

John Passiak
Egidijus
Member
Member
on

Hi, can you possibly tell me why it doesn't work with PCI-6115 card and what modifications I should inplement?

Cheers,

E

John_P1
Trusted Enthusiast
Trusted Enthusiast
on

The 6115 only has 1 DMA channel, so I believe the Counter Input task is going to default to Interrupts.  With this setting, if the clock is too fast then you'll probably get error -200141 on the counter input task (Data has been overwritten before it could be read by the system.)

You can still get that error if using DMA, but the latency will be much lower so you can achieve higher rates.  If using a 6115 I would make the following modifications:

  1. Use the DMA channel for the Counter Input task (settable with a DAQmx Channel Property Node)

  2. Use only on-board memory for the Analog Output task (settable with a DAQmx Channel Prooperty Node)

Other than this I don't see any problems with using the code with a 6115.  Use the version that is not for the 621x / X Series.

John Passiak
Egidijus
Member
Member
on

Thanks John, I am now actually trying to buy a reasonably priced card specificly tailored for this (or similar) application. Since I need to be able to raster-scan (and therefore photon-count) quite fast in xyz it seems that the PCI-6229 would be optimal for this application. Do you see any problems with this card? By the way the PCIe-6323 seems to have even better spec for the same price, again - would it work?

Cheers,

E

John_P1
Trusted Enthusiast
Trusted Enthusiast
on

Since I need to be able to raster-scan (and therefore photon-count) quite fast in xyz it seems that the PCI-6229 would be
optimal for this application

  1. One limitation on the PCI 6229 is that there is no on-board FIFO for counters (similar to the 6115).  From this benchmark here, you'll probably be limited to about 380 kHz on the PCI 6229 (should be identical to the 625x).  The PCIe 6323 card (or any 63xx card) will sustain a MUCH faster throughput on the counter lines given the faster PCIe bus and the inclusion of an on-board FIFO.  The limiting factor on this card becomes the max AO update rate (775 kHz for 3 channels).

  2. The second concern with the 622x (or 632x for that matter) is the accuracy and glitch energy of the DAC.  Depending on what your control voltages are, you might find the glitch energy unacceptable for these two boards which use the same DAC.  The maximum glitch energy is specced at 100 mV * 2.6 us.  This maximum glitch would occur when crossing the midpoint of the DAC (~0V), so you can somewhat avoid it if you ensure you do not cross the 0V mark with your AO.

I think the ideal solution would be something more along the lines of the PCIe 6353.  It has the on-board FIFO which all X Series cards have, as well as a better DAC (1.54 MHz on 3 channels, 10nV * 1s glitch energy).  So, this would allow you to go faster and with more accuracy.  It is about $600 more so you'll need to decide if the tradeoff is worth it or not (perhaps 775 kHz is fast enough for your application and the glitch/acuracy is negligible at your voltage levels).

In any case, I would avoid the M Series (62xx) and go with the X Series (63xx) equivalent if PCI Express is an option.  There's nothing inherently wrong with the M Series cards, but the X Series boards will have more features for the same (or lower) price.  The X Series are our newer generation of DAQ cards and are priced competitively with the old generation.


If you do go with an X Series board you would need to use the example posted labelled "621x" since these boards also automatically discard the first sample (which is not a full period of the input signal).

John Passiak
Egidijus
Member
Member
on

Thanks John, I am now considering buying PCIe-6363 card which have the best specs, as I understand. So I assume that it will also work well with the software ('621x') and I will not have to change anything in there.

Cheers,

E

John_P1
Trusted Enthusiast
Trusted Enthusiast
on

That's correct--I wrote this code before X Series DAQ cards were released but they should have the same behavior as the 621x with regards to this application.

The 6363 and 6353 use the same DACs.  If you're just purchasing the card for this application the 6353 could save you a little bit of money.  The AO specs are identical for the two boards.

The 6363 can sample faster for single-channel acquisitions, but for multi-channel Analog Input applications the multiplexer is the limiting factor (same on both boards).

John Passiak
Egidijus
Member
Member
on

Ok, makes sense. Thanks. I might actually want to used a high sampling rate in Analog input, however. But I have this PCI-6115 card (10MS/s for AI) - can the two cards be made to work together in synchrony without too much of a trouble? I mean the PCIe-6363 would be used for AO&Counting and PCI-6115 for AI (both synchronously).

E

John_P1
Trusted Enthusiast
Trusted Enthusiast
on

The cards can certainly run at the same time. 

If you're looking to actually synchronize the boards together I would highly recommend using a RTSI cable to share timing and triggering signals between the boards.  Some things to take note of:

  • The X Series board can accept a reference clock and PLL its 100 MHz oscillator to it
  • Either board can accept an external timebase or sample clock
  • The 6115 has a 2 sample AI pipeline
John Passiak
Egidijus
Member
Member
on

Can you also let me know which PCIe slot does it specifically occupy? Is it PCIe x1?

Thanks,

E

John_P1
Trusted Enthusiast
Trusted Enthusiast
on

The board itself is x1 which means it will work with x1, x4,x8, and x16 PCIe slots.

You can refer to the Bus Interface section of the Device Specifications (here's a link for the 636x).

John Passiak
GabyTheriault
Member
Member
on

Hi,
I have LabVIEW 8.5 with a PXIe controller, could these VI's work on my computer?

If so, could you please post the VI's in 8.5 format?

Cheers,

Gaby

John_P1
Trusted Enthusiast
Trusted Enthusiast
on

Sure, are you using X Series DAQ (PXIe 63xx)?  If so, it will use the same VI as the 621x example.

I added a .zip file that contains the VIs saved for LV 8.2 which should also work in 8.5.

John Passiak
GabyTheriault
Member
Member
on

Thank you for answering so quickly John!

I can now run the VIs.

I'm new to LabView so this might seem silly, but I don't understand how to get the physical channel right. When I try to select a channel, I get a blank browse window. The hardware I have is two function generators (PXIe-5402) and an oscilloscope (PXIe-5122). Does it mean I can't use DAQ functions and have to write a VI using Ni-Scope functions?

John_P1
Trusted Enthusiast
Trusted Enthusiast
on

Hi Gaby,

Yeah, the 5402 uses NI-FGEN and the 5122 uses the NI-SCOPE driver so this example won't work with that hardware.  We do have online support for Function Generators and Scopes.  If you're looking for assistance on how to program your application with this hardware I would try the forums or contacting NI for support.

Depending on your exact requirements, it might be easier to use a Multifunction DAQ card.  What are the specs required for your application?  The 5402 and 5122 are going to have much better dynamic performance and a much higher sample rate than a DAQ card for example.  However, this example uses the on-board counters of a DAQ card to count TTL pulses during each pixel rather than sampling the analog signal.  If this is what you need to do, and the update rate/glitch energy of a DAQ card's AO isn't a problem, you might instead want to go this route.

John Passiak
GabyTheriault
Member
Member
on

I was hoping to find pre-made VI's for a fluorescence microscope scanning system, but it looks like I'll have to program my own!

Thank you for your assistance.

Data acquisiotion
Member
Member
on

Thanks for sharing the code:)

How easy is to change the line-rate (x speed) in your code?

How about making it bi-directional?

Thanks

laserpuppy
Member
Member
on

Hi John, found your code as searching for some sync. solutions. Your post has been of great help. But I do have a question, as you mentioned in some other post about the 'period' measurement with counter, the very first sample will be ignored by the system, so my question was, if you are also doing AO task, which is synchronized with CI task, and the CI input values will be the pixel values (in your example), then what will be the value for the first pixel in this case?

Suppose that you have 10 by 10 matrix to fill with counter's values, is that ture the counter input task will only sample 99 samples instead of 100 (due to the invalid first sample?)

Thanks

John_P1
Trusted Enthusiast
Trusted Enthusiast
on

Discarding the first sample is a "feature" of newer DAQ hardware (621x, X Series).  So there are two different versions of the top-level program depending on which version of hardware you are using (I should probably make a combined version that cases off of hardware types--at the time I wrote this X Series did not yet exist).

With the 10x10 matrix you should receive 100 samples since there is an extra AO sample at the end to return the output back to its original position.

John Passiak
lp9805
Member
Member
on

Dear John_P1,

I am hoping that you might be able to help me synchronise a PCI 6115 running an AI task at 10 MS/s with a PCIe 6363 running a AO task at 2 MS/s.  I have a RTSI cable and have been talking with NI UK Customer Support, but so far we haven't succeeded in synchronising these two cards while also running them at different sampling rates. 

My understanding from reading this:

http://zone.ni.com/reference/en-XX/help/370466V-01/mxcncpts/syncsampleclock/

this:

http://zone.ni.com/reference/en-XX/help/370466V-01/mxdevconsid/synchrone/

and this:

http://zone.ni.com/reference/en-XX/help/370466V-01/mxdevconsid/synchronmxsc/

Is that we need both devices to support either Master Timebase or Reference Clock synchronisation methods and since they are S and X series respectively, we have no overlap in their supported synchronisation methods.

Is there something we are missing?  Or something that we can do using the RTSI cable?

Any help very gratefully received!

Loren

lp9805
Member
Member
on

Resolved with the aid of NI UK Support.  We use an RTSI cable to synchronise the sample clocks.

@mi
Member
Member
on

 

Hi,

 

I am working on project where I have to make laser scan device which can scan the sample in line by line manner or raster scan.

 

For the same I am using small beam galvano mirror device from Thorlab (https://www.thorlabs.de/newgrouppage9.cfm?objectgroup_id=3770), USB DAQ 6361(National Instrument) and Labview software.

 

Galvano mirror has input range +-10V, sinewave(250Hz) or Triangular Wave(175Hz) or Sawtooth wave(175Hz) or Square Wave(100Hz).

 

Mirror is configured to rotate 0.8V/1 Degree,

 

I have made one labview design by using that I can operate the mirror, but now I have to make graphical programme which can control the scanning of the beam on to the sample.

 

So do you know how to control the laser beam while scanning?

control the X and Y mirror analog input voltage.

 

As this is the comment section I can not able to attached the vi 

 

Thank you.

 

Kevin_Price
Proven Zealot
Proven Zealot
on

Crossposting.  Continue discussion over here.   (I'm gonna point back to this thread but I think discussion should happen in the other one.  Examples aren't a forum that fosters a lot of ongoing discussion.)

 

 

-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).
WengWengWeng
Member
Member
on

Hi,

I am new to LabVIEW. I would like to build a confocal microscopy with APD and galvomirror. I would like to 2D raster scan the sample and the APD will count the photons at each position. (PCI-6733 and PCI-6602) 

 

I have a few questions about this code. I am confused that how to set the frequency of 2D sawtooth. I cannot find the code inside which is related to the frequency.

Another question is, if I want to read out a photon count at each point, how should I synchronize all of them. Based on this example( https://forums.ni.com/t5/Counter-Timer/Help-with-photon-counter-data-acquisition-using-LabView-12/td...), the CI is synchronize with another CO.

 

Thanks for the help!

 

-Crystal