Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Tutorial
NI Supported: Yes
Publish Date: Jul 16, 2007

Triggering a FireWire Camera Using LabVIEW on a Compact Vision System

1 ratings | 4.00 out of 5
Print

Overview

This tutorial introduces basic triggering concepts, but focuses on triggering with IEEE 1394 cameras. In addition to triggering IEEE 1394 cameras this document also discusses some of the particulars of using LabVIEW on a Compact Vision System (CVS) along with an IEEE 1394 camera for different triggering applications.

General Triggering Concepts

In any data acquisition, including image acquisition, there is often a need to synchronize data to actions or events.  Triggering is one method used to fulfill this need. A trigger signal is commonly a digital pulse that has a distinct transition.  This transition should be clear and deterministic to ensure that our actions occur at the desired time.  If image acquisition is being used to examine parts on an assembly line, a signal is needed to ensure that the parts appear in the same location in each image.  Without triggering we would acquire many images that may either not contain the item of interest or maybe even multiple images of the same item.  Later in this paper we will discuss specific use cases for triggering as well as triggering methods, but first, we will discuss the normal operating mode of a camera.

Free Run Mode

Free run mode is the default operation mode for most cameras.  In free run mode a camera uses its internal timing circuitry to acquire and output images on a regular basis.  How often a camera outputs an image is referred to as the frame rate, commonly stated in frames per second (fps).  When a camera is powered on, it immediately begins acquiring and sending data.  When connected with a framegrabber, the framegrabber will lock onto the camera’s pixel clock and acquire pixels based on the camera’s timing signals.  In the case of IEEE 1394 cameras, the IEEE 1394 interface will acquire packets of data as they are sent from the camera.  In this operation the camera acquires data in its own time and is not synchronized with any outside source.

Software Trigger

In cases where a camera does not have the capability of being triggered, or synchronization is not critical, a software trigger can be used to “begin” acquisition.  In this mode, the camera still operates in free run mode, but the software trigger simply determines when our interface will begin paying attention to the data being sent by the camera.  The term “software trigger” is used loosely as this method does not actually start the image acquisition.  If a camera is in the middle of acquiring a frame, the interface will wait until the next full frame is available and consequently there can be a large time variance between when the software trigger is seen and when the associated image is actually acquired.  Due to its non-deterministic nature the “software trigger” is not considered an actual trigger for the purposes of this paper.

Hardware Trigger

As described above, the delays and non-deterministic behavior of the “software trigger” means that synchronization using this method is poor at best and will not be considered as a trigger for this paper.  In order to achieve synchronization with an external signal a camera must have triggering capabilities.  The camera must be capable of being set in trigger mode and accepting a trigger signal.  When the camera receives the trigger signal it will begin acquiring an image immediately.  Since these signals and timing are all strictly hardware based this acquisition is deterministic and immediate for most practical purposes (trigger latency will be discussed at a later time).  Different trigger modes exist where each frame (or even each line in the case of line scan cameras) can be triggered or the start of acquisition can be triggered and the camera will acquire at its own speed after the initial trigger.

Every camera interface has its own triggering abilities. Since most analog cameras use a BNC cable to send data this means that a second cable is required for the trigger signal.  The CameraLink standard specifies multiple data lines and camera control lines that are all contained in a single cable.  Trigger signals can be sent along these camera control lines eliminating the need for extra cabling.

This paper is concerned with triggering IEEE 1394 compliant cameras, which, like analog cameras, requires a second line for triggering.  Like analog and CameraLink cameras, for true triggering, an IEEE 1394 camera must have circuitry that makes triggering possible.  We will first provide a background on the IEEE 1394 technology and how it relates to cameras and then we will discuss triggering modes with these cameras.

IEEE 1394 Camera Standard

IEEE 1394, also known as FireWire or I-Link, is a high-performance serial bus interface that offers high-speed communications and isochronous real-time data services.  Devices which use this technology are hot-pluggable, eliminating the need for shutting down a PC to add and remove hardware.  

The IEEE 1394 bus provides both asynchronous and isochronous data transfer contingent on if the user wants guaranteed delivery or guaranteed bandwidth, respectively.  Asynchronous mode uses a data acknowledge packet from the recipient to verify that all data is transferred correctly.  If the device does not get this acknowledgement after sending data, it will retry the command; therefore there is no guarantee of bandwidth.   For isochronous data transfer, the data transmission is divided into 125 microsecond cycles and each cycle begins with an asynchronous cycle start packet for commands.   Each device requests a partition of the 125 microsecond cycle depending on its packet size (KB/packet).  Since the recipient does not acknowledge data transfer, there is no guarantee that transfer has been successfully made.  Devices, such as cameras, that request isochronous bandwidth are guaranteed a single packet per cycle.   Also note that the total bandwidth of the IEEE 1394 bus is shared among all devices connected which is limited to 400 MB/s and 800MB/s for 1394 a and b respectively.

The IEEE 1394-based Digital Camera (DCAM) Specification is owned by the IEEE 1394 Trade Association and provides a means of standardizing image formats, triggering methods, frame rates, and control of FireWire-based devices.  When these settings are chosen, the camera automatically assigns the packet size that will be transferred with each isochronous transfer.  Users can typically change the packet size by changing the frame rate or the image size.  The smaller the packet size, the longer the transfer time, but bandwidth will free up to allow more devices to send their packets within the 125 microsecond time slice. 

More information regarding IEEE 1394 technology can be found at:

Acquiring from FireWire Cameras with National Instruments NI-IMAQdx and Legacy NI-IMAQ for IEEE 1394

Triggering IEEE 1394 Cameras

The 1394 bus does not have the ability to directly send a trigger signal to the camera; therefore, a separate line is needed.  Also, the camera must have triggering capabilities.  The following are the various trigger modes available on the IEEE 1394 bus.

Trigger Modes

Six triggering modes (0-5) are defined by the DCAM spec with two additional modes (14, 15) reserved in v1.31 for vendor-defined triggering methods.  

Mode 0 – Programmable Trigger - The camera starts integration of the incoming light from the external trigger input falling edge.  The integration time is specified by defining the “Shutter” attribute; therefore, no parameter is needed.

Mode 1 - Pulse Width Control - Similar to Mode 0, the camera starts integration from an external trigger input falling edge; however, the integration time is equal to the low state of the external trigger.  Again, no parameter is required.

Mode 2 – Trigger Pulses Control - The camera starts integration of incoming light from the FIRST external trigger input falling edge.  At the Nth (parameter) external trigger input falling edge, integration is stopped.  This N control parameter is required to be 2 or more (N >= 2)

Mode 3 – Internal Trigger - The camera issues a trigger internally and cycles N (control parameter) times of the cycle time of the fastest frame rate.  The integration time is specified by defining the “Shutter” attribute.

Mode 4 (DCAM 1.31+) – N Frames, Programmable Shutter – The camera starts frame integration when the external trigger input changes to an active value. Each frame is exposed for a duration specified by the shutter attribute. The sequence is repeated N time for every external trigger input falling edge then finishes integration.  This parameter N is required to be 1 or more.

Mode 5 (DCAM 1.31+) – N Frames, Pulse Width Control - Similar to Mode 4, the camera starts frame integration when the external trigger input changes to an active value, but exposes incoming light while the external trigger is active.  The number of frames is specified by the optional parameter, N, which must have a value of 1 or more.

Not all cameras support every mode listed above.  When designing a system for external triggering it is important to understand the specifications of the particular camera and which modes are available.   It is also necessary to take into account trigger latency, which is the amount of time between physically triggering the image and acquiring it in computer memory.  The total time is the summation of the trigger response time, exposure time, sensor readout, IEEE 1394 bus transfer time, and host response time as presented in the equation:

Ttotal = Ttrig + Texp + Tsensor + Ttrans + Thost

Hardware trigger (Ttrig) response times typically ranges from .02 - .07 milliseconds depending on the camera model.  Exposure time (Texp) is the amount of time the camera is acquiring light which can be user-defined usually from 20 microseconds and up to several seconds.   Sensor readout (Tsensor) is the time needed to empty the pixel data to the camera’s on-board image buffer.  The amount of time (Ttrans) to transfer the image from the camera to the PC, via the IEEE-1394 bus can be calculated using the following equation.

Ttrans = [{(AOI Height x AOI Width)/ (Bytes/packet)}*125]/1000   

The time (Thost) it takes for Windows to place the video data into a buffer for further image processing is dependent on both the host processor speed and the thread priority.  Now that we have covered the trigger modes available for IEEE 1394 cameras we will present system configuration options and applications using the Compact Vision System (CVS).

Triggering Configurations

These next sections discuss how a CVS can be used in a triggered acquisition.  There are three main configurations: triggering the camera directly, triggering the CVS which then triggers the camera and triggering the CVS which can then trigger the camera and a light source.  Each of these configurations builds on the simpler configurations. 

Trigger Camera Directly

The first and most simple configuration is to trigger your camera directly and use the CVS for acquisition of the image data only. 

Hardware Setup

In this configuration wire the sensor output directly to the camera.  This method is straightforward as long as the signal from the sensor is compatible with the trigger circuitry of the camera.  Many cameras have optically isolated trigger inputs which may require some additional circuitry from your sensor signal for proper functionality.  When the camera is triggered it will send the image data to the CVS where it can be acquired/processed as needed.

Hardware setup to trigger camera directly from sensor and then send acquisition data to CVS
Figure 1. Hardware setup to trigger camera directly from sensor and then send acquisition data to CVS

Software Setup

To run an application where the camera is triggered, your software setup will be very similar to a normal Grab application.  The important step in this configuration is that the camera is put into triggered mode.  Using IMAQdx you can query the available trigger modes, then select from the available modes and set this mode on the camera.  You can also see the available trigger modes for your camera in Measurement and Automation Explorer (MAX) in the Attributes tab.  See the Trigger Modes section to determine the appropriate mode for your application.

Camera Attributes Tab in MAX
Figure 2. You can see the available trigger modes for your camera in MAX.

Open your camera reference. Select the appropriate TriggerMode, TriggerActivation and Timeout. Use a property node to set these values on the camera. This node will set the trigger mode, polarity and timeout for the trigger mode on the camera.  Note: The Active Attribute string must be entered exactly as it appears in MAX for the attribute to be recognized.  Then the next VI configures the Grab.

Configure Camera Attributes Using IMAQdx
Figure 3. In LabVIEW open a reference to the camera and set camera attributes using an IMAQdx Property Node, then configure your grab acquistion.

  The rest of your code is unchanged from a normal grab acquisition as shown below. Close your camera reference and handle errors at the end of your program.

Grab Acquisition Code
Figure 4. After setting the trigger mode on the camera perform a grab acquisition as you normally would.

Use Cases

This is the simplest trigger configuration and should be used when no other timing requirements exist.  This use case will minimize cabling necessary compared to other possible configurations, but will give no control over timing delays or synchronization with other devices.  The camera will acquire when it sees the trigger source and then the CVS will process the image as soon as it is received.  For more advanced synchronization methods, use IMAQ I/O functions to program the Field Programmable Gate Array (FPGA) on the CVS.

Advanced IMAQ I/O

The CVS has a 44-pin DSUB connector, shown in Figure 5, that provides access to the general-purpose digital inputs and outputs.  This connector is described in detail in the user manual for the CVS.  The general-purpose digital I/O available on this connector includes 2 TTL inputs and 6 timed pulse outputs that can be used as trigger inputs and outputs.  These lines are controlled by a Field Programmable Gate Array (FPGA) which allows for precise hardware timing in addition to being independent of the processor on the CVS.  The IMAQ I/O driver [IMAQ I/O function palette is shown in Figure 6] can be used to access the FPGA and achieve a variety of more advanced triggering applications.  Using these functions the CVS can send multiple triggers to different devices as well as accepting trigger signals.  The software configuration will be discussed in more detail in the corresponding sections describing different triggering applications.

44-Pin DSUB Connector
Figure 5. 44-Pin DSUB Connector

 

NI-IMAQ I/O Function Palette in LabVIEW
Figure 6. NI-IMAQ I/O Palette contains functions to configure the FPGA on the CVS.

Trigger Camera from CVS

This configuration is slightly more advanced than the first configuration where we directly triggered the camera.  In this case the signal from the sensor is passed to the CVS and then the CVS sends a trigger pulse to the camera.

Hardware Setup

In this configuration, the sensor is connected to the Compact Vision System on the 44-Pin DSUB on either TTL Input pins 0/16 or Trig0 on SMB connectors.  The FPGA is then programmed to initiate a timed pulse when a trigger is received.  Once the camera is triggered, the image data is received by the CVS for inspection and image processing. 

Hardware setup to 1) Sensor triggers CVS, 2) CVS sends trigger pulse to camera, and 3) Camera sends image to CVS.
Figure 7. Hardware setup to 1) Sensor triggers CVS, 2) CVS sends trigger pulse to camera, and 3) Camera sends image to CVS.

Software Setup

The software setup is the same as the camera triggered mode with the addition of a few functions.  These functions open and initialize the FPGA on the CVS and configure the trigger pulse.

Place the Open I/O function on the block diagram and the appearance changes as shown. 

Open IMAQ I/O Function
Figure 8. Open I/O function will open a reference to the FPGA target on the CVS.

After you open the reference to the FPGA on the CVS add an IMAQ I/O Read/Write Control.  Then you can select the pulse line on which you want to output a trigger pulse to the camera.  You can select each item individually or populate all the elements for this digital line by selecting All Elements.  As with other property nodes the Read/Write Control executes from top to bottom and can be resized as needed. 

 Configure Pulse using Read/Write Control
Figure 9. Select All elements for desired pulse line to configure attributes using the IMAQ I/O Read/Write Control.

After selecting all elements you can wire constants or controls to each of the elements to define your pulse parameters and also the trigger source line for this pulse generation.  This configuration can be performed in parallel with the code configuring your camera, but should be completed before the acquisition is begun and the trigger is sent.
 

Configure Pulse
Figure 10. The IMAQ I/O Read/Write Control executes from top to bottom.  This configuration should be complete before the image acquisition begins.

When the code in Figure 10. is executed, the FPGA on the CVS will set the Pulse 5 (TRIG 1) line to low and wait for a rising edge on ISO Input 8 (since the Trigger Polarity is set to TRUE). 10 µS after it recieves a rising edge on ISO Input 8, the FPGA will drive the Pulse 5 (TRIG 1) line high for 1000 µS before setting it back to low. This process will repeat for every rising edge on ISO Input 8.

At the end of your program in addition to closing the reference to your camera and clearing image buffers make sure to close the FPGA reference as shown below.
 

Close FPGA Reference
Figure 11. As part of the clean-up for your program make sure to close all references including the FPGA reference.

Use Cases

This setup allows you to control the trigger signal going to the camera.  Depending on the application, the generated pulse can occur from a falling or rising edge of an input trigger and can be configured for high or low active polarity.    You can configure both the pulse width (time between first assertion and deassertion edges) and pulse delay (time between a trigger and first assertion edge) in microseconds from 10 μs to 4,294,967,295 μs.  With this configuration, you can also access the isolated voltage line either through an isolated input to source an output device or as a digital output to source currents to an external load.  In order to prevent damaging the CVS-1450 device, do not apply voltages greater than 30 VDC to the isolated inputs and do not draw more than 100 mA from 24V or 30V isolated outputs or 50mA from 5V isolated outputs.  Further information including circuit diagrams can be found in the CVS User Manual.

Trigger Camera and Strobe Light from CVS

This extension of the previous configuration allows for the CVS to send a trigger to the camera and a light controller for more control over timing parameters.

Hardware Setup

The configuration is similar to that described previously, however now you can also connect another TTL or Viso output line to a light source.  As shown in the figure, another of these output lines is used to strobe a light.

Hardware setup to 1) Senor triggers CVS, 2) CVS sends trigger pulse to camera and light source, and 3) Camera sends image to CVS.
Figure 12. Hardware setup to 1) Senor triggers CVS, 2) CVS sends trigger pulse to camera and light source, and 3) Camera sends image to CVS.

Software Setup

This setup is similar to the first two configurations described except now code must be added to configure a second timed pulse line.  This action can be performed either by adding additional elements to the IMAQ I/O Read/Write Control, as shown below, or adding a second Read/Write Control. 
 

Configure two output pulses to be sent after single trigger.
Figure 13. A single Read/Write Control can be used to configure the FPGA to output two pulses.

When the code in Figure 13. is executed the FPGA is configured to output a pulse on both the TRIG 1 and the TRIG 2 lines for each rising edge on the ISO Input 8 line.

Notice that in Figure 13. the pulse delay and width for TRIG 2, which is connected to your light controller, is 10 µS and 2000 µS respectively. In order to compensate for underexposure, trigger latency, and ramp up required for full illumination of your light source, you should trigger the light source earlier and for a longer duration (i.e. shorter delay and larger pulse width).  For this configuration, also ensure that the trigger source for each pulse is the same. 

Use Cases

Besides being applicable to the previous cases, this setup ensures that the light source will be on during the duration of exposure time.  If the inspected object is moving quickly, the strobe light will reduce blurring effects by shortening the exposure time.  To ensure that the light is on during the entire exposure time; it is important to also account for light ramp-up time.

Conclusion

Since the IEEE 1394 bus does not have the capabilities to directly trigger a camera, the signal must be sent through hardware either directly to the camera or through the Compact Vision System (CVS).  This document described how to trigger a camera directly as well as using the FPGA functionality on the CVS to achieve deterministic timing for multiple triggers.  The concepts in this document can also be extended for use with the PCI-8254R, PCIe-8254R and PCIe-8255R as these devices have both an IEEE 1394 interface and FPGA like the CVS.

1 ratings | 4.00 out of 5
Print

Reader Comments | Submit a comment »

 

Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).