Documentation

CAN Bit-Unpacking

CAN Bit-Unpacking block (not recommended)

Library

Simulink® Real-Time™ Library of Drivers No Longer Recommended for Use.

To open this library, type xpcobsoletelib in the Command Window.

Description

This block is for message data of type double. This block extracts CAN data frames, and its input port is normally connected to an output port of a CAN Receive driver block. The block has one input port of data type double (a scalar). This port represents the data frame entity from which the signals are extracted and leaving the block at its output ports. The number of output ports and the data type of each output port depend on the settings in the block dialog box.

Do not use this block to unpack CAN_MESSAGE data types or to process a remote frame. Use the CAN Unpack block.

Block Parameters

Bit Patterns

Lets you define the bit patterns in a flexible way. The data type entered in the control must be a MATLAB® cell array vector. The number of elements in the cell array define the number of output ports shown by this block instance. The cell array elements must be of type double array and define the position of each bit of the incoming value (data typed output port) in the incoming double value (data frame).

Data Types

From a data type perspective (output ports), the block behaves like a Simulink Source block, and therefore the data types of the output ports must be defined in the second control (edit field). The data type entered in that control must be a MATLAB cell array vector of the same length as the bit pattern cell array. The cell array elements must be of type char and define the data type of the corresponding output port. The following values are supported:

boolean, int8, uint8, int16, uint16, int32, uint32

The sample time of the block is inherited from the driving block. Therefore you do not need to provide an explicit sample time in the block dialog box.

If you unpack the data frame into a signed type (int8, int16, or int32), the block performs sign extension. For example, if the bit pattern is [0:4], and the data type is int8, you are extracting 5 bits into an 8 bit wide signed type. In this case, bits 5, 6, and 7 are the same as bit 4, resulting in sign extension. This functionality enables you to pack and unpack negative numbers without losing precision. In the preceding example, you can pack and unpack numbers in the range [-16:15] (a fictitious int5 type).

Example

The example in this topic describes the use of the Softing® CAN blocks with standard double data types for message storage. For an alternative and easier way to unpack CAN_MESSAGE data types, use the CAN Unpack block.

The example in the CAN Bit-Packing shows the transmission of a data frame to an external CAN node. In this case, an external CAN node sends the data frame and the real-time application running on a target computer receives it. Therefore, you use the CAN Bit-Unpacking block to extract the various data fields from the entire data frame. Because the bit pattern definitions of the packing and unpacking block are symmetric, the bit pattern definition could look the same. You do not need to extract byte 2 (reserved area), because its content is known. The bit pattern edit field can therefore look as follows:

{ [0:7] , [15:-1:8] , [25] , [-1,-1,26:31] , [32:47] }

and the data type edit field as

{ 'uint8' , 'uint8' , 'boolean' , 'int8' , 'int16' }

These requirements result in the following Simulink model.

Often it makes sense to test the bit-packing and unpacking operations in a Simulink model (simulation) before building the real-time application. Both blocks work the same way either in the Simulink system or the generated code. By combining the two models shown so far, a third model emerges that can be used to simulate the behavior.

Introduced before R2006a

Was this topic helpful?