X-10 Protocol and Control

NOTE: The X-10 protocol is patented but X-10 gives anyone that purchases a PL513 or TW523 express permission to transmit X-10 commands. To create your own hardware interface to the power line and transmit X-10 is expressly forbidden. To do so is in direct violation of their patent.

This is a reference to be used later to help understand the BEGIN1.ASM code dealing with X-10, that I will explain when I start the walk thru of the file BEGIN1.ASM in the next lesson.

X-10 has been around for many years, and is a diverse protocol that has just recently been expanded. My explanation here doesn't include any description, except in passing, of this fact. I will be referring to the original X-10 protocol. Also this discussion assumes that you live in a country that has 60 Hz power frequency (USA). I realize that some of you will be from countries that have 50 Hz mains power, but I have no experience with this frequency. I will say that X-10 has modules for 50 Hz power mains.

X-10 allows for up to 256 devices, divided into 16 house codes, each with 16 unit codes. On most X-10 devices is the ability to select, with a couple of rotary switches, the house and unit code address. The TW523 is one of the few devices that doesn't have these selector switches. That is because the TW523 can communicate with any one of the 256 possible devices.

Originally, lighting was a big part, and still is, for the use of X-10. There are also horn modules, thermostat modules, dry contact input modules, dry contact output modules, appliance modules, pet feeders, infrared motion sensors, and many more. Each recognizes and may respond to some or all of the commands available. It depends on the module.

The X-10 Commands

There are many different X-10 modules available. One is the lighting module. This module recognizes the ON, OFF, ALL UNITS OFF, ALL UNITS ON, ALL LIGHTS ON, ALL LIGHTS OFF, DIM, and BRIGHT commands. Some of the newer models may also recognize and respond to STATUS REQUEST with STATUS=ON or STATUS=OFF and recognize the PRE-SET DIM command.

The ON and OFF commands are straight forward and either turn off or turn on a device. The ALL UNITS ON and OFF also do the same thing, except that it is done for all devices on a particular HOUSE code. The ALL LIGHTS ON and OFF act on all lighting control modules on a particular HOUSE code. The DIM dims a particular lighting module and the BRIGHT brightens a lighting module. The PRE-SET DIM sets a particular lighting module to a DIM level somewhere between OFF and ON, without having to send repeated DIM's or BRIGHTs to get it to that level.

The HAIL REQUEST is used to determin if there is another "talker" or transmitter within "listening range" of the TW523. This could be another TW523. If there is another talker, it will respond with the HAIL ACKNOWLEDGE response.

The X-10 Protocol

To control an X-10 device, the HOUSE code, the UNIT code and the FUNCTION code must be sent for a complete command. The UNIT code and the FUNCTION code vary in the most significant bit, called D16 in the X-10 protocol documentation. For a UNIT code this bit is a zero and for a FUNCTION code this bit is a one. Following is a table listing all the codes used by X-10.

     House Codes             Key Codes

     H1 H2 H3 H4           D1 D2 D4 D8 D16

'A'  0  1  1  0      '1'   0  1  1  0  0   UNITS
'B'  1  1  1  0      '2'   1  1  1  0  0
'C'  0  0  1  0      '3'   0  0  1  0  0
'D'  1  0  1  0      '4'   1  0  1  0  0
'E'  0  0  0  1      '5'   0  0  0  1  0
'F'  1  0  0  1      '6'   1  0  0  1  0
'G'  0  1  0  1      '7'   0  1  0  1  0
'H'  1  1  0  1      '8'   1  1  0  1  0
'I'  0  1  1  1      '9'   0  1  1  1  0
'J'  1  1  1  1     '10'   1  1  1  1  0
'K'  0  0  1  1     '11'   0  0  1  1  0
'L'  1  0  1  1     '12'   1  0  1  1  0
'M'  0  0  0  0     '13'   0  0  0  0  0
'N'  1  0  0  0     '14'   1  0  0  0  0
'O'  0  1  0  0     '15'   0  1  0  0  0
'P'  1  1  0  0     '16'   1  1  0  0  0

'ALL LIGHTS OFF'           0  0  0  0  1   FUNCTIONS
'ALL LIGHTS ON'            0  0  0  1  1
'ON'                       0  0  1  0  1
'OFF'                      0  0  1  1  1
'DIM'                      0  1  0  1  1
'BRIGHT'                   0  1  0  1  1
'ALL LIGHTS OFF'           0  1  1  0  1
'EXTENDED CODE'            0  1  1  1  1
'HAIL REQUEST'             1  0  0  0  1
'HAIL ACKNOWLEDGE'         1  0  0  1  1
'PRE-SET DIM'              1  0  1  X  1
'EXTENDED DATA (ANALOG)'   1  1  0  0  1
'STATUS=ON'                1  1  0  1  1
'STATUS=OFF'               1  1  1  0  1
'STATUS REQUEST'           1  1  1  1  1
 

The X-10 protocol defines transmissions in 11 cycle message segments. Each message segment contains a START code, a HOUSE code, and a KEY code. The KEY code can be a UNIT or a FUNCTION, depending on the state of bit D16. The X-10 protocol states that, except for the START code, all bits are sent in their "True" state, immediately followed by the "inverted" state. In other words if a HOUSE code 'A' is sent (0110) this would look like 01 10 10 01. Each of these pairs of bits would take one complete cycle of power to be sent. The true state is sent on the first half cycle and the inverted state on the second half cycle.

The exception is the START code, which is always sent out as 1110. Looking at the above example of HOUSE code 'A', that data is 01101001. Notice that in that data there is never 3 one's in a row, and never the pattern 1110. This makes the START code unique in the data stream, and what signals the start of an X-10 message segment. A complete message segment will take 11 cycles of power to send. In other words the data is sent out just as it is listed in the above table, from left to right starting with the START followed by H1, H2, H4, H8, D1, D2, D4, D8, and D16 along with the inverted bits.

Here's an example of what the data stream would look like for HOUSE code 'A' and UNIT code '1'.

1110011010010110100101

Dividing it up in it's functional groups it would look like this.

1110 01101001 0110100101

The first four bits are the START code, the next 8 are the HOUSE code and the last 10 are the KEY code.

Dividing this up in pairs of bits, representing complete cycles of power, it would look like this.

START   HOUSE CODE    KEY CODE

11 10   01 10 10 01   01 10 10 01 01

As you see here, the START code takes 2 cycles, the HOUSE code 4 cycles, and the KEY code 5 cycles. This is the 11 cycle message segment. One complete command consists of the message segment sent twice, taking 22 cycles of power to send. If the TW523 was receiving this 22 cycle transmission, data will only be sent out to the DS5000 during the second message segment. The proprietary chip inside the TW523 is comparing the first message segment with the second segment as it is received and presents data to the DS5000 during this second segment. This comparison is made to validate the X-10 command, and that it wasn't garbled with noise during transmission.

To actually turn 'ON'  HOUSE code 'A', UNIT '1', two commands are sent. The first command selects the UNIT to be controlled and the second command is the action to be taken, in this case to turn 'ON'. This complete transmission would take 22 cycles for the first command, followed by 3 cycles of silence, followed by 22 cycles for the second command, for a total of 47 cycles. There would also have to be at least 3 cycles of silence following the second command, which would bring the total to 50 complete cycles of power for one complete transmission, before another could be sent.

The exceptions to the rule of 3 cycles of silence between commands is in the case of DIM, BRIGHT, EXTENDED CODE, and EXTENDED DATA. These commands are sent with no gaps or silence between commands. The TW523 can only receive commands separated by 3 cycles of silence.

The format of the X-10 message follows a strict order. Following is a complete X-10 message. Although I've shown it on two lines, they should be considered as one long line.

START  HOUSE      UNIT   START  HOUSE      UNIT    SPACE
|    |        |          |    |        |          |      |

START  HOUSE    FUNCTION START  HOUSE    FUNCTION  SPACE
|    |        |          |    |        |          |      |

My approach to X-10 transmission is to build the complete message (all 47 cycles worth) in a buffer in data memory, and then send it out, one bit per each 120 Hz interrupt iteration. This is one of the reasons I picked 120 Hz for the interval of the interrupt. In this way, a minimum of CPU time is spent sending the X-10 transmission.

In my design, there is something dealing with X-10 that I omitted. That is the ability to communicate over 3 phase power systems. I only deal with single phase power, which is the norm for homes. To deal with 3 phase power, you must send the transmission at three different times, separated by 120 degrees. In other words, I only send the data at one time, not three. This minimizes the hardware and software requirements for the DS5000 and still lets you control things in the single phase environment, which covers the majority of homes.

To explain further, X-10 requires that you modulate the power line within 50 usec of the "zero crossing" point and that this modulation last for 1 ms. For three phase power, this would be repeated at the 120 degree mark and the 240 degree mark, which are the zero crossing points for the other two phases.

The TW523 outputs a square wave, in sync with the power line frequency and within the 50 microsecond window of zero crossing. This is a 60 Hz square wave. In my design I trigger two single shots, one on the rising edge of this square wave and one on the falling edge. I OR the outputs of these two single shots together to form the 120 Hz frequency needed, for software simplicities sake, to generate and receive the X-10 transmission. I also use another single shot to generate the 1 ms modulation envelope for transmitting X-10. This relieves the software from having to time this interval leaving more crunch time for everything else. I don't expect everyone to understand all this, but I give it here for the more curious at heart. Just build the schematic as shown and it will work fine.

Also, all inputs and outputs of the TW523 are opto isolated, using 4N35 parts or equivalents, and therefore safe to connect to a different power system, namely that of the DS5000. These opto's provide a minimum of 7500 volts of isolation between the power line and the DS5000.

One last thing, when a 1 is present in the X-10 data stream, this results in a 120 KHz carrier being applied to the power line. If a zero, no carrier is present. In other words if a 120 KHz carrier is present, that is interpreted as a 1, otherwise it is a zero. To make this even more confusing, the transmit and receive signal points on the TW523 are INVERTED. In other words to send a 1 you really send a zero and if you are receiving a zero, that's really a one. Sounds very confusing, but in reality you handle this by simply inverting everything you send or receive with the TW523, in software. This way you handle the data inside the DS5000 buffer as true data and invert it as it leaves or enters the DS5000.

I used software for this inversion instead of external inverter gates. This is one example of software being as good or better than hardware for a particular job. I didn't have any spare inverter gates left and the impact on software is very minimal to perform this inversion. On the other hand I added a single shot gate to time the 1 ms envelope requirement for X-10 transmission, which would have used a lot of CPU time to generate this interval in software. When designing a system, there is a continuous effort to use the minimum amount of hardware, but at the same time to have enough hardware to simplify the software, where it matters.

In closing, there are devices on the market that will interfere with X-10 communications. These include baby minders, intercoms, and phone extenders, that all operate over the power lines. The interference comes from the fact that these devices are transmitting all, or part of the time, covering up and scrambling the X-10 signals (120 KHz carrier). If you experience other problems with X-10, it's usually because there is something noising up the power line. Defective fluorescent lights, motors, air conditioners, and the like, will either cause spikes, or outright noise, either of which could cause intermittent or total loss of communications.

My home page is http://www.hkrmicrop.com/personal/index.html .

On to lesson 17.

Table of Contents