Digital Packet

DCCWiki, a community DCC encyclopedia.
Jump to: navigation, search

Summary: A DCC Digital Packet (or DCC Command Packet) is a defined group of signals. The technical term is a broadcast protocol as data is sent to all devices, with each decoder responsible to determine if it should take any actions based on that packet. Every packet consists of a minimum of 38 bits.

A Digital Command Control Packet

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 hexadecimal (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.

Example

These are examples of the data on the rails, presented in plain text for ease of understanding. These packets are continuously broadcast by the command station.

  1. L2499 FG2:,05,06,07,08
  2. L1600 FG2:,,,07,08
  3. L2499 FG2:,,,,
  4. L1600 FG2:,,,07,08
  5. L2499 S005F
  6. L1600 S040F
  • «Type»«Address» «Function Group» «functions»
  • «Type»«Address» «Speed Step and Direction»

So, Example #1 is a Locomotive packet, addressed to 2499, with instructions for Function Group 2, functions 5-8 are active.. In line 3 the functions are turned off.

Example 5 is addressed to locomotive address 1600, Speed = Step 40, and direction is Forward.

Structure of a Baseline DCC Data Packet


NMRA Standard File:NMRA s-9.2 communications standards 2004.pdf

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. [1]

A baseline packet has a length of three data bytes, separated by a 0 bit, those using the extended packet format may have a length between three and six bytes separated by a 0 bit.

{preamble} 0 [AAAAAAAA] 0 [DDDDDDDD] 0 [EEEEEEEE] 1

  1. Preamble – Tells all decoders a data packet is about to start.
  2. Address – A:This sequence of bits contains the address of the decoder the packet is meant for.
  3. Instruction – D:The command that is being sent to the addressed decoder.
  4. Error Detection – E: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 preamble.
A DCC Waveform on the rails.

Preamble

The Preamble is a sequence of '"ONE'" (or HIGH) bits as specified in the NMRA DCC standard, which tells every device listening that a new packet is starting. A decoder must not accept a sequence of less than 10 complete one bits as valid, or require more than 12 bits. Command stations must transmit a minimum of 14 full preamble bits. [2]

The bit count of the preamble can be an issue with RailCom. Some multifunction decoders expect more than the maximum of 12 bits, and will have problems if RailCom is in use.

Packet Start Bit

The Packet Start Bit is the first bit with a value of zero transmitted after a valid preamble. The Packet Start Bit terminates the preamble and indicates an Address Byte is following.[3]

Address Data Byte

The first data byte of the packet, consisting of eight bits of address information. Some addresses are reserved for special purposes. The first byte can also be an instruction byte in special cases. [4] The first bit of the address byte is considered the most significant bit. [5]

The Address alerts the device the message is intended for, usually a decoder, or a consist (two or more multifunction 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 a Primary (two-digit binary) address will ignore a two-byte address. This allows compatibility with older systems that may not have Extended (binary, 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.

Special Applications of the Address Byte

It is permissible to insert an instruction in place of the Address Byte. One such application is Service Mode Programming, as it does not rely on the Address when programming, unlike Ops Mode.

Data Start Bit

This is a single bit with a value of 0 which precedes the Data Byte

Data Bytes

The DATA byte tells the decoder to set a function (light, bell, whistle, horn, coupler, etc.) on or off, to change to a specified speed step, reverse direction, initiate an 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 first bit of the data byte is considered the most significant bit.

Error Detection

The final byte indicates the packet is complete. It also allows decoders to check the validity of the packet. 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 performs the same function, comparing the result to the error detection byte. If the calculated and transmitted values do not match, the data is corrupt.

If the packet is corrupted, the decoder would ignore the packet and wait for an uncorrupted one to arrive. This is why command stations keep repeating the packets over time. A corrupted packet often occurs if dirty wheels or track prevented the whole packet from being read properly.

Packet End Bit

This bit indicates the termination of the packet, and has a value of 1. It may also count as the preamble of the next packet, if there are no alternate command control protocols inserted between packets. The DCC bitstream must continue for an additional 26µS (minimum) after the packet end bit. [6]

Definitions

Baseline Packet

The Baseline Packets provide for the minimum interoperability between different systems. More complex packet formats supporting different types of decoders, additional functions, addresses and speeds are provided by the Extended Packet Format.

To meet the requirements of the Standard a command station must encode the operator's input in compliance with the Baseline packet, and multifunction decoders must recognise and provide suitable control in conformance with the structure of the baseline packet. Idle and Broadcast Stop Packets are optional for Command Stations, required for decoders.

Extended Packet Format

This is a common form of DCC Digital Packet. It allows for more complex instructions including 28/128 Speed Steps Main Article:

Main article: Digital Packet/DCC Extended Packet

NMRA Standard S-9.2.1

Extended Packet Format
{preamble} 0 AAAAAAAA 0 {Instruction Bytes} 0 EEEEEEEE 1
Address Instructions Error

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. When two bytes are present in address space, they must be separated by a 0 bit.

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 motors and multiple additional functions. Each Instruction is constructed using a 3-bit instruction 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 signal 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 Multifunction 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

If this byte is in the range of 192-231, a second byte will follow.

Data Byte

Baseline Packet, Speed Instructions:

0 1 D C S3 S2 S1 S0 0
Start



(Optional: Accessory Control)
Direction Undefined LSB 2 3 4

Extended Packets can have an additional one or two data bytes.

Speed Bits
Speed Steps C S S S S 0 S S S S
14 Undefined LSB 2 3 MSB - - - -
28 LSB 2 3 4 MSB - - - -
128[7] 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 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.

Decoder and Consist Control

S-9.2.1 The Data Byte(s) have the following construction:

0000CCCF or 0000CCCF DDDDDDDD

For decoder control the data byte begins with four zeros. In most cases these processes will be handled transparently by the command station.

DECODER CONTROL
0 0 0 0 C C C F

An additional data byte may follow this data byte.

Instructions

Instruction
000 F=0, Decoder Reset. F=1, Hard Reset
001 Factory test, factory use only
010 Reserved
011 Set Decoder Flags
100 Reserved
101 Set Advanced Addressing (CV29, Bit 5)
110 Reserved
111 F=1, Decoder Acknowledgment Req.
  1. Reset: Decoder to erase all volatile memory and return to its initial state at power up
  2. Hard Reset: CV 29, 31 and 32 return to factory default, CV 19 cleared and set to 0, and a reset is performed.

Set Decoder Flags

This is an expanded decoder function which allows the command station to control various flags within a specific decoder or group of decoders.

A second data byte will contain the commands as well as the decoder sub address. Up to seven decoders can share the same primary address while allowing certain functions, such as CV changes, to be performed on an individual decoder within the group, or if the sub address is 0, all decoders in that group.

Consist Control

For consist control the data byte begins with 0001CCCC.[8]

This controls consist setup, activation or deactivation. These commands allow the command station to configure consisting without regard to the status of the Decoder Lock.[9][10]

When this mode is in effect, the multifunction decoder will ignore speed and direction instructions addressed to its normal locomotive address, except if the consist should have the same address as the locomotive. These instructions only apply to the consist address.

Functions controlled by instruction 100 and 101 (see table able) will continue to respond to the decoder's baseline address. Functions controlled by instructions 100 and 101 also respond to the consist address if the appropriate bits in CV21 and 22 have been activated.

When in this mode all forms of bi-directional communications are deactivated, unless activated specifically by a decoder control instruction. Ops Mode acknowledgements and data transmission apply to the appropriate commands at the respective decoder addresses.

  • When CCCC = 0010, set consist address in second byte and activate consist. The consist address is then stored in CV19, bits 0-6, bit 7 is set to zero. The consist will travel in the normal direction.
  • When CCCC = 0011, set consist address in second byte and activate consist. The consist address is then stored in CV19, bits 0-6, bit 7 is set to one. The consist direction will be the opposite of the normal direction.[11]

With either command, when the consist address is set to 0000 0000 the consist will be deactivated.

Advanced Operations

These instructions control advanced decoder functions. Only a single advanced operations instruction may be contained in a packet.

Format: 001C CCCC 0 DDDD DDDD

The five C bits allow for 32 instructions. Only three are currently in use.

  1. CCCCC = 11111 (31): 128 Speed Steps
  2. CCCCC = 11110 (30): Restricted Speed Step Instruction, restricts maximum speed of decoder
  3. CCCCC = 11101 (29): Analog Function Group

Special Commands

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

Digital Decoder Reset Packet

The Digital Decoder Reset Packet for All Decoders [12] has an address and data value of zero and the XOR operation means the error byte has a zero value. Upon receiving a reset packet, a multifunction decoder must bring a moving locomotive to an immediate stop.

The reset packet is transmitted for several seconds by the command station after it has been powered up. This packet clears a multifunction decoder's volatile memory of speed and direction commands, and mutes the sound. This prevents runaways and other unexpected events after a DCC system reset or during layout power up. When the command station begins transmitting Idle Packets the sound should return, unless the decoder was configured to mute on startup. [13]

Reset packets are sent as part of the service mode programming procedures to clear and provide power to a multifunction decoder prior to transmission of programming packets. The contents of the decoder's programming can be altered immediately after receipt of the Decoder Reset Packet, as per Service Mode Recommended Practices.

Idle Packet / Digital Decoder Idle Packet for All Decoders

The Digital Decoder Idle Packet for All Decoders is a three-byte packet which differs from the reset packet in that the address (first) byte is set to eight 1s, the second byte consists of eight 0 bits, and the third byte is eight 1s. Upon receipt the decoder shall perform no actions, and act as if this packet was addressed to another decoder. [14]

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 / Digital Decoder Broadcast Stop Packets for All Decoders

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. [14][15]

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 which hogs bandwidth is operating an analog locomotive on a DCC system.

Further Reading

Try the Wayback Machine here: [DCC Packets]

References

  1. A "word" being 8 bits.
  2. NCE's Power Pro transmits a 12 bit preamble, and the Power Cab provides a 17 bit preamble. Erratic macro operation
  3. S–9.2, Preamble: The preamble to a packet consists of a sequence of "1" bits. A digital decoder must not accept as a valid, any preamble that has less then 10 complete one bits, or require for proper reception of a packet with more than 12 complete one bits. A command station must send a minimum of 14 full preamble bits.
  4. S–9.2: The first byte can also be used in special cases to indicate instructions. See the Service Mode Recommended Practice (RP-9.2.3) for an example of this dual use.
  5. Address values 00000000, 11111110, and 11111111 are reserved.
  6. S–9.2 footnote.
  7. If a 128 step speed instruction to sent to a multifunction decoder, it will switch to that mode. If the decoder does not support 128 steps, loss of control occurs.
  8. S-9.2.1, 160
  9. Bypassing the Decoder Lock may not be possible with some multifunction decoders.
  10. Some multifunction decoders do not support Consist Control commands,
  11. When CV19 bit 7 is set to one, the consist will travel in the direction opposite of normal.
  12. Communications Standards For Digital Command Control, All Scales S-9.2
  13. This packet does not reset the decoder to factory defaults.
  14. 14.0 14.1 S–9.2: Digital Decoder Idle Packets and Digital Decoder Broadcast Stop Packets are optional for Command Stations, and required for decoders.
  15. S–9.2: Broadcast Stop Packet requirement for decoders, effective 1-Aug-2002.