CAN Output

CompactRIO Reference and Procedures (FPGA Interface)

Edition Date: June 2010

Part Number: 370984T-01

»View Product Info

Write a CAN frame to be transmitted.

Complete the following steps to write to a CAN port using CAN Output.

  1. Use the Add Targets and Devices dialog box to add the CAN module to your CompactRIO configuration. Right-click the CAN module in the Project Explorer window and select Properties to specify the configuration properties for the module.
  2. Create an FPGA I/O item for CAN by right-clicking the FPGA target under My Computer in the Project Explorer window, selecting New»FPGA I/O, and then adding CAN»NI 9852»CAN0 (or CAN»NI 9853»CAN0) and/or CAN»NI 9852»CAN1 (or CAN»NI 9853»CAN1) to the FPGA I/O list. Refer to New FPGA I/O dialog box (FPGA Module) for more information about creating and adding FPGA I/O to your CompactRIO configuration.
  3. Place an I/O Node from the FPGA I/O palette onto your FPGA VI diagram.
  4. Right-click the I/O Node and select Select FPGA I/O»CAN»NI 9852»CAN0 (or Select FPGA I/O»CAN»NI 9853»CAN0) or Select FPGA I/O»CAN»NI 9852»CAN1 (or Select FPGA I/O»CAN»NI 9853»CAN1).
  5. Right-click the I/O Node and select Change to Write to use the I/O node for CAN Output.
  6. Right-click the I/O Node and choose Properties to select the Data Type.

Start communication on the CAN port prior to using CAN Output. Enable Auto Start in the Module Configuration, or invoking the Start method to start communication.

The communication path from LabVIEW FPGA to the CAN port on the module is implemented as a FIFO. The CAN Output node waits for an available element in the FIFO, then writes the frame to the FIFO. If no other CAN frame exists in the FIFO, the CAN frame will begin to transmit immediately.

CAN Output does not wait for the requested transmit to complete on the network (acknowledgement). Call CAN Output followed by Wait on Transmit Complete (I/O Method) if you want to transmit CAN frames one at a time.

Write multiple frames to the output FIFO if you want to transmit CAN frames as fast as possible. The CAN module will submit these frames to the SJA1000 controller as fast as possible, thus generating close to 100% busload.

When the output FIFO is full, the CAN Output node waits for an element to become available, then writes the frame to the FIFO. The Output Timeout (ms) of the CAN Advanced Port Configuration dialog box specifies how long to wait for a new element to become available, which occurs when a frame from a previous CAN Output transmits successfully onto the network. If you specify Output Timeout (ms) of 0, the CAN Output node returns an error status of TRUE (error) if a new element is not available (non-blocking). When an error is returned, you must attempt CAN Output of the same frame again at a later time.

In addition to the CAN Output node, the Output Timeout (ms) also applies to most methods and properties. For example, if Output Timeout (ms) is 0, the Abort Transmit method will return an error if the output FIFO is full. For more information on the output path from LabVIEW FPGA to the CAN port, refer to Arbitration.

Note  You can add more than one CAN output port to the FPGA I/O node, and also add analog and digital outputs to the same FPGA I/O node by right-clicking the FPGA I/O node and selecting Add Element. Right-click the created I/O name and select Select FPGA I/O to specify the I/O name. If you use more than one output per node, LabVIEW will execute them sequentially starting with the top output. If one output is blocked while waiting for the output, subsequent outputs will be delayed.

Properties Dialog

Selects the Data Type for the CAN frame written to the CAN Input node. The available values are Cluster (default) and Array of 6 U32.

The benefits of using the Cluster data type are:

  • Simpler block diagram (easy to use)
  • Fast and efficient, if you limit use to the block diagram only (not front panel)

The benefits of the Array of 6 U32 data type, and handshaking integers to the host VI one at a time, are:

  • Faster for transfer to/from host VI
  • Fewer FPGA gates

Refer to the Using Clusters and Arrays in LabVIEW FPGA Application Note for more information on the use of clusters and arrays. Refer to the CAN examples in NI 9852/NI 9853 Related Documentation and Examples for examples using each data type.

Node Inputs

Error In

Optional. Not shown by default. Right-click the node and select Error Terminals to enable.

CANx

If the Data Type is defined as Cluster (default), the CAN frame is represented as a cluster with the following elements:

Timestamp High
Ignored. The transmit request always occurs as soon as possible (not timed).
Timestamp Low
Ignored. The transmit request always occurs as soon as possible (not timed).
Identifier

Arbitration ID.

If bit 29 (20000000 hexadecimal) is clear, this ID uses the standard format (11-bit). If bit 29 is set, this ID uses extended format (29-bit).

This representation of the CAN identifier is the same as NI-CAN (see NI 9852/NI 9853 Related Documentation and Examples).

Type
Type of frame:
Data Frame0
Remote Frame1
InfoA

Reserved for future use.

InfoB

Reserved for future use.

Data Length

For data frames, this indicates the number of bytes in Data (0–8).

For remote frames, this indicates the number of bytes requested.

Data

For data frames, this provides the data bytes. The array uses a fixed size of 8 bytes.

If the Data Type is defined as Array of 6 U32, the CAN frame is represented as the following array of 6 U32 values:
Most significant byte ... ... Least significant byte
Timestamp (upper U32)
Timestamp (lower U32)
Identifier
Type InfoA InfoB DataLength
Data[0] Data[1] Data[2] Data[3]
Data[4] Data[5] Data[6] Data[7]

The meaning of each element is the same as the Cluster data type.

Node Outputs

Error Out

Optional. Not shown by default. Right-click the node and select Error Terminals to enable.

Unless you set the Output Timeout (ms) to -1 to wait indefinitely, you must use the error terminals to determine whether the CAN Output successfully submitted a CAN frame for transmit.

WAS THIS ARTICLE HELPFUL?

Not Helpful