NIDAQ External Clock Synchronization

I have a few questions on how to configure a multifunctional DAQ card (PCI-6030E) and synchronize waveform output to an external clock. A few questions I cannot seem to answer by looking at the general NIDAQ Tools procedures are how to set the level of a triggering even and whether it should key on a rising or falling edge. Is this possible?

More importantly I need to synchronize an external event that operates at a frequency of 10-20 kHz that can be accessed through a TTL signal. This TTL signal has negative peaks that last about 2 us which could potentially be used as trigger events and march through each row in a waveform.

To make things a little more complicated I'd like to use a master trigger event to start looking for the external clock and march through the custom wave. Any help would be greatly appreciated. I've tried the general waveform generation panel but when using an external master trigger and an external clock there seems to be a discrepancy as to when the waveform repeats. I would very much like the master event trigger to reset the waveform playback and interrupt any current playback to start a new one.

Cheers,

Brian
I don't quite follow what you want to do, so I will offer one general suggestion. When synchronization is required to an external device, it seems to me that usually the internal time-bases must be synchronized. Your NIDAQ card's internal time base (whether 10MHz or 20MHz) will not match exactly an external device that uses another time base, even if at the same nominal frequency. I have found that the RTSI interface will allow you to input an external time base to the NIDAQ card, and then you will have to be sure the triggers you use match the external world's timing.

Here is a line of code that illustrates such usage:
DAQmx_Scan/DEV="dev1"/MC={"/Dev1/RTSI7",20e6}/TRIG={"dev1/PFI9"}/AVE={100,50}/BKG/EOSH="scan_hook()"/STRT WAVES=ScanString

Lookup the IGOR NIDAQ Tools Manual for the proper syntax and flags, and check your device specs to be sure they are applicable.
I think s.r.chinn's solution is mostly correct, but you probably don't need the /MC flag. That flag uses an external clock as the master clock for the entire board; I don't see that need in your description. Instead, feed your 10-20 kHz signal into a PFI input and then select that input as the clock for the waveform:
DAQmx_WaveFormGen/DEV="dev1"/CLK={"/dev1/PFI10", 0}/TRIG={"dev1/PFI6"} "wave0, 0;"
I haven't actually tried this command...

It is intended to tell NIDAQ Tools to run your waveform generator with samples from a wave called "wave0", output through analog output channel 0, using PFI6 as the waveform trigger, and PFI10 (which is pretty arbitrary) as the waveform sample clock. I heartily recommend getting the waveform output to work using an internal clock before trying to use the external clock!

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
John and s.r.chinn,

Thanks for the suggestions. I am able to get the output waveform triggered and using an external clock to march through the waveform. The problem I am running into now has to do with the retriggerable nature of the process. While I would like the input clock to dictate which row of the waveform is output I would like the start trigger to reset the process and am not sure how to do this.

In essence, I'd like to have one period of the waveform that can be interrupted by an external trigger and started again immediately.

It seems like there was another function (e.g. http://www.igorexchange.com/node/5601) that you added a repeat function to that appeared helpful. I'm not sure this can be done with the DAQmx_WaveFormGen function, however, is there another combination of functions that might achieve the desired result.

Perhaps a clever way of using a hook to reset the trigger? Any help would be appreciated.

Cheers,

Brian
After fumbling through the manual I came up with the following idea and it works to some degree. The problem arises when I try to restart the DAQmx_WaveFormGen function. There appears to be a bit of an overhead and as a result the main start trigger is missed with only every other master pulse being recognized. Is there a way to make the DAQmx_WaveFormGen repeat without reloading the waveform constantly?

To refresh outline of the problem I am trying to solve, I have a master pulse that occurs every 6 seconds that is timed by another clock running at 16.667 kHz. I want the master trigger to start the playback of a waveform using the external clock at 16.667 kHz to march through the output waveform row by row. The key difference here is that I want the system to start back at first row of the playback waveform at each master trigger event. In my estimation I need to use the external clock as there is some amount of jitter involved with the master pulse so I can't simply set the period and let it ride. Again, any help is greatly appreciated.

#pragma rtGlobals=3     // Use modern global access method and strict wave access.
#include <NIDAQmxWaveScanProcs>
#include <NIDAQmxWaveFormGenProcs>
#include <NIDAQmxPulseTrainGenerator>
#include <NIDAQmxSimpleEventCounter>
#include <NIDAQmxChannelSelectorProcs>



Function TestDaq()
    resetDevice()
    Variable numPeriods = 1//set to 0 for infinite
    String EOSH
    try
        EOSH="endHook()"
        DAQmx_WaveFormGen/DEV="dev2" /CLK={"/dev2/PFI5", 0} /TRIG={"/dev2/PFI0", 2, 1, 2.5} /NPRD=(numPeriods) /EOSH=EOSH /ERRH="errorHook()" "root:wave0, 0;"//outputWave, Channel
       
    catch
        print fDAQmx_ErrorString()
    endtry
End

Function GoAgain()
    DAQmx_WaveFormGen/DEV="dev2" /CLK={"/dev2/PFI5", 0} /TRIG={"/dev2/PFI0", 2, 1, 2.5} /NPRD=1 /EOSH="endHook()" /ERRH="errorHook()" "root:wave0, 0;"//outputWave, Channel
End

Function resetDevice()
    Variable resetRtn
    fDAQmx_WaveformStop("dev2")
    resetRtn = fDAQmx_ResetDevice("dev2")
    print resetRtn
End

Function errorHook()
    fDAQmx_WaveformStop("dev2")
    print "Error"
    print fDAQmx_ErrorString()
End

Function endHook()
    //Variable numRepeats = 1
    //fDAQmx_WaveformStart("dev2", numRepeats)//doesn't produce the desired cyclic repeat it will only repeat once and then stop--doesn't loop.
    GoAgain()
    print "Repeating"
End
I don't think there is a way to have an analog waveform reset to the start while it is running. You can approximate it by computing the number of periods you need to almost fill the space between triggers (since it sounds like this happens on a timed basis) and then setting up the waveform to produce that many periods of the waveform. There are two caveats:
1) You can't have a fractional period. You will have to put up with a brief period of static output level when the last waveform period ends.
2) It silently occupies one of your counters to count the waveform periods.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com