Main Content

Synchronizing an NI® Frame Grabber And Data Acquisition Card

This example shows how to synchronize the start of image and data acquisition using Image Acquisition Toolbox™, Data Acquisition Toolbox™, and NI RTSI capable equipment.

It is often necessary to synchronize two or more acquisition boards very closely. For example, you can record the voltage from an analog sensor, such as a strain gauge, as well as synchronized video during an experiment. For the synchronization/triggering signal, you can use an RTSI cable for a reliable connection between your NI PCI-6229 data acquisition card and PCIe-1430 frame grabber.

Configure the Data Acquisition Board

Using the Data Acquisition Toolbox, create the analog input object to record voltage from the strain gage and set up the parameters for acquisition.

% Create the object.
d = daq('ni');
% Add one channel for recording the strain.
ai = addinput(d,'Dev1','ai0','Voltage');
% Set the sample rate to 10,000 Hz.
d.Rate = 10000;

Next, configure the DataAcquisition object for hardware-triggered acquisition using the RTSI1 terminal as the external trigger source.

addtrigger(d,'Digital','StartTrigger','External','Dev1/RTSI1');
d.DigitalTriggers(1).Condition = 'RisingEdge';

Configure the Image Acquisition Board

Using the Image Acquisition Toolbox, create the video input object to record video and set up the parameters for acquisition and for driving RTSI1 high when the acquisition starts.

% Create the object.
vid = videoinput('ni', 2);
% Set to acquire approximately one second of frames per trigger.
vid.FramesPerTrigger = 30;

In order to drive the data acquisition card's RTSI line, you need to set the correct line and polarity on the frame grabber. In addition, you need to determine what frame grabber event will drive the RTSI line. You can see a list of events that are available by looking at the device-specific source properties that end in “DriveLine” and “DrivePolarity”:

% Get the currently selected source.
src = getselectedsource(vid);
% Display the properties and their possible settings.
set(src)
  General Settings:
    Tag

  Device Specific Properties:
    AcquisitionDoneDriveLine: [ {none} | external0 | rtsi0 | rtsi1 | rtsi2 | rtsi3 | rtsi4 | rtsi5 | rtsi6 ]
    AcquisitionDoneDrivePolarity: [ {activeHigh} | activeLow ]
    AcquisitionInProgressDriveLine: [ {none} | external0 | rtsi0 | rtsi1 | rtsi2 | rtsi3 | rtsi4 | rtsi5 | rtsi6 ]
    AcquisitionInProgressDrivePolarity: [ {activeHigh} | activeLow ]
    ExternalTriggerLineFilter: [ off | {on} ]
    FrameDoneDriveLine: [ {none} | external0 | rtsi0 | rtsi1 | rtsi2 | rtsi3 | rtsi4 | rtsi5 | rtsi6 ]
    FrameDoneDrivePolarity: [ {activeHigh} | activeLow ]
    FrameStartDriveLine: [ {none} | external0 | rtsi0 | rtsi1 | rtsi2 | rtsi3 | rtsi4 | rtsi5 | rtsi6 ]
    FrameStartDrivePolarity: [ {activeHigh} | activeLow ]
    HSyncDriveLine: [ {none} | external0 | rtsi0 | rtsi1 | rtsi2 | rtsi3 | rtsi4 | rtsi5 | rtsi6 ]
    HSyncDrivePolarity: [ {activeHigh} | activeLow ]
    RTSITriggerLineFilter: [ off | {on} ]
    VSyncDriveLine: [ {none} | external0 | rtsi0 | rtsi1 | rtsi2 | rtsi3 | rtsi4 | rtsi5 | rtsi6 ]
    VSyncDrivePolarity: [ {activeHigh} | activeLow ]

In this case, you want to drive RTSI line 1 high when the acquisition is in progress. This ensures that the line is driven high as soon as the acquisition begins. To do this, you need to set the acquisition in progress drive line to 'rtsi1':

% Set to drive RTSI1 high when the acquisition begins.
src.AcquisitionInProgressDriveLine = 'rtsi1';

Looking at the output above, you can see that the polarity for the acquisition in progress event is already set to 'activeHigh', so you do not need to set it.

Note that the maximum number of lines that you can drive is hardware dependent and will possibly vary between devices.

At this point you are set to acquire approximately one second of data from each device when the image acquisition device is started.

Start the Acquisition

You can now start the analog input object, which acquires one second of data by default. See that it is waiting for a hardware trigger.

start(d)
d.WaitingForDigitalTrigger
ans = 

  logical

   1

You can now display a summary of the video input object and see that it is set up to trigger immediately upon start.

vid
Summary of Video Input Object Using 'PCIe-1430'.

   Acquisition Source(s):  Channel 0 is available.

  Acquisition Parameters:  'Channel 0' is the current selected source.
                           30 frames per trigger using the selected source.
                           'img0_Port0' video data to be logged upon START.
                           Grabbing first of every 1 frame(s).
                           Log data to 'memory' on trigger.

      Trigger Parameters:  1 'immediate' trigger(s) on START.

                  Status:  Waiting for START.
                           0 frames acquired since starting.
                           0 frames available for GETDATA.

When you start the video input object, it will immediately be triggered and begin acquiring. At that moment, the frame grabber will send a signal to the data acquisition card across RTSI line 1, which will cause the data acquisition to begin nearly synchronously.

start(vid)
% Wait on both objects until you are done acquiring.
wait(vid), wait(d,2)

Display a Summary of Acquisitions

If you now display a summary you will see that both devices have acquired data.

d.NumScansAcquired
ans = 

    10000

and:

vid
Summary of Video Input Object Using 'PCIe-1430'.

   Acquisition Source(s):  Channel 0 is available.

  Acquisition Parameters:  'Channel 0' is the current selected source.
                           30 frames per trigger using the selected source.
                           'img0_Port0' video data to be logged upon START.
                           Grabbing first of every 1 frame(s).
                           Log data to 'memory' on trigger.

      Trigger Parameters:  1 'immediate' trigger(s) on START.

                  Status:  Waiting for START.
                           30 frames acquired since starting.
                           30 frames available for GETDATA.

Clean up the Objects

Once the video input and analog input objects are no longer needed, delete them and clear them and the reference to the source from the workspace.

delete(vid)
clear vid d src