Synchronizing Two NI Frame Grabbers
This example shows how to synchronize the start of image capture using Image Acquisition Toolbox™ and two NI® RTSI capable frame grabbers.
It is often necessary to synchronize two or more frame grabbers very closely. For example, you could record synchronized video during an 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 NI PCI-1409 and PCIe-1430 frame grabbers.
Configure the PCI-1409
Using the Image Acquisition Toolbox, create the video input object to record video and set up the parameters for acquisition.
% Create the object. vid1409 = videoinput('ni', 1); % Set to acquire approximately one second of frames per trigger. vid1409.FramesPerTrigger = 30;
You can use either card to trigger the other, but this example uses the PCIe-1430 to trigger the PCI-1409. See what triggering settings are available for the PCI-1409.
% See the possible settings.
triggerinfo(vid1409)
Valid Trigger Configurations: TriggerType: TriggerCondition: TriggerSource: 'immediate' 'none' 'none' 'manual' 'none' 'none' 'hardware' 'fallingEdge' 'external0' 'hardware' 'fallingEdge' 'external1' 'hardware' 'fallingEdge' 'external2' 'hardware' 'fallingEdge' 'external3' 'hardware' 'fallingEdge' 'rtsi0' 'hardware' 'fallingEdge' 'rtsi1' 'hardware' 'fallingEdge' 'rtsi2' 'hardware' 'fallingEdge' 'rtsi3' 'hardware' 'fallingEdge' 'rtsi4' 'hardware' 'fallingEdge' 'rtsi5' 'hardware' 'fallingEdge' 'rtsi6' 'hardware' 'risingEdge' 'external0' 'hardware' 'risingEdge' 'external1' 'hardware' 'risingEdge' 'external2' 'hardware' 'risingEdge' 'external3' 'hardware' 'risingEdge' 'rtsi0' 'hardware' 'risingEdge' 'rtsi1' 'hardware' 'risingEdge' 'rtsi2' 'hardware' 'risingEdge' 'rtsi3' 'hardware' 'risingEdge' 'rtsi4' 'hardware' 'risingEdge' 'rtsi5' 'hardware' 'risingEdge' 'rtsi6'
Set the video input object for hardware triggering off of RTSI line 1 upon a rising edge.
% Set the triggering configuration. triggerconfig(vid1409, 'hardware', 'risingEdge', 'rtsi1');
Configure the PCIe-1430
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. vid1430 = videoinput('ni', 2); % Set to acquire approximately one second of frames per trigger. vid1430.FramesPerTrigger = 30;
In order to drive the PCI-1409's RTSI line, you need to set the correct line and polarity on the PCIe-1430. 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(vid1430); % 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 frames from each device when the PCIe-1430 is started.
Start the Image Acquisition
You can now start the PCI-1409 video input object and see that it is waiting for a hardware trigger.
start(vid1409); vid1409
Summary of Video Input Object Using 'PCI/PXI-1409'. Acquisition Source(s): Channel 0, Channel 1, Channel 2, and Channel 3 are available. Acquisition Parameters: 'Channel 0' is the current selected source. 30 frames per trigger using the selected source. 'img1' video data to be logged upon START. Grabbing first of every 1 frame(s). Log data to 'memory' on trigger. Trigger Parameters: 1 'hardware' trigger(s). Status: Waiting for trigger 1 of 1. 0 frames acquired since starting. 0 frames available for GETDATA.
You can now display a summary of the PCIe-1430 video input object and see that it is set up to trigger immediately upon start.
vid1430
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 PCIe-1430 video input object, it will immediately be triggered and begin acquiring. At that moment, the frame grabber will send a signal to the other frame grabber across RTSI line 1, which will cause the PCI-1409 to begin nearly synchronously.
start(vid1430)
% Wait on both objects until you are done acquiring.
wait(vid1430), wait(vid1409)
Display a Summary of Acquisitions
If you now display a summary you will see that both devices have acquired frames.
vid1409
Summary of Video Input Object Using 'PCI/PXI-1409'. Acquisition Source(s): Channel 0, Channel 1, Channel 2, and Channel 3 are available. Acquisition Parameters: 'Channel 0' is the current selected source. 30 frames per trigger using the selected source. 'img1' video data to be logged upon START. Grabbing first of every 1 frame(s). Log data to 'memory' on trigger. Trigger Parameters: 1 'hardware' trigger(s). Status: Waiting for START. 30 frames acquired since starting. 30 frames available for GETDATA.
and:
vid1430
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 objects are no longer needed, delete them and clear them and the reference to the source from the workspace.
delete(vid1430) delete(vid1409) clear vid1430 vid1409 src