CAN database decoding and numbering

Importing eDAQ CAN databases has shown need for informing users of byte order, decoding and numbering schemes.

Byte and bit numbering

CAN messages contain from 0 to 8 data bytes, and thus from 0 to 64 bits.

Byte numbering

The data bytes are always numbered 0, 1, ..., 7 in the order they are transmitted:

Bit Numbering

The CAN specification (ISO 11898-1) specifies that multi-bit fields in a CAN frame, including data bytes, are always transmitted most-significant bit first. When it is necessary to number the up to 64 possible data bits in a CAN message, two different systems are used: Standard, sequential and reverse bit numbering.

Standard (or Sawtooth) Bit Numbering

In standard (sometimes also called "sawtooth") bit numbering, bits within a byte are numbered in ascending order of significance. This results in a sawtooth pattern when viewing the bits in transmission order.

  Transmission Order →
  MSB   LSB
Data Byte
0
7 6 5 4 3 2 1 0
Data Byte
1
15 14 13 12 11 10 9 8
  ... ... ... ... ... ... ... ...
Data Byte
7
63 62 61 60 59 58 57 56

MSB = Most Significant Bit, LSB=Least Significant Bit.

Sequential Bit Numbering

In sequential bit numbering, bits are numbered in transmission order. Thus, within a given byte, lower-numbered bits are more significant and higher-numbered bits are less significant.

  Transmission Order →
  MSB   LSB
Data Byte
0
0 1 2 3 4 5 6 7
Data Byte
1
8 9 10 11 12 13 14 15
  ... ... ... ... ... ... ... ...
Data Byte
7
56 57 58 59 60 61 62 63

MSB = Most Significant Bit, LSB=Least Significant Bit.

Reverse Bit Numbering

In reverse bit numbering, bits are numbered in reverse transmission order: the reverse number of a bit is the difference between 63 and the sequential bit number.

  Transmission Order →
  MSB   LSB
Data Byte
0
63 62 61 60 59 58 57 56
Data Byte
1
55 54 53 52 51 50 49 48
  ... ... ... ... ... ... ... ...
Data Byte
7
7 6 5 4 3 2 1 0

MSB = Most Significant Bit, LSB=Least Significant Bit.

Byte Ordering

As already stated, the CAN specification (ISO 11898-1) specifies that multi-bit fields in a CAN frame, including data bytes, are always transmitted most-significant bit first. However, there are two ways to encode signal values which span multiple adjacent data bytes: Motorola and Intel byte ordering.

Motorola Byte Ordering

In Motorola byte ordering, encoded signal value bits appearing in earlier-transmitted (lower-numbered) bytes are more significant than bits appearing in later-transmitted (higher-numbered) bytes. The following examples show the significance (binary weight) of each bit in a series of Motorola encoding examples.

  Transmission Order →                                
  Data Byte 0                 Data Byte 1              
4-bit signal, unaligned     23 22 21 20                      
8-bit signal, aligned 27 26 25 24 23 22 21 20                  
8-bit signal, unaligned         27 26 25 24   23 22 21 20        
12-bit signal, right-aligned         211 210 29 28   27 26 25 24 23 22 21 20
12-bit signal, left-aligned 211 210 29 28 27 26 25 24   23 22 21 20        
16-bit signal, aligned 215 214 213 212 211 210 29 28   27 26 25 24 23 22 21 20

Yellow-highlighted cells indicate bits that are part of a signal's encoded value.

Intel Byte Ordering

In Intel byte ordering, encoded signal value bits appearing in earlier-transmitted (lower-numbered) bytes are less significant than bits appearing in later-transmitted (higher-numbered) bytes. The following examples show the significance (binary weight) of each bit in a series of Intel encoding examples.

  Transmission Order →                                
  Data Byte 0                 Data Byte 1              
4-bit signal, unaligned     23 22 21 20                      
8-bit signal, aligned 27 26 25 24 23 22 21 20                  
8-bit signal, unaligned 23 22 21 20                   27 26 25 24
12-bit signal, right-aligned 23 22 21 20           211 210 29 28 27 26 25 24
12-bit signal, left-aligned 27 26 25 24 23 22 21 20           211 210 29 28
16-bit signal, aligned 27 26 25 24 23 22 21 20   215 214 213 212 211 210 29 28

Yellow-highlighted cells indicate bits that are part of a signal's encoded value.

Specifying a Signal

In order to decode a signal's value from a CAN message, the position of the encoded bits and the format of those bits must be unambiguously known. This is usually accomplished by a combination of three parameters: one to specify the position according to some scheme; one to specify the total number of bits; and one to specify the format of the bits. Unfortunately, the scheme used to specify the position differs significantly from system to system. VECTOR names the following six schemes:

Motorola Signal Schemes

  • Motorola Forward LSB - The standard bit number of the least-significant bit is specified.
  • Motorola Forward MSB - The standard bit number of the most-significant bit is specified.
  • Motorola Sequential - The sequential bit number of the most-significant bit is specified.
  • Motorola Backward - The reverse bit number of the least-significant bit is specified.
  Transmission Order →                                          
  Data Byte 0                 Data Byte 1                        
Sequential Bit Number 0 1 2 3 4 5 6 7   8 9 10 11 12 13 14 15   Signal Position      
Sawtooth Bit Number 7 6 5 4 3 2 1 0   15 14 13 12 11 10 9 8          
Reverse Bit Number 63 62 61 60 59 58 57 56   55 54 53 52 51 50 49 48   Forward LSB Forward MSB Sequential Backward
4-bit signal, unaligned     23 22 21 20                         2 5 2 58
8-bit signal, aligned 27 26 25 24 23 22 21 20                     0 7 0 56
8-bit signal, unaligned         27 26 25 24   23 22 21 20           12 3 4 52
12-bit signal, right-aligned         211 210 29 28   27 26 25 24 23 22 21 20   8 3 4 48
12-bit signal, left-aligned 211 210 29 28 27 26 25 24   23 22 21 20           12 7 0 52
16-bit signal, aligned 215 214 213 212 211 210 29 28   27 26 25 24 23 22 21 20   8 7 0 48

MSB = Most Significant Bit, LSB=Least Significant Bit. Yellow-highlighted cells indicate bits that are part of a signal's encoded value.

Intel Signal Schemes

  • Intel Standard - The standard bit number of the least-significant bit is specified.
  • Intel Sequential - The sequential bit number of the least-significant bit is specified.
  Transmission Order →                                      
  Data Byte 0                 Data Byte 1                 Signal Position  
Sequential Bit Number 0 1 2 3 4 5 6 7   8 9 10 11 12 13 14 15      
Sawtooth Bit Number 7 6 5 4 3 2 1 0   15 14 13 12 11 10 9 8   Standard Sequential
4-bit signal, unaligned     23 22 21 20                         2 5
8-bit signal, aligned 27 26 25 24 23 22 21 20                     0 7
8-bit signal, unaligned 23 22 21 20                   27 26 25 24   4 3
12-bit signal, right-aligned 23 22 21 20           211 210 29 28 27 26 25 24   4 3
12-bit signal, left-aligned 27 26 25 24 23 22 21 20           211 210 29 28   0 7
16-bit signal, aligned 27 26 25 24 23 22 21 20   215 214 213 212 211 210 29 28   0 7

MSB = Most Significant Bit, LSB=Least Significant Bit. Yellow-highlighted cells indicate bits that are part of a signal's encoded value.

eDAQXR Setup Files (SXR) and VECTOR DBC Database Files (DBC)

CAN signals in eDAQXR setup files are specified using three parameters:

  • db_bit_start specifies the standard bit number of:
    • for Motorola signals, the most significant bit; this is equivalent to the Motorola Forward MSB position.
    • for Intel signals, the least significant bit; this is equivalent to the Intel Standard position.
  • db_bit_length specifies the total number of bits in the encoded signal value.
  • db_data_format specifies the layout of the bits in the encoded signal value:
    • xMSB specifies Motorola byte ordering.
    • xLSB specifies Intel byte ordering.
    • Uxxx specifies unsigned integer encoding.
    • Sxxx specifies signed integer encoding; the most-significant bit is replaced by a sign bit.
    • Fxxx specifies IEEE 754 floating-point encoding; the db_bit_length must be either 32 or 64.

In VECTOR DBC database files, the reckoning of a signal's position and length is identical to that of the eDAQXR (Motorola Forward MSB and Intel Standard are used).

Examples

  Transmission Order →                                        
  Data Byte 0                   Data Byte 1                  db_bit_start  db_bit_length
Motorola Standard Numbering 7 6 5 4 3 2 1 0   15 14 13 12 11 10 9 8      
  4-bit signal, unaligned     23 22 21 20                         5 4
  8-bit signal, aligned 27 26 25 24 23 22 21 20                     7 8
  8-bit signal, unaligned         27 26 25 24   23 22 21 20           3 8
  12-bit signal, right-aligned         211 210 29 28   27 26 25 24 23 22 21 20   3 12
  12-bit signal, left-aligned 211 210 29 28 27 26 25 24   23 22 21 20           7 12
  16-bit signal, aligned 215 214 213 212 211 210 29 28   27 26 25 24 23 22 21 20   7 16
Intel Standard Numbering 7 6 5 4 3 2 1 0   15 14 13 12 11 10 9 8      
  4-bit signal, unaligned     23 22 21 20                         2 4
  8-bit signal, aligned 27 26 25 24 23 22 21 20                     0 8
  8-bit signal, unaligned 23 22 21 20                   27 26 25 24   4 8
  12-bit signal, right-aligned 23 22 21 20           211 210 29 28 27 26 25 24   4 12
  12-bit signal, left-aligned 27 26 25 24 23 22 21 20           211 210 29 28   0 12
  16-bit signal, aligned 27 26 25 24 23 22 21 20   215 214 213 212 211 210 29 28   0 16

MSB = Most Significant Bit, LSB=Least Significant Bit. Yellow-highlighted cells indicate bits that are part of a signal's encoded value. Blue-highlighted cells show which bit is identified by the "start bit" / "bit position" parameter.

eDAQ Database Files (TXT)

CAN signals in Vector DBC database files are specified using five parameters:

  • The bitpos specifies the sequential bit number, plus an offset (see below) ofof,
    • for Motorola signals, the most significant bit; this is equivalent to the Motorola Sequential position.
    • for Intel signals, the bit following the last-transmitted bit, minus the signal length.
      • For signals which have whole-byte sizes (8, 16, ..., 64), this is equivalent to the position of the first-transmitted bit.
      • For signals which have fractional-byte sizes, this is equivalent to the position of the first-transmitted bit plus the number of fractional bits minus one.
    • for 11-bit CAN messages, an offset of 16 is applied, so that the first-transmitted data bit has a bitpos of 16 and the last has a bitpos of 80.
    • for 29-bit CAN messages, an offset of 32 is applied, so that the first-transmitted data bit has a bitpos of 32 and the last has a bitpos of 96.
  • The bitlength specifies the total number of bits in the encoded signal value.
  • The dataformat specifies the layout of the bits in the encoded signal value:
    • xMSB specifies Motorola byte ordering.
    • xLSB specifies Intel byte ordering.
    • Uxxx specifies unsigned integer encoding.
    • Sxxx specifies signed integer encoding; the most-significant bit is replaced by a sign bit.
    • Fxxx specifies IEEE 754 floating-point encoding; the db_bit_length must be either 32 or 64.

Examples

In these examples, we assume 11-bit CAN messages with a bitpos offset of 16. For 29-bit CAN messages, the bitpos of each example should be increased by a further 16.

  Transmission Order →                                        
  Data Byte 0                   Data Byte 1                  bitpos  bitlength
Motorola Sequential Numbering with +16 Offset 16 17 18 19 20 21 22 23   24 25 26 27 28 29 30 31      
  4-bit signal, unaligned     23 22 21 20                         18 4
  8-bit signal, aligned 27 26 25 24 23 22 21 20                     16 8
  8-bit signal, unaligned         27 26 25 24   23 22 21 20           20 8
  12-bit signal, right-aligned         211 210 29 28   27 26 25 24 23 22 21 20   20 12
  12-bit signal, left-aligned 211 210 29 28 27 26 25 24   23 22 21 20           16 12
  16-bit signal, aligned 215 214 213 212 211 210 29 28   27 26 25 24 23 22 21 20   16 16
Intel Sequential Numbering with +16 Offset 16 17 18 19 20 21 22 23   24 25 26 27 28 29 30 31      
  4-bit signal, unaligned     23 22 21 20                         18 4
  8-bit signal, aligned 27 26 25 24 23 22 21 20                     16 8
  8-bit signal, unaligned 23 22 21 20                   27 26 25 24   Not Supported Not Supported
  12-bit signal, right-aligned 23 22 21 20           211 210 29 28 27 26 25 24   Not Supported Not Supported
  12-bit signal, left-aligned 27 26 25 24 23 22 21 20           211 210 29 28   20 12
  16-bit signal, aligned 27 26 25 24 23 22 21 20   215 214 213 212 211 210 29 28   16 16

Red-highlighted "8-bit unaligned" and "12-bit right-aligned" example signals are not supported by the legacy eDAQ because their least-significant bits do not coincide with the least-significant bit of the data byte. Yellow-highlighted cells indicate bits that are part of a signal's encoded value. Blue-highlighted cells show which bit is identified by the "start bit" / "bit position" parameter.