Abstract: This page looks at the pattern of 1s and 0s that occur on a model railway track under DCC (Digital Computer Control). The pattern of 1's and 0's determine the actions of the trains and the accessories.
The patterns have been checked using an NCE DCC Twin controller and the hardware developed in project DCC_Probe
Notes:
1. My objective was to develop an accessory (point or turnout ) decoder for a NCE layout so my interest was the accessory protocols. The other protocols will be documented as time and interest permit.
2. The detail in the DCC protocol is determined by a number of CVs(Configuration Variables). I have not been able to get a good handle on the CVs so these have only been mentioned in passing.
The following logic analyser trace extracts three bits from a continuous string of 1's and 0's. The first two bits are a logic "1" and each has a duration of 118uS while the third bit is a logic "0" and has a duration of 222uS.
Zooming out a complete message may be seen.
This example is for the Idle Command. Briefly:
1.There are at least 12 "1's" making the preamble packet. This is terminated by a "0" that says there is more to follow.**
2.There is one byte (8 bits) of "1's" terminated by a "0"
3.There is one byte of "0's" also terminated by a "0" making 10 in total.
4.The final byte is 8 "1's" terminated by a "1" the "1"indicating the message is complete. (The checksum)
5.The preamble for the next message follows.
Other commands will have different bit patterns and may be more than three bytes in length.
The final byte is always an error check performed by an XOR comparison of each bit of the previous bytes.++
**For reference this "0" is roughly above the "o" in the text "Period"
++ With the Idle command given each bit in the first byte is a "1" and each bit in the second byte a "0". The XOR of a "1" and "0" is "1" so every bit in the third byte is a "1".
----------------------
0000,0000: Special Commands. See Byte2_Special.
0000,0001-0111,111: Locos 1-127. This is known as CV1: (Configuration Variable). The complete command requires two more bytes plus an error byte. See below. Also continued in Byte2_Loco
1000,0000 -1011,1111: Decimal 128-191 Accessory Command. The lower 6 bits (0-63) give part of accessory address - CV513 Decoder Address LSB. Continued in Byte2_Accessory
11000000-11100111 Decimal 192-199, 224-231) Multi Function Decoders with 14 bit addresses. See below and continued Byte 2 Multi function.
11101000-11111110 Decimal 232-254: Reserved for Future Use
1111,1111: Decimal 255: Idle command. Byte 2 = 0000,0000. Byte 3 or Error byte = 1111,1111 See waveform above. Runs continuously to ensure power to the track. Signals ignored by all decoders.
-----------------------------
Byte 1 = 0000,0000
Byte 2 = 0000,0000 Reset - Next byte = checksum
Byte 2 0000,0001 - 1111,1111 Not developed
----------------------------
From my reading bit 7 = 0 for loco speed. Bit 7 = 1 for other (normally loco) functions
0000,0000 - 0111,1111 Decimal 0 - 127 .
Setting the loco speed the second byte was a constant 63dec (0011,1111) on the NEC DCC TWIN whereas at Leonland the constant was 69dec. (0100,0101) ?? Continued at Byte3_Loco
Byte2 10xx,xxxx 128-191 Controls Functions.
1000,0000 - 1001,1111: 128- 159. Bit 5 controls light. Bits 3 .. 0 control functions F4..F1, "1" for on - "0" for off
1010,0000 - 1011,1111: 160- 175:Bit 5 controls light.Bit 5 controls light. Bits 3 .. 0 control functions F8..F5, "1" for on - "0" for off
1100,0000 - 1111,1111: 192-255 Feature Expansion Instruction
---------------------
General format of the accessory command is:
Preamble 0 10aaaaaa 0 1bbbCddD 0 EEEEEEEE 1.
Command is quite complex. From my readings it is possible to have 9 bit address and 11 bit address. With 9 bits it is possible to have 512 unique accessory decoders where as with 11 bits 2048 are possible. However decoders with 9 bit addresses have the ability to control 4 functions, specified by dd in the command above from the one address. D is the output at the specified address.
1000,0000 - 1111,1111 Decimal 128-255
The 9 bit address will be cccaaaaaa where ccc is CV521the Decoder Address MSB and is the 1's complement of bits 4-6 (bbb) in the second byte.
NCE appear to include dd to give an 11 bit address. ie bbbaaaaaadd.
Details are probably best explained with an example.
Assume two bytes 1010,0001 and 10101101 both in binary. (161dec, 173dec)
By observation aaaaaa = 10,0001 (= 33 decimal) and bbb = 010 making its complement ccc = 101
That is the full address = 1,0110,0001 (9 bits0 = 353 decimal
Subtract 1 to obtain 1,0110,0000 or 352 decimal.
Make room for the dd portion by multiplying by 4 or shift left 2 places to give 101,1000,00zz (11 places) where zz = 00
Include/Add dd = 10 the address =101,1000,0010
Adding 1 makes the address =101,1000,0011
In decimal = 1024 + 256 + 128 + 2 + 1 = 1411
-------
Working backwards from 101,1000,0011.
Subtract 1 to obtain 101,1000,0010 making dd = 10 and cccaaaaaa = 101,1000,00
Read cc = 101 making bbb = 010 and aaaaaa = 10,0000
Adding 1 to aaaaaa gives 10,0001
Result
1010,0001, 1010110D = 161, 172 or 173 depending upon D
----------
Byte 1 is in the range 11000000-11100111 (192-199, 224-231) where bits 5..0 are high part of address (weight 256). Byte 2 gives the lower 8 bits. For example loco 1234 gives 196,210 + instruction bytes. Masking top two bits have 4,210 or 4*256+210 = 1234.
Continued at Byte 3 Multifunction
-----------------------------
Bit 7 gives direction. 1 : forward 0 : reverse
Results found with NCE DCC TWIN
0000,0000 - 0111,1111 Decimal 0-127 Speed in reverse direction: 0 is stationary. 127 is maximum reverse.
1000,0000 - 1111,1111 Decimal 128-255. Speed in forward direction: 128 is stationary. 255 is maximum forward.
Speed = 1 (or 129) is emergency stop.
-------------------
Bytes 1 and 2 give the 14 bit address. There are then one or two instruction bytes followed by error control byte.
Byte 3 is defined as follows CCCDDDDD. Each instruction consists of a 3-bit instruction type field followed by a 5-bit data field. Some instructions have one, two or three additional bytes of data.
The 3-bit instruction type field is defined as follows:
000 Decoder and Consist Control Instruction
001 Advanced Operation Instructions
010 Speed and Direction Instruction for reverse operation
011 Speed and Direction Instruction for forward operation
100 Function Group One Instruction
101 Function Group Two Instruction
110 Future Expansion
111 Configuration Variable Access Instruction
-------------------
Byte 3 0000,0000 - 0001,1111 (0-31 decimal): Decoder and Consist Control Instruction
Byte 3 0010,0000 - 0011,1111 (32-63 decimal): Advanced Operation Instructions
Byte 3 0100,0000 - 0101,1111 (64- 95 dec) Reverse speed 64 stopped (why did I get 66 for speed 1?) maximum 31. 32 speed steps
Byte 3 0110,0000 - 0111,1111 (96 - 127 dec) Forward speed. 96 stopped ( I read 98 for 1 and 100 for 5)
For Byte 3 1xxx,xxxx see Byte 2 1xxx,xxxx Function operations
----------------------------------------------------------
The last byte of the packet is the Error Detection Byte