Image Acquisition Toolbox

Synchronizing a National Instruments® Frame Grabber And Data Acquisition Card

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

It is often necessary to synchronize two or more acquisition boards very closely. For example, you could record the voltage from a strain gage as well as synchronized video during a destructive experiment that is costly or impossible to duplicate. Because of the nature of the experiment, it would be beneficial to use RTSI to ensure the most reliable connection between your National Instruments 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.
ai=analoginput('nidaq', 'Dev1');
% Add one channel for recording the strain.
addchannel(ai, 1);
% Set the sample rate to 10,000 Hz.
set(ai, 'SampleRate', 10000);
% Set to acquire samples for one second per trigger.
set(ai, 'SamplesPerTrigger', 10000);

Next, set the analog input object for hardware triggering off of RTSI line 1.

% Set the triggering type to hardware digital.
set(ai, 'TriggerType', 'hwDigital');
% Set the triggering condition to a positive edge.
set(ai, 'TriggerCondition', 'PositiveEdge');
% Set the triggering source to RTSI line 1.
set(ai, 'HwDigitalTriggerSource', 'RTSI1');

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.
set(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.
set(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 and see that it is waiting for a hardware trigger.

start(ai);
ai
Display Summary of Analog Input (AI) Object Using 'PCI-6229'.

  Acquisition Parameters:  10000 samples per second on each channel.
                           10000 samples per trigger on each channel.
                           1 sec. of data to be logged per trigger.
                           Log data to 'Memory' on trigger.

      Trigger Parameters:  1 'HwDigital' trigger(s).

           Engine status:  Waiting for trigger 1 of 1.
                           0 samples acquired since starting.
                           0 samples available for GETDATA.

AI object contains channel(s):

   Index:  ChannelName:  HwChannel:  InputRange:  SensorRange:  UnitsRange:  Units:   
   1       ''            1           [-10 10]     [-10 10]      [-10 10]     'Volts'  

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(ai, 2)

Display a Summary of Acquisitions

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

ai
Display Summary of Analog Input (AI) Object Using 'PCI-6229'.

  Acquisition Parameters:  10000 samples per second on each channel.
                           10000 samples per trigger on each channel.
                           1 sec. of data to be logged per trigger.
                           Log data to 'Memory' on trigger.

      Trigger Parameters:  1 'HwDigital' trigger(s).

           Engine status:  Waiting for START.
                           10000 samples acquired since starting.
                           10000 samples available for GETDATA.

AI object contains channel(s):

   Index:  ChannelName:  HwChannel:  InputRange:  SensorRange:  UnitsRange:  Units:   
   1       ''            1           [-10 10]     [-10 10]      [-10 10]     'Volts'  

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)
delete(ai)
clear vid ai src