CAN Pack
Purpose
Generate a CAN message from input signals
Library
Communication
Description
The CAN Pack block takes PLECS signals as inputs and generates a CAN message. The signal definitions can optionally be imported from a dbc (data base CAN) file.
Signal specification
A signal in a CAN message is defined by its data type, its byte order (Little Endian / Big Endian) and its start bit and length within the 64 bit CAN message. A signal can be scaled and an offset can be applied to efficiently send floating point signals as integers. The bits within the CAN message are numbered from 0 (least significant bit of the first byte) to 63 (most significant bit of the last byte).
The following Types are supported in a signal definition:
- bool
A single bit (length 1) with signal values 0 or 1.
- unsigned
An unsigned integer value of variable length (2 to 32 bits).
- signed
A signed integer value of variable length (2 to 32 bits).
- float
A floating point value according to IEEE 754, 32 bit length.
- double
A floating point value according to IEEE 754, 64 bit length.
The Byte Order specifies the order in which bytes are sent for multi-byte messages. With Little Endian (or Intel) byte order the least significant byte (LSB) is transferred first. With Big Endian (or Motorola) byte order the most significant byte is transferred first.
To ensure compatibility with the dbc file format, the byte order also has an impact on the counting direction of the bits of a signal within a CAN message. For little endian signals, the Start bit specifies the position of the most significant bit in the CAN message. The bits within a byte are counted upwards. For big endian signals, the start bit specifies the position of the least significant bit. The bits within a byte are counted down. The bytes of a signal are always counted upwards.
Example
An unsigned signal of length 8 and start bit 12 in little endian encoding is composed of bits 12-15 and 16-19 of the CAN message. The most significant bit is placed in bit 19, the least significant bit in bit 12.
Little Endian signal specification (Start bit: 12, length: 8)
The same signal in big endian encoding is composed of bits 8-12 and 21-23 of the CAN message. The most significant bit is placed in bit 12, the least significant bit in bit 21.
Big Endian signal specification (Start bit: 12, length: 8)
Scale and Offset are applied to the signals specified in the CAN message to adjust them to their value range within PLECS:
Min and Max are lower and upper bounds for the signal in PLECS.
The Unit and Comment field can be used for documentation purposes.
Parameters
- CAN ID
The ID of the CAN message. The id terminal of the block must be connected to the id terminal of the CAN Transmit block to use this parameter in the generated CAN message.