The data packet containing the information needed to control a decoder
- 1 A Digital Command Control Packet
- 2 Structure of a DCC Data Packet
- 3 Special Commands
- 4 Data Rate
- 5 See Also
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.
- Preamble -- Tells all decoders a data packet is about to start.
- Address -- This sequence of bits contains the address of the decoder the packet it meant for.
- Instruction -- The command that is being sent to the addressed decoder.
- 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.
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.
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.
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.
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.
Putting It All Together
A complete data packet might look like this:
- 1111111111 0 0AAAAAAA 0 01DUSSSS 0 EEEEEEEE 1
AAAAAAA 0 = Address. The trailing zero (MSB) can be for the headlight.
DCC Packet Construction
0 = Headlight
|XORed address and data bytes|
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.
There are a couple of special commands that can be transmitted.
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.
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.
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.
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.
- For more information, refer to some of books on the Resources page.
Try the Wayback Machine here: [DCC Packets]