Embedded Target for Motorola MPC555 |
 |
CAN Message Packing (CANdb)
Pack Simulink double signals into CAN messages
Library
CAN Message Blocks
Description

The CAN Message Packing (CANdb) block gives you control over the packing of Simulink double signals into a CAN message. You can specify the scaling and offset of individual input signals and how many bits the signal will take up in the message.
Dialog Box

There are four panels to the CAN Message Packing (CANdb) dialog box.
Data Source Panel
Specify whether you want to define the message composition manually, or retrieve a message composition specification from a CANdb database. CANdb is a standard controlled by Vector-Informatik. To use CANdb you need to purchase a copy of CANdb from Vector-Informatik.
The software cannot read the CANdb format file directly. Instead you must export the file from CANdb as a DBASE (.dbf)
format file and place it in your working directory.
- Define signals by hand
- When you select Define signals by hand, the Message, Message Signals, and Signal Editor panels are activated. You can then edit the message characteristics manually.
- Use file exported from CANdb
- Select this option if you want to retrieve a message composition specification from a CANdb database. Before using this feature, you must configure an ODBC data source and locate your database files in the MATLAB work directory. The procedure for doing this is given in Configuring the ODBC Data Source for CANdb Blocks.
- When you select Use file exported from CANdb, the Browse... button and .DBF file field become active. You can then select a database file by browsing for it or by entering the file name in the .DBF file field. After you have selected a database file, the CAN message identifier menu displays a list of available messages (by identifier) in the database. Select the desired message.
Message Panel
This panel contains information that applies to the whole message.
- Name
- Name of the message
- Identifier (hex)
- The hexidecimal number that identifies the message on the CAN bus.
- Length
- Length of the message, in bytes
- CAN message type
- Select either
Standard(11-bit identifier)
or Extended(29-bit identifier)
.
Message Signals Panel
Provides a display-only list of information for each input signal to be packed into the message. The signal parameters displayed in this list are described in the Signal Editor Panel section below.
In addition to the list of signals, this panel contains three buttons:
- The New button lets you create a signal, which you can then edit in the Signal Editor.
- The Edit button activates the Signal Editor panel. This panel lets you edit the parameters of the selected signal.
- The Delete button lets you delete a signal.
The List signals for mode menu lets you restrict the list of signals to display only those signals with a given mode value. (See Type and Mode). By default, the mode is set to display all signals regardless of mode value. Note that when displaying signals for a specific mode, the Signal Editor panel is disabled.
The Port# column displays the number of each input signal. The number indicates the order in which the signals enter the Simulink block, from top to bottom.
The other columns display properties described in Signal Editor Panel.
Signal Editor Panel
Lets you enter or change parameter values for the selected signal. To edit a signal, select it in the Message Signals Panel, and then press the Edit button. The Signal Editor panel will become active. After you have made the required changes to the signal click OK to commit your changes. Click Cancel to finish editing without retaining changes.
Each parameter is described briefly here. Each signal is defined according to the CANdb standard; refer to your CANdb documentation for detailed information.
- Name
- The name of the signal that you see displayed in the CANdb and on the Simulink block.
- Start bit
- The bit position, in the data bytes, where the signal is inserted.
- Length (bits)
- The number of bits to be used in the message
- Type and Mode
- More than one signal can be mapped to the same location in a message. To determine which message is actually mapped, you can define at most one mode signal. The mode signal is an integer valued input. You can then define as many mode dependent signals as you want. A mode dependent signal also makes use of the Mode value. The Mode value is matched against the mode signal. If the Mode value equals the value of the mode signal then the signal is packed into the message. If it does not match then the signal is ignored.
- Mode
- See Type and Mode above.
- Data type
- This menu allows you to specify whether the bits allocated to a signal are interpreted as a signed (two's complement) or unsigned integer. For example, consider a 3-bit signal where all bits are set to 1. If the signal is interpreted as signed, it would represent the value -1 before scaling and offsetting. If the signal is interpreted as unsigned, it would represent the value 7 (
0x7h
) before scaling and offsetting.
- Byte order
- Select one of the following options:
Big Endian (Motorola)
: the start bit is the least significant bit of the least significant byte from the end of the message. Bytes are counted left from here.
Little Endian (Intel)
: the start bit is the least significant bit of the least significant byte from the beginning of the message. Bytes are counted right from here.
- The CAN Message Packing (CANdb) block uses Motorola Backwards big endian format, which is the default for CANdb. It does not uses Motorola Forwards big endian format, which is the default for CANdb++.
- For more detailed descriptions of byte layout, see your CANdb documentation.
- Factor and Offset
- Define the Factor and Offset values in the formula for conversion between the physical value (Simulink signal value) and the data stored in the packet. The conversion formula is defined as
Phys_value = (Raw_value - Offset) / Factor
Where Raw_value is the value stored in the packet. Note that the Raw_value may be signed or unsigned depending on the Data type.
- Units
This field is informational only. If desired, enter the appropriate units for the signal.
Configuring the ODBC Data Source for CANdb Blocks
The CAN Message Packing (CANdb) and CAN Message Unpacking (CANdb) blocks let you retrieve a message composition specification from a CANdb database. To use this feature, you must configure an ODBC data source, specifying the MATLAB work directory as the location for database files.
To configure the data source:
- Locate the MATLAB work directory. At the MATLAB prompt, type
- The command returns the path to
matlabroot
/work
, for example:
Note this path for use in Step 7.
- From the Start menu, open
Settings/Control Pane/Administrative Tools/Data Sources (ODBC).
- The ODBC Data Sources Administrator window opens. Click the User DSN tab.
- Click the Add... button. The Create New Data Source dialog box opens. Select
Microsoft dBase Driver (*.dbf)
from the list of drivers. Then click Finish.
- The ODBC dBase Setup dialog box opens. Enter
dBase Sources for CAN
in the Data Source Name field. You must use this exact name.
- Clear the Use Current Directory check box.
- Click the Select Directory button and navigate to the MATLAB work directory that you located in Step 1. Click OK.
- The path to the MATLAB work directory should now appear on the ODBC dBase Setup dialog box. Click OK to dismiss the ODBC dBase Setup dialog box.
- Click OK to complete ODBC dBase Setup. Then click OK to close the ODBC Data Sources Administrator window.
- Place the DBF files you want to work with in the MATLAB work directory. You can then use the Use file exported from CANdb option to access the CANdb information by using the CANdb blocks.
| CAN Message Packing | | CAN Message Unpacking |  |