Digital packet

DCCWiki, a community DCC encyclopedia.
(Redirected from Packet)

Short Definition

The data packet containing the information needed to control a decoder

A Digital Command Control Packet

A packet is a bundle of data sent over the wires or rails in the case of model railroading. The concept is similar to sending a message via email.

A data packet is made of up Binary digITs, or 'BITS'. A group of eight bits is referred to as a byte. A word is typically two bytes or sixteen bits. Bytes can be split into nibbles (four bit units),which represent numbers between zero and fifteen. To make them easier to read nibbles are often represented by hexademical (base 16) numbers, from zero to F. A byte can represent 256 values from $00 to $FF

In the model railroading control system called Digital Command Control, packets are made up of several "words", and most words are one or two bytes long.

Structure of a DCC Data Packet

The DCC data packet consists of a preamble, the address and instruction, followed by the post amble. The most common packets are four-word bundles.

BipolarWaveform2.png

  1. Preamble -- Tells all decoders a data packet is about to start.
  2. Address -- This sequence of bits contains the address of the decoder the packet it meant for.
  3. Instruction -- The command that is being sent to the addressed decoder.
  4. Error Detection -- This allows the decoder to check that the packet is valid, and if it is corrupted, the decoder will just ignore the packet and wait for the next pramble.
A DCC Waveform on the rails.

Preamble

The Preamble is a string of twelve "ONE" (or HIGH) bits as specified in the NMRA DCC standard, which tells every device listening on that a new packet is starting. No other DCC command can or will consist of a string of twelve ones.

Address Bytes

The Address alerts the device the message is intended for, usually a decoder, or a consist (two or more locomotive decoders). It also tells all other devices to ignore this packet. The address can be one or two bytes in size. A two digit address is represented by a single byte, and two bytes are used for a four digit address. A decoder set for two digit addresses will ignore a two byte address. This allows compatibility with older systems that may not have four digit capability. If the address does not match the decoder, the decoder will simply ignore the data and wait for the next preamble to be transmitted.

Instruction Bytes

The Instruction byte tells the device to set a function (light, bell, whistle, horn, coupler, etc.) on or off, to change to a specified speed step, to reverse direction, to emergency stop, etc. Systems using 14 or 28 speed steps only need one byte for the instructions. For 128 speed steps, two bytes are required. The structure of the bytes differs to indicate the speed steps used.

Error Detection

The final byte indicates the packet is complete. It also allows the decoders to check the validity of the packet. If the packet is corrupted, a decoder looking at the final byte would find the checksum included is wrong. It would ignore the packet and wait for an uncorrupted one to arrive. (This is one reason why the command stations keep repeating the packets over time.) A corrupted packet most commonly occurs if dirty wheels or track prevented the whole packet from being read properly.

The command station applies an XOR function to the address and instruction bytes, and this is appended to the packet to create the error detection byte. The decoder can perform the same function and compare the result to the error detection byte.

Definitions

Extended Packet Format

NMRA Standard S-9.2.1

A Address Bit
0 Bit which has a value of 0
1 Bit which has a value of 1
U Undefined bit, 0 or 1 are valid states
B Bit position / Address
C Instruction type field
F Flag, determines Instruction Implementation
L Low Order Binary State Control Address
H High Order Binary State Control Address
S Sub address of decoder
V CV address bit
D Data
X Signal Head aspect bit
E Error detection bit

Bits are numbered from left to right, Bit 0 is the least significant bit (LSB), bit 7 is the Most significant bit (MSB)

Address Partitions

Address Values Decimal Value Purpose
00000000 0 Broadcast Address
00000001-01111111 1-127 Inclusive Multifunction decoders with a 7 bit address
10000000-10111111 128-191 inclusive Basic Stationary Decoders with 9 bit addresses and Extended stationary decoders with 11 bit addresses
11000000-11100111 192-231 inclusive Multifunction decoders with a 14 bit address
11101000-11111110 232-254 Reserved for future applications
11111111 255 Idle Packet

For extended addresses, a second byte will follow

Broadcast Address

Any instructions addressed to the broadcast address must be acted on. If the command is not supported the decoder can ignore it.

Instructions for Multifunction Decoders

Multifunction decoders are decoders intended to control one or more motors and/or accessories.

The first address byte contains 8 bits. if the most significant bits are 11 and the remaining bits are not 111111, a second address byte must follow. The MSB of the address is bit 5 of the first byte, bits 6 and 7 are 1 in this instance. When two bytes are present in address space, they must be separated by a 0 bit

Each Instruction is constructed using a 3 bit instruction type field preceding a 5 bit data field. The eight possible values are:

000 Decoder and Consist control instructions
001 Advanced operations
010 Speed and Direction for reverse operation
011 Speed and Direction for forward operation
100 Function Group 1
101 Function Group 2
110 Future use
111 CV Access Instruction

Accessory Decoder Packet Format

Basic Accessory Decoder Format

Preamble 0 10AAAAAA 0 1AAACDD 0 EEEEEEEE 1

Extended Accessory Decoder Packet Format

Preamble 0 10AAAAAA 0 0AAA0AA1 0 000XXXXX 0 EEEEEEEE 1

XXXXX is for a single head, a value of 00000 is an absolute stop aspect. Other values represent possible aspects as determined by the signalling system in use, and prototype being modelled.

Broadcast Commands

Basic
Preamble 0 10111111 0 1000CDDD 0 EEEEEEEE 1
Advanced
Preamble 0 10111111 0 00000111 0 000XXXXX 0 EEEEEEEE 1

Putting It All Together

DCC Packet Construction for a Multi Function Decoder with 7 bit Address

Preamble
Address
Data
Error Detection
Trailing Bit
1111111111 0 AAAAAAA0 0 01DUSSSS 0
EEEEEEEE
1
A= Address

0 = Headlight|

D=Direction

U=Undefined

S=Speed

XORed address and data bytes

AAAAAAA 0 = Address. The trailing zero (MSB) can be for the headlight.

Address Byte

A A A A A A A 0
LSB 2 3 4 5 6 7 MSB
Address Bits
Headlight

Data Byte

0
1
D
U
S
S
S
S
0
Start
(Optional: Accessory Control)
Direction
Undefined
LSB
2
3
4
Speed Bits
Steps
U
S
S
S
S
S
S
S
S
14
Undefined
LSB
2
3
MSB
-
-
-
-
28
LSB
2
3
4
MSB
-
-
-
-
128
Undefined
LSB
2
3
4
5
6
7
MSB

The 01 indicates the start of the data byte. D is Direction (bit 5), U is undefined. SSSS is the speed control. If in 28 step mode, U is used for the LSB. The 01 can also be used for accessory control, such as couplers, bells, etc. The Speed control in this example is 4 bits, for the optional 128 step mode, another 4 bits would be included. The 4 bits allow for the mandated 28 speed steps. All decoders can switch to 28 steps if the command station transmits them.

If SSSS equals zero, that is a STOP command. The eSTOP is 0001. Values from 2 to 16 are the the fourteen speed steps. In 28 step mode, the values would go from 2 to 30. In this case, stop is 00000, eStop is 00001, and the first step is 00010.

E is the Error Correction.

Special Commands

There are a couple of special commands that can be transmitted.

Reset Packet

The Reset Packet has an address and data value of zero and the XOR operation means an error byte of zero value.

This packet allows the Command Station to clear some of its previous instructions. These include speed and direction data from any decoders. Upon receiving a reset packet a mobile decoder must bring a moving locomotive to an immediate stop.

In practice reset packets are normally sent as part of the programming or start up procedures to clear and power a decoder prior to transmission of programming packets.

Idle Packet

An Idle packet differs from the reset packet in that the address byte is set to 7 High (1) states, and the data packet is all Low (0) States.

The idle packet is used to provide power to the track when there are no trains in motion, or no locomotives have been addressed.

E-Stop

The E-Stop command generates a broadcast packet (all decoders) which must be obeyed. Valid DCC data remains on the rails, meaning a runaway locomotive caused by the decoder switching to analog mode will remain in motion.

Data Rate

DCC packets are transmitted at the rate of approximately 8000 bits per second. The command station tries to use the bandwidth available as efficiently as possible.

Packets are prioritized by the command station to maximize the throughput.

Packets are only created and transmitted when the command station receives instructions to make a change. A locomotive running at a constant speed would not have any packets addressed to it unless the throttle was changed to increase or reduce speed, lights turned on or off, or in the case of sound, a button was pressed to blow the horn (or whistle). This reduces the amount of data traffic, which increases response. DCC systems can transmit hundreds of packets a second, which allows control of a large number of trains. A large amount of data traffic will negatively impact the responsiveness of your train.

A typical command station can queue up to 20 packets in the buffer, which are transmitted in sequence unless the system determines the need to transmit one packet sooner.

One application that hogs bandwidth is operating an analog locomotive on a DCC system.

See Also

  • For more information, refer to some of books on the Resources page.

Try the Wayback Machine here: [DCC Packets]