The Internet Power Line Adapter - University of Queensland
The Internet Power Line Adapter - University of Queensland
The Internet Power Line Adapter - University of Queensland
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>The</strong> <strong>Internet</strong> <strong>Power</strong> <strong>Line</strong><br />
<strong>Adapter</strong><br />
by<br />
Quenten Alick<br />
Department <strong>of</strong> Computer Science and Electrical Engineering<br />
<strong>The</strong>sis submitted for the degree <strong>of</strong><br />
Bachelor <strong>of</strong> Engineering (Hons)<br />
in the division <strong>of</strong> Computer Systems Engineering<br />
15 th October 1999
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
<strong>The</strong> Dean<br />
School <strong>of</strong> Engineering<br />
<strong>University</strong> <strong>of</strong> <strong>Queensland</strong><br />
St Lucia, QLD 4072<br />
Dear Pr<strong>of</strong>essor Simmons,<br />
- i -<br />
57 Primrose Tce<br />
Red Hill QLD 4059<br />
Tel (07) 3369 2749<br />
15 th October 1999<br />
In accordance with the requirements for the degree <strong>of</strong> Bachelor <strong>of</strong> Engineering<br />
(Honours) in the division <strong>of</strong> Computer Systems Engineering, I present the following<br />
thesis titled “<strong>The</strong> <strong>Internet</strong> <strong>Power</strong> <strong>Line</strong> <strong>Adapter</strong>”. This thesis was conducted under the<br />
supervision <strong>of</strong> Dr. Mark Schulz.<br />
I declare that the work submitted in this thesis is my own, except as<br />
acknowledged in the text, footnotes and citations, and has not been previously<br />
submitted for a degree at the <strong>University</strong> <strong>of</strong> <strong>Queensland</strong> nor any other Institution.<br />
Yours Sincerely,<br />
Quenten Alick
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
Acknowledgments<br />
Many people have contributed to this thesis in one way or another. This is my chance to<br />
thank them.<br />
• Dr Mark Schulz, my supervisor for his consistent advice throughout the year.<br />
• Len Payne for his practical advice and assistance in the thesis labs.<br />
• Tony Truong, my partner, for putting up with me throughout this project.<br />
• John MacDonald, for his assistance with the analogue circuits.<br />
• Montse Ros, for her valuable support throughout the year, and for pro<strong>of</strong>reading this<br />
document.<br />
• To Coiltronics Inc., for their timely provision <strong>of</strong> some sample inductors.<br />
• And finally, to all my friends, both in and out <strong>of</strong> the CSE thesis labs, for their<br />
support and good humour through the good and the bad.<br />
- ii -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
Abstract<br />
Automation systems have been around for many years making light work <strong>of</strong><br />
tasks that are considered too menial or dangerous for humans to perform.<br />
Recently there has been a trend towards the development <strong>of</strong> home automation<br />
systems that will automate many <strong>of</strong> our tasks around the home, making them<br />
easier to perform and providing humans more time to be creative. However, for<br />
a home automation system to function, different devices must be able to<br />
communicate with each other.<br />
This thesis aims to show that the home’s power lines are suitable for use as a<br />
communications medium for home automation systems. To show this, a power<br />
adapter was designed that would be able to monitor the power consumption <strong>of</strong><br />
various devices around the home and let a user monitor it using a web page<br />
interface.<br />
Overall this thesis was successful in demonstrating that the power lines are a<br />
suitable medium for communications within a home automation system despite<br />
there being some problems with the measurement <strong>of</strong> power. Several<br />
improvements to the design have also been suggested.<br />
- iii -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
Table <strong>of</strong> Contents<br />
ACKNOWLEDGMENTS................................................................................................................... II<br />
ABSTRACT.......................................................................................................................................III<br />
LIST OF FIGURES...........................................................................................................................VI<br />
CHAPTER 1 ........................................................................................................................................ 2<br />
1.1 INTRODUCTION......................................................................................................................... 2<br />
1.2 THE DREAM.............................................................................................................................. 2<br />
1.3 GOALS OF POWER LINES & HOME AUTOMATION ....................................................................... 3<br />
1.4 OVERVIEW OF THIS THESIS........................................................................................................ 4<br />
CHAPTER 2 ........................................................................................................................................ 5<br />
2.1 TECHNOLOGY REVIEW.............................................................................................................. 5<br />
2.2 HOME AUTOMATION................................................................................................................. 5<br />
2.2 X-10 POWER LINES HOME AUTOMATION STANDARD................................................................. 6<br />
2.2.1 X-10 Network Layout ...................................................................................................... 6<br />
2.2.2 X-10 Transmission Protocol............................................................................................ 7<br />
2.2.3 X-10 Summary ................................................................................................................ 8<br />
2.3 LONWORKS............................................................................................................................. 9<br />
2.3.1 LONWorks Network Layout & Transmission Protocol ..................................................... 9<br />
2.3.2 LONWorks Summary....................................................................................................... 9<br />
2.4 CEBUS (CONSUMER ELECTRONICS BUS) STANDARD................................................................ 10<br />
2.4.1 CEBus Network Layout ................................................................................................. 10<br />
2.4.2 CEBus Transmission Protocol....................................................................................... 12<br />
2.4.3 CEBus Summary ........................................................................................................... 13<br />
CHAPTER 3 ...................................................................................................................................... 14<br />
3.1 SPECIFICATIONS OF THE SYSTEM ............................................................................................. 14<br />
3.2 OVERVIEW OF THE SYSTEM ..................................................................................................... 14<br />
3.3 CLIENT SPECIFICATIONS.......................................................................................................... 15<br />
3.3.1 <strong>Power</strong> Measurement & Turn On / Off............................................................................ 15<br />
3.4 SERVER SPECIFICATIONS......................................................................................................... 16<br />
3.4.1 Control and Receive Data from Client........................................................................... 16<br />
3.4.2 Communications with the <strong>Internet</strong> ................................................................................. 16<br />
3.5 SUMMARY OF SPECIFICATIONS ................................................................................................ 17<br />
CHAPTER 4 ...................................................................................................................................... 18<br />
- iv -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
4.1 HARDWARE IMPLEMENTATION................................................................................................ 18<br />
4.2 POWER LINES NETWORK CONTROLLER.................................................................................... 18<br />
4.3 POWER MEASUREMENT & SWITCHING..................................................................................... 19<br />
4.4 MICROPROCESSOR .................................................................................................................. 20<br />
4.5 POWER SUPPLY....................................................................................................................... 22<br />
4.6 INTERNET CONNECTIVITY ....................................................................................................... 23<br />
4.7 HARDWARE DESIGN SUMMARY............................................................................................... 23<br />
CHAPTER 5 ...................................................................................................................................... 25<br />
5.1 SOFTWARE IMPLEMENTATION ................................................................................................. 25<br />
5.2 MICROPROCESSOR CODE......................................................................................................... 25<br />
5.3 PC OPERATING SYSTEM.......................................................................................................... 27<br />
5.4 WEB SERVER & PC INTERFACE............................................................................................... 27<br />
5.5 SOFTWARE SUMMARY............................................................................................................. 28<br />
CHAPTER 6 ...................................................................................................................................... 29<br />
6.1 DESIGN EVALUATION.............................................................................................................. 29<br />
6.2 POWER LINES COMMUNICATION EVALUATION......................................................................... 29<br />
CHAPTER 7 ...................................................................................................................................... 32<br />
7.1 REVIEW OF THE DESIGN .......................................................................................................... 32<br />
7.2 FUTURE DIRECTION ................................................................................................................ 33<br />
CHAPTER 8 ...................................................................................................................................... 35<br />
8.1 CONCLUSION .......................................................................................................................... 35<br />
APPENDIX A – SCHEMATICS ....................................................................................................... 36<br />
APPENDIX B – PRINTED CIRCUIT BOARD................................................................................ 40<br />
APPENDIX C – CODE FLOWCHARTS ......................................................................................... 42<br />
APPENDIX D – ASSEMBLER CODE LISTING............................................................................. 44<br />
APPENDIX E – C CODE LISTING ................................................................................................. 50<br />
REFERENCES & BIBLIOGRAPHY ............................................................................................... 61<br />
- v -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
List <strong>of</strong> Figures<br />
Figure 2-1 X-10 transmission signal............................................................................7<br />
Figure 2-2 X-10 Transmission Formats .......................................................................8<br />
Figure 2-3 A TV split into CEBus objects. ................................................................11<br />
Figure 2-4 List <strong>of</strong> CEBus symbols & Transmission times..........................................12<br />
Figure 2-5 CEBus <strong>Power</strong> line Chirp ..........................................................................13<br />
Figure 3-1 Block Diagram <strong>of</strong> the System...................................................................15<br />
Figure 4-1 P300 Evaluation Board ............................................................................19<br />
Figure 4-2 Final Hardware Block Diagram................................................................24<br />
Figure 5-1 Write operation for the P300....................................................................26<br />
Figure 5-2 S<strong>of</strong>tware Overview ..................................................................................28<br />
- vi -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
<strong>The</strong> <strong>Internet</strong> <strong>Power</strong> <strong>Line</strong> <strong>Adapter</strong><br />
Chapter 1<br />
1.1 Introduction<br />
<strong>The</strong> topics <strong>of</strong> this thesis, in isolation, hardly need introduction. Today, almost<br />
everyone has heard <strong>of</strong> and used the <strong>Internet</strong> in one or more <strong>of</strong> its forms. It is one<br />
<strong>of</strong> the fastest growing areas in communications. Likewise, most people<br />
understand the concept <strong>of</strong> home automation, where computers and machines<br />
control parts <strong>of</strong> your home. Home automation is <strong>of</strong>ten portrayed as being a part<br />
<strong>of</strong> life in films and shows set in the future. Finally, “power lines” refers to the<br />
power lines within a home that supply power to the home.<br />
1.2 <strong>The</strong> Dream<br />
If there were no limit on the resources available, the system that had been<br />
envisaged would be a home automation system that could control a wide variety<br />
<strong>of</strong> different appliances using the power lines as a communications medium. This<br />
overall system would be connected to the <strong>Internet</strong> and would be able to be<br />
controlled from the <strong>Internet</strong>, through a web page, by an authorized user.<br />
This system could make a wide variety <strong>of</strong> possibilities become available. All the<br />
functions <strong>of</strong> a normal home automation system could be accessed via the<br />
<strong>Internet</strong>. If you’re at work during a heat wave, you can activate the air<br />
conditioning so that when you arrive home, the house is a comfortable<br />
temperature. Dinner could be cooked and waiting, having been started before<br />
you left work. It also becomes easier to monitor your home while you’re away.<br />
If you left the lights on in the bathroom or left the gas running, you can easily<br />
rectify the situation. You could even remotely control your home security<br />
- 2 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
systems. Finally, the use <strong>of</strong> power lines as a communications medium would<br />
greatly reduce the setup cost <strong>of</strong> such a system since is removes the need for<br />
additional wiring to be installed.<br />
1.3 Goals <strong>of</strong> <strong>Power</strong> <strong>Line</strong>s & Home Automation<br />
Home automation is a very large and diverse field. Almost every modern<br />
appliance could be connected to a home automation system to allow it to<br />
communicate with other appliances and to be controlled from a central point.<br />
With this in mind it was decided to reduce the scope <strong>of</strong> the home automation<br />
system to the concept <strong>of</strong> an adapter that any appliance could be plugged into.<br />
This adapter would give a rudimentary measurement <strong>of</strong> the power consumption<br />
and give the ability to turn the connected appliance on or <strong>of</strong>f.<br />
<strong>The</strong> <strong>Internet</strong> is also a very large and diverse field. An entire thesis could be done<br />
on the topic <strong>of</strong> <strong>Internet</strong> Security alone. Also, the concept <strong>of</strong> connecting<br />
appliances to the <strong>Internet</strong> has been done before and therefore has already been<br />
demonstrated to be feasible. For these reasons it was decided that this thesis<br />
would concentrate on the concept <strong>of</strong> proving that power lines are a viable<br />
communications medium for home automation systems. <strong>The</strong> <strong>Internet</strong><br />
connectivity would be considered a minor part and would be completed in the<br />
quickest way possible.<br />
<strong>The</strong> ultimate aim <strong>of</strong> this thesis is to design a device that will prove that the use<br />
<strong>of</strong> home power lines as a communication medium for a home automation system<br />
is a realistic option. A device will be designed and constructed in order to prove<br />
this. <strong>The</strong> exact specifications <strong>of</strong> this device will be discussed in chapter 3.<br />
- 3 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
1.4 Overview <strong>of</strong> this <strong>The</strong>sis<br />
<strong>The</strong> thesis started by introducing the topic with attention to the relevance the<br />
topic has in today’s society. It also presents the vision that this thesis started<br />
with before the dictates <strong>of</strong> reality reduced its scope. It then presented the goals<br />
<strong>of</strong> the thesis.<br />
<strong>The</strong> next chapter is titled the technology review. It takes a detailed look at the<br />
various existing technologies that are used for power line communications<br />
within the home. <strong>The</strong>se technologies are reviewed with attention to their<br />
suitability for use in a new home automation system.<br />
Following this chapter are the specifications for the adapter that will be<br />
constructed. <strong>The</strong>se specifications are taken from a high level. Chapters Four and<br />
Five then look in detail at the hardware and s<strong>of</strong>tware that was chosen to<br />
implement the adapter, as well as the decisions behind the choices.<br />
Chapter Six describes the results that were obtained from the product and how<br />
they met the design specifications. <strong>The</strong> following chapter then discusses the<br />
design process with respect to how the student followed engineering practice.<br />
Possible future direction and improvements to the adapter are also discussed in<br />
that Chapter. Lastly Chapter Eight presents the conclusions that were drawn<br />
from this thesis.<br />
- 4 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
Chapter 2<br />
2.1 Technology Review<br />
This chapter will look at existing technology in the areas <strong>of</strong> power line<br />
communications and home automation. It is intended to give the reader some<br />
background into the field <strong>of</strong> home automation. <strong>The</strong> various existing home<br />
automation communications mediums will be discussed. Following on from this,<br />
several <strong>of</strong> the existing home automation standards will also be discussed.<br />
2.2 Home Automation<br />
To create a home automation system, various devices within the home must be<br />
able to communicate with each other. As such, the method used to communicate<br />
between devices is very important. To date, many communication methods have<br />
been used, including radio signals, infrared communications and cable, coaxial,<br />
twisted pair and power lines. <strong>The</strong>se methods all have their advantages and<br />
disadvantages.<br />
<strong>The</strong> wireless communication methods have the advantage <strong>of</strong> being easier to<br />
install since there is no need to install wires. However, they do have drawbacks.<br />
Radio frequencies suffer from interference from other sources, and infrared<br />
systems require near line-<strong>of</strong>-sight between receivers in order to function<br />
efficiently. On the other hand, cable systems such as coaxial and twisted pair do<br />
not suffer much interference, but do have the disadvantage <strong>of</strong> installing the<br />
actual cable. Not only is this expensive in an existing home, it limits the<br />
expansion and changing <strong>of</strong> a home automation system since new cabling will be<br />
required in order to add new components to the system.<br />
- 5 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
<strong>Power</strong> lines communications <strong>of</strong>fers a slightly different set <strong>of</strong> options to the other<br />
cabling methods. <strong>The</strong>re is no need to install additional cable since every home<br />
has power lines. Outlets are also conveniently placed close to where appliances<br />
will exist in the home. However, power lines communications suffers from<br />
interference problems due to the fact that power is being transmitted as well as<br />
communications, and that the power lines are unshielded and can act like<br />
antennas.<br />
Several standards already exist in the home automation industry and some <strong>of</strong><br />
these will be discussed next. <strong>The</strong> topics that will be discussed are the X-10<br />
power line communications protocol, the LONWorks standard and the CEBus<br />
(Consumer Electronics BUS) home automation standard.<br />
2.2 X-10 <strong>Power</strong> <strong>Line</strong>s Home Automation Standard<br />
<strong>The</strong> X-10 standard is the oldest standard that was considered, being first<br />
introduced in 1978. It is purely a power line communications standard. Due to it<br />
being the first standard on the market it does have widespread support.<br />
However, it originally did not have any support for two-way communication<br />
between devices. Devices capable <strong>of</strong> two-way communication have only been<br />
developed relatively recently.<br />
2.2.1 X-10 Network Layout<br />
<strong>The</strong> X-10 network specification allows for up to 256 devices which consists <strong>of</strong><br />
16 house codes and 16 unit codes. It also defines X-10 devices as being either<br />
receivers or transmitters. This means that a single transmitter would be able to<br />
control 16 devices. In order to control more devices, new transmitters would<br />
need to be added with each transmitter using a different house code. Receivers<br />
ignore any signal that is not sent to their assigned house code. Two-way<br />
transceivers fit into the same pattern except that they can both receive and<br />
- 6 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
transmit. In this manner, is should be possible to chain transceivers together to<br />
have a single controller controlling more than 16 devices.<br />
2.2.2 X-10 Transmission Protocol<br />
<strong>The</strong> X-10 transmission protocol is concerned only with sending pure digital<br />
data. <strong>The</strong>refore the only two signals which can be sent are a logical one and a<br />
logical zero. This information is transmitted at the zero crossing point <strong>of</strong> the<br />
50Hz power signal. Logic one is represented by the presence <strong>of</strong> a 120kHz PCM<br />
(Pulse Code Modulation) burst 1ms in length at the zero crossing point. Logic<br />
zero is represented by the absence <strong>of</strong> this burst. Bursts are transmitted three<br />
times per AC cycle to allow the receiver to gather the data even if it is located on<br />
a different phase to the transmitter. <strong>The</strong> transmission points are highlighted in<br />
figure 2-1. Of course for this to work coupling between phases is required but<br />
devices that can perform this are commercially available.<br />
Transmission points<br />
Figure 2-1 X-10 transmission signal<br />
1ms 120kHz burst<br />
- 7 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
A complete X-10 takes 11 AC cycles to transmit. <strong>The</strong> header code (1110) is<br />
transmitted during the first two AC cycles with one bit transmitted per half<br />
cycle. <strong>The</strong> next eight cycles are used to transmit eight data bits, with each bit<br />
being transmitted both “normally” and complemented. This is similar to<br />
Manchester Encoding and is used to make to signal more resistant to line noise.<br />
<strong>The</strong> first four bits are the house code and the second four are the unit code.<br />
Finally, a stop bit is transmitted in the 11 th AC cycle.<br />
Once the 11-cycle transmission has been completed, the transmitter goes idle for<br />
at least three AC cycles before it repeats the same transmission. After the repeat<br />
transmission, a signal can be sent that will tell the addressed device what it has<br />
to do, for example for a light, turn on or <strong>of</strong>f. This message must also be<br />
transmitted twice. <strong>The</strong> formats <strong>of</strong> the two messages are shown in figure 2-2.<br />
Start code (4 bits) House code (4 bits) Unit code (4 bits) Stop bit (1 bit)<br />
Start Code (4 bits) House Code (4 bits) Control (4 bits) Stop bit (1 bit)<br />
2.2.3 X-10 Summary<br />
Figure 2-2 X-10 Transmission Formats<br />
Although the X-10 system is widely used and already has many products on the<br />
market, there is one main drawback to the system. Despite all the redundancy in<br />
the transmission <strong>of</strong> information, the signal is still very susceptible to line noise. In<br />
many cases, repeaters or noise blocks / filters (to remove the effects <strong>of</strong> high<br />
capacitance power loads such as computers) need to be added before the home<br />
automation system functions reliably.<br />
- 8 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
2.3 LONWorks<br />
LONWorks is an automation standard that was developed by Echelon. It was<br />
originally used in industrial automation areas but has since moved towards the<br />
home automation market. <strong>The</strong> standard is defined so that any medium can be<br />
used to transit signals. LONWorks is intended as a complete solution that<br />
provides all the necessary parts for a home automation system.<br />
2.3.1 LONWorks Network Layout & Transmission Protocol<br />
LONWorks uses a network where a central controller or a master / slave<br />
network is not needed. Instead there are local control nodes that are responsible<br />
for controlling a certain groups <strong>of</strong> sensors or actuators.<br />
<strong>The</strong> LONWorks transmission protocol is called LONTalk. This is a standard<br />
which unfortunately costs about $150US to purchase. Due to this reason, it was<br />
not possible to review the LONTalk standard in any depth. However, the<br />
standard does cover the seven layers <strong>of</strong> the OSI network model. It also provides<br />
the facilities necessary to implement a secure network, such as transaction<br />
acknowledgement, peer to peer communications and error detection and<br />
recovery.<br />
2.3.2 LONWorks Summary<br />
One <strong>of</strong> the main problems with the LONWorks standard is the cost <strong>of</strong> getting the<br />
technical details and the development tools. When compared to the cost <strong>of</strong><br />
purchasing the equivalent parts from CEBus, LONWorks proved to be much<br />
more expensive. However, this appears to be the only real drawback <strong>of</strong> the<br />
system. LONWorks has been used extensively in industry for many years with a<br />
- 9 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
recent move being towards home automation networks. It will be interesting to<br />
see how this standard fares in the next few years.<br />
2.4 CEBus (Consumer Electronics Bus) Standard<br />
<strong>The</strong> CEBus standard is designed as a general standard for home automation.<br />
Like the LONWorks standard, CEBus does not specify any one communications<br />
medium, rather it lays out specifications for using any <strong>of</strong> the mediums, either in<br />
isolation or in combination, that can provide home automations services. <strong>The</strong><br />
mediums supported by the CEBus standard include power line wiring, infrared,<br />
radio frequency, twisted pair cables and coaxial cables.<br />
2.4.1 CEBus Network Layout<br />
CEBus has two possible methods <strong>of</strong> organization and control. Either all nodes in<br />
the network are independent and can communicate and control each other, or a<br />
“cluster control” node can control several other nodes. <strong>The</strong>se two methods can<br />
also be combined in the one network. In this way, CEBus does not require a<br />
central control point; neither does it exclude the possibility.<br />
Each device on a CEBus network has two addresses. <strong>The</strong> first is the house code<br />
which is shared by all devices in an area such an apartment or home. <strong>The</strong> second<br />
is a device address that is unique to each device. <strong>The</strong>re is provision for about<br />
64k (2 16 ) unique devices for each house code, which also has 64k values.<br />
Several <strong>of</strong> these are reserved, such as the broadcast address.<br />
Every network also has a control channel and an optional number <strong>of</strong> data<br />
channels. <strong>The</strong> control channel is used to send command messages in a specified<br />
format and is required by all CEBus compliant nodes. <strong>The</strong> data channels are<br />
used to send other information, which can be in any format desired. <strong>The</strong> only<br />
- 10 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
restriction is the frequency and amplitude limitations <strong>of</strong> the channel on the<br />
medium.<br />
Various services are built into the CEBus standard. <strong>The</strong>se include the options for<br />
acknowledged “handshake” style services, unacknowledged services, parity<br />
checks and packet priority as well as sequence numbers. This means that the<br />
CEBus standard can be implemented as a reliable network or an unreliable<br />
network. Finally, there is also provision for authentication information, which<br />
can be used to implement security features.<br />
To make it possible for different CEBus compliant devices from different<br />
vendors to communicate with each other within a home, many common home<br />
automation appliances and their functions have been predefined as CEBus<br />
objects. See figure 2-3 for an example <strong>of</strong> how a TV can be broken into CEBus<br />
objects. This means the CEBus controllers can broadcast onto the network, find<br />
devices and query them to find out what they are capable <strong>of</strong> by sending a certain<br />
predefined request. <strong>The</strong> device can then respond saying that it is capable <strong>of</strong><br />
certain standard functions that the controller will know how to control since<br />
they’ve already been defined. This means that CEBus standard can create a Plug<br />
and Play network.<br />
Figure 2-3 A TV split into CEBus objects.<br />
- 11 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
2.4.2 CEBus Transmission Protocol<br />
<strong>The</strong> CEBus standard does not define exactly how each medium should represent<br />
data. It defines that the transmission medium should be capable <strong>of</strong> taking on two<br />
different states, superior and inferior. <strong>The</strong> inferior state is defined as the idle<br />
state <strong>of</strong> the medium. To begin making a transmission, the medium starts in the<br />
superior state. It then alternates states for each successive symbol that is<br />
transmitted.<br />
<strong>The</strong> length that each state is transmitted for indicates which symbol is being<br />
transmitted. <strong>The</strong>re are four different symbols, logical one, logical zero, end-<strong>of</strong>-<br />
field and end-<strong>of</strong>-packet. <strong>The</strong> transmission lengths and symbols are summarized<br />
in figure 2-4.<br />
Symbol Name Transmission Length<br />
Logical One 100μs<br />
Logical Zero 200μs<br />
End-<strong>of</strong>-Field 300μs<br />
End-<strong>of</strong>-Packet 400μs<br />
Figure 2-4 List <strong>of</strong> CEBus symbols & Transmission times<br />
In the case <strong>of</strong> power line CEBus products, the superior state is defined as a<br />
“chirp” <strong>of</strong> noise which is transmitted at the zero crossing point <strong>of</strong> the 50Hz AC<br />
power signal. <strong>The</strong> “chirp” is defined as a signal that changes frequency from<br />
200kHz to 400kHz, then 100kHz to 200kHz within the space <strong>of</strong> 100μs. <strong>The</strong><br />
spread-spectrum chirp is shown in figure 2-5. In order to create the different<br />
length states for the different symbols, this 100μs chirp is repeated to create the<br />
- 12 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
required length symbol. Finally, the frequency sweep means that the “chirp” is<br />
spread-spectrum, which gives the “chirp” better noise resistance.<br />
Figure 2-5 CEBus <strong>Power</strong> line Chirp<br />
All data in the CEBus protocol is transmitted in packets with a header and a<br />
“payload” or message. <strong>The</strong> header contains information on the type <strong>of</strong> service<br />
being provided as well as source and destination addresses with the total length<br />
being around nine bytes. <strong>The</strong> packet message can be up to 32 bytes long and can<br />
contain any data that the recipient understands.<br />
2.4.3 CEBus Summary<br />
<strong>The</strong> CEBus standard has several advantages. Firstly it allows for a large number<br />
<strong>of</strong> appliances within a home. While sixty-four thousand per house code may be a<br />
little excessive, it is many more than the sixteen that the X-10 standard <strong>of</strong>fers.<br />
Secondly, the open and versatile nature <strong>of</strong> the CEBus standard that allows<br />
different vendors to create a device and be reasonably certain that it will be able<br />
to communicate with the device from another vendor. Thirdly, the spread-<br />
spectrum nature <strong>of</strong> the power line implementation means that the system has<br />
quite good noise immunity. Finally, the way in which the network can be set up<br />
to suit the needs <strong>of</strong> the user is extremely versatile. Both reliable and unreliable<br />
networks can be created using the CEBus standard. <strong>The</strong>se factors mean that the<br />
CEBus standard was the choice made for the power line communications<br />
standard in this thesis.<br />
- 13 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
Chapter 3<br />
3.1 Specifications <strong>of</strong> the System<br />
This chapter will outline the specifications for the device that will be designed to<br />
meet the goals that were defined earlier. <strong>The</strong> various sub-sections <strong>of</strong> this design<br />
will be examined to determine what requirements each section needs to be meet<br />
to achieve the goal.<br />
3.2 Overview <strong>of</strong> the System<br />
To prove the use <strong>of</strong> power lines communications as a realistic option for home<br />
automation a simple client / server device will be designed. <strong>The</strong> client part <strong>of</strong><br />
this device will be an adapter to which any normal household appliance can be<br />
connected. <strong>The</strong> adapter will be able to measure the power that is consumed by<br />
the attached appliance. It will also be able to turn <strong>of</strong>f the appliance. This would<br />
give a user the ability to monitor the power consumption <strong>of</strong> their home and to<br />
adjust it to suit their needs. <strong>The</strong> server device will be responsible for controlling<br />
the client device and receiving data from the client. It will also be connected to<br />
the <strong>Internet</strong>. See figure 3-1 for an overall layout <strong>of</strong> the system<br />
- 14 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
<strong>Adapter</strong> 1<br />
<strong>Internet</strong><br />
Controller&<br />
Web Server<br />
Figure 3-1 Block Diagram <strong>of</strong> the System<br />
3.3 Client Specifications<br />
3.3.1 <strong>Power</strong> Measurement & Turn On / Off<br />
- 15 -<br />
<strong>Adapter</strong> 2<br />
<strong>The</strong> accurate measurement <strong>of</strong> power consumed in home AC systems is a very<br />
large and difficult topic. For this thesis, the emphasis is on the home automation<br />
system, not the power consumption, therefore the power meter will not be<br />
designed to be accurate. It is intended more for the purpose <strong>of</strong> generating some<br />
meaningful data that can be sent across the power lines. <strong>The</strong>refore the main<br />
requirement for the power meter is that it is simple and easy to build.<br />
<strong>The</strong> ability to turn the connected appliance on or <strong>of</strong>f is also intended to prove the<br />
communications aspect. It is quite a simple feature to implement but it is typical<br />
<strong>of</strong> the type <strong>of</strong> communications that needs to be sent to simple home automation<br />
devices.
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
3.4 Server Specifications<br />
3.4.1 Control and Receive Data from Client<br />
In order to control and receive data from the client, the power line<br />
communications medium will be used. <strong>The</strong> main requirement for this is<br />
simplicity and low cost. <strong>The</strong>re is no need for a high-speed link since the adapter<br />
being designed relies on human input. In this case a response time <strong>of</strong> a second<br />
would be quite acceptable. Also, the amount <strong>of</strong> data being transferred from the<br />
client to the server is relatively small. Reliability is also not essential. Although<br />
a reliable communications link is desirable, the nature <strong>of</strong> the data being<br />
transmitted means that loss <strong>of</strong> data or corrupted data will not adversely affect the<br />
system.<br />
3.4.2 Communications with the <strong>Internet</strong><br />
<strong>The</strong>re are many options that need to be considered when connecting a device to<br />
the <strong>Internet</strong>. For a practical home automation system, the use <strong>of</strong> a modem is<br />
likely to be the best option. However, as was mentioned earlier, the <strong>Internet</strong><br />
Connectivity <strong>of</strong> this design is not considered to be the main focus <strong>of</strong> the thesis.<br />
For this reason, the only requirement for the <strong>Internet</strong> connection is that it be<br />
quick and simple to set up.<br />
To be able to remotely control the adapter the controller in the system will need<br />
to have a web server. <strong>The</strong> requirement for this is the ability to handle incoming<br />
requests as well as being able to update a local web page to reflect the current<br />
status <strong>of</strong> the system.<br />
- 16 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
3.5 Summary <strong>of</strong> Specifications<br />
This chapter has outlined the general specifications for the adapter that are listed<br />
below. <strong>The</strong> next chapter will take a thorough look at the possible specific<br />
hardware solutions that will address the listed specifications.<br />
<strong>Adapter</strong> Specifications<br />
� Client:<br />
� Measure <strong>Power</strong> Consumption<br />
� Turn Appliance On / Off<br />
� Receive data from Server<br />
� Server:<br />
� Control Client<br />
� Receive data from Client<br />
� Communicate with the <strong>Internet</strong><br />
- 17 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
Chapter 4<br />
4.1 Hardware Implementation<br />
This chapter will look at the hardware design decisions that were made for the<br />
adapter. <strong>The</strong> design decisions will be examined with reference to the<br />
specifications mentioned in the previous chapter.<br />
4.2 <strong>Power</strong> <strong>Line</strong>s Network Controller<br />
It had already been decided to use a CEBus compatible power lines network<br />
controller. Of the companies that <strong>of</strong>fered CEBus compatible network chips, the<br />
Intellon and Domosys chips seemed to be the most suited. With the only<br />
requirement that the system be simple, the main determining factor became the<br />
cost <strong>of</strong> purchasing a development kit.<br />
In the end, the Intellon P300 kit proved to be the most suitable. It was the<br />
cheapest solution available that provided two development boards with the<br />
provision for the use <strong>of</strong> either a MC68HC05 microprocessor or another<br />
alternative microprocessor. <strong>The</strong> alternative Domosys development board had the<br />
option <strong>of</strong> either a combined microprocessor with network chip or a standalone<br />
network chip. However, both these options also required the further purchase <strong>of</strong><br />
a circuit to interface the chip to the power lines. With the Intellon boards, the<br />
power line interface circuitry, network controller and microprocessor were all in<br />
the same development kit. This made the Intellon board cheaper.<br />
<strong>The</strong> P300 development kit made use <strong>of</strong> three separate chips. See figure 4-1 for a<br />
picture <strong>of</strong> the development board. <strong>The</strong>se were the microprocessor, a<br />
MC68HC705C9, the P300 power line network controller and the P111 media<br />
interface IC. <strong>The</strong> P300 chip takes information from the microprocessor and<br />
- 18 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
converts it into a CEBus compliant analogue signal. This output signal is in the<br />
form <strong>of</strong> the chirps mentioned earlier. However, it is not possible to directly<br />
couple this signal to the power line power signal. It must first be filtered and<br />
amplified before it can be coupled. <strong>The</strong> P111 is responsible for the amplification<br />
<strong>of</strong> the output signal. Discrete components are used to filter the input from the<br />
P300 to the P111 as well as the signal from the power line, which is sent directly<br />
to the P300.<br />
Figure 4-1 P300 Evaluation Board<br />
4.3 <strong>Power</strong> Measurement & Switching<br />
Proper measurement <strong>of</strong> power for an appliance can be a difficult proposition. An<br />
entire thesis could be written on the topic <strong>of</strong> accurate power measurements itself.<br />
For this reason, a relatively simple circuit was designed to measure the power<br />
consumed by the appliance connected to the adapter.<br />
- 19 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
<strong>The</strong> basis <strong>of</strong> the circuit is the measurement <strong>of</strong> current. Since the adapter is<br />
plugged into the main supply, it is reasonable to expect that the supply voltage<br />
will be a constant 240V AC. If the current can be measured then by sampling the<br />
current and averaging over a time period, then using the result in a simple<br />
“power equals voltage times current” equation, a rough measure <strong>of</strong> the power<br />
should be attained.<br />
<strong>The</strong> main concern with this circuit is choosing a suitable series resister that is<br />
able to dissipate the power that may run through it.. For this, a 0.1Ohm 7-Watt<br />
power resister can be placed in series with the load i.e. the appliance. As a<br />
precautionary measure, a 5A fuse should be placed in series with the appliance.<br />
<strong>The</strong> voltage across the power resister can then be passed to a low pass filter to<br />
remove line transients and noise. <strong>The</strong> chosen filter was a Sallen-Key 2 nd order<br />
active filter with a cut-<strong>of</strong>f point <strong>of</strong> 100Hz [4]. This should be sufficient to retain<br />
the power signal while removing most <strong>of</strong> the transients.<br />
<strong>The</strong> output from the filter can then be passed to a simple Op Amp circuit to<br />
achieve a gain that will distribute the resulting voltage across the 5V range <strong>of</strong><br />
the ADCs used on the microprocessor. Finally, the switching <strong>of</strong> the adapter can<br />
be accomplished relatively simply using a relay. A dry reed relay that switches<br />
240V AC using a 5V input was selected. This relay needs to be placed in series<br />
with the appliance.<br />
4.4 Microprocessor<br />
<strong>The</strong> microprocessor used for both the client and server must be capable <strong>of</strong><br />
controlling the power lines network chip. As mentioned before, there is no need<br />
for fast communications. <strong>The</strong>refore, the processor need not be fast and an 8-bit<br />
microprocessor should be sufficient. For the client, there is an additional need<br />
for Analogue to Digital Converters (ADCs) in order to translate an analogue<br />
signal from the power meter into a digital signal. It is possible to use external<br />
ADCs so this requirement will serve to mainly save board space.<br />
- 20 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
<strong>The</strong> chosen microprocessor must also have both an SPI (Serial Peripheral<br />
Interface) and an SCI (Serial Communications Interface). <strong>The</strong> SPI is needed to<br />
be able to communicate with the Intellon P300 network chip and the SCI<br />
interface is needed to communicate with the PC that will be running the web<br />
server. In order for the SCI interface to be able to communicate with the PC a<br />
RS232 transceiver must be used to convert the voltage levels from TTL to<br />
RS232 and vice versa. <strong>The</strong> MAXIM MAX232 RS232 interface should be able to<br />
perform this task with a minimum <strong>of</strong> extra circuitry.<br />
<strong>The</strong>re are a number <strong>of</strong> processors from the Motorolla range that are suitable. <strong>The</strong><br />
processors considered were from the MC68HC05 and the MC68HC11 range.<br />
<strong>The</strong> use <strong>of</strong> a MC60HC05C series would have been ideal since the Intellon<br />
development board already used one. <strong>The</strong> only drawback would have been the<br />
need to provide external ADCs since the MC68HC05C does not provide any<br />
internal ones. This would require more PCB space, making the board more<br />
expensive. However, the cost <strong>of</strong> purchasing another development kit for the<br />
microprocessor made this option non-feasible. Even if a development kit could<br />
have been found, the individual cost <strong>of</strong> $55 per microprocessor was also rather<br />
high. If this option had been taken, the cost would have risen about $310.<br />
This left the choice with the various MC68HC11 processors for which there<br />
were suitable development kits available. <strong>The</strong> microprocessor used in the<br />
development kits was the MC68HC11A1. This is an 8-bit processor with ADCs<br />
and a SPI and SCI interface and so meets the requirements. <strong>The</strong> 256 bytes <strong>of</strong><br />
RAM should be sufficient to store temporary variables, however the 512 bytes<br />
<strong>of</strong> EEPROM are insufficient to store data from the power meter.<br />
<strong>The</strong>re are several options available to address this problem. Firstly, the<br />
MC68HC11A1 development boards come with 8k <strong>of</strong> parallel SRAM, which is<br />
more than sufficient to store the required data. If necessary, the system could be<br />
demonstrated using the development boards. <strong>The</strong> preferred option would be to<br />
- 21 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
add some external EEPROM to the microprocessor. One option for this would<br />
be the Microchip 25C080 serial EEPROM which contains 8k <strong>of</strong> EEPROM,<br />
arranged as 1024 x 8.<br />
This EEPROM uses an SPI interface. Although this could be connected to the<br />
SPI interface on the microprocessor, it is preferred that this SPI be devoted to<br />
communicating with the P300. Port pins can still be used to access serial<br />
EEPROM by “bit-banging” the interface. <strong>The</strong> final fallback is to use a<br />
MC68HC11E2 microprocessor without the serial EEPROM. <strong>The</strong> MC68HC11E2<br />
is identical to the MC68HC11A1 except that it has 2048 bytes <strong>of</strong> EEPROM. <strong>The</strong><br />
drawback is that the recording time for the power meter will have to be reduced.<br />
4.5 <strong>Power</strong> Supply<br />
<strong>The</strong> power supply for the client and server was relatively straightforward. <strong>The</strong><br />
Intellon PIII interface chip requires a 10V DC supply and the microprocessor<br />
and the P300 network chip require 5V DC supplies. <strong>The</strong>se are the only two<br />
requirements <strong>of</strong> the power supply. Since both the adapter and the controller need<br />
to be plugged into the 240V AC mains supply for the communications, this also<br />
provides a simple way <strong>of</strong> powering the two devices.<br />
<strong>The</strong> Intellon development boards required the use <strong>of</strong> a separate wall adapter that<br />
stepped the 240V AC mains supply down to 12V AC. From this supply, a diode<br />
bridge and capacitor were used to rectify the AC signal to a DC one. From here,<br />
two voltage regulators were used. <strong>The</strong> first was an LM2940T-10, which gives<br />
10V from 14-16V. From the 10V supply a LM7805 voltage regulator was used<br />
to provide the 5V supply. <strong>The</strong>se regulators can supply sufficient power for the<br />
circuitry.<br />
- 22 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
4.6 <strong>Internet</strong> Connectivity<br />
As has been mentioned before, the main aim <strong>of</strong> the <strong>Internet</strong> Connectivity was for<br />
ease and simplicity. Several options were available and they included using an<br />
Ethernet Controller with an embedded microprocessor, using a Modem chip<br />
with an embedded microprocessor or using a PC with an existing operating<br />
system and web server. <strong>The</strong> latter choice <strong>of</strong> PC was chosen since it represented<br />
the quickest and easiest way <strong>of</strong> connecting to the <strong>Internet</strong>. Another benefit <strong>of</strong><br />
this is that the same microprocessor can be used for both the client and the<br />
server.<br />
<strong>The</strong> PC used in the thesis was built from spare parts. Any processor greater than<br />
an 80386 would have been suitable. A hard drive and a network card were the<br />
only other hardware components required apart from user input / output<br />
components. <strong>The</strong> network card was needed to connect to the <strong>Internet</strong> via an<br />
Ethernet connection. One advantage <strong>of</strong> the PC is that it is capable <strong>of</strong> running<br />
several types <strong>of</strong> s<strong>of</strong>tware that could be used for <strong>Internet</strong> connectivity such as<br />
DOS or Linux. <strong>The</strong> s<strong>of</strong>tware used on the PC will be discussed in the next<br />
chapter.<br />
4.7 Hardware Design Summary<br />
This chapter has investigated the various hardware design decisions that have<br />
been made. <strong>The</strong> power line communications chip meets the requirements <strong>of</strong><br />
being both cheap and simple to implement. Likewise the microprocessor meets<br />
similar requirements as well as the requirement <strong>of</strong> having SCI and SPI interfaces<br />
for communications and ADCs for measuring the power. <strong>The</strong> choice <strong>of</strong> using a<br />
PC for the <strong>Internet</strong> connectivity meets the requirements <strong>of</strong> being simple to<br />
implement and also means that the same microprocessor can be used for the<br />
client and the server, which will make the design simpler. In the next chapter the<br />
- 23 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
specific s<strong>of</strong>tware requirements <strong>of</strong> the thesis will be discussed. See figure 4-2 for<br />
a detailed overview <strong>of</strong> the system.<br />
<strong>Internet</strong><br />
PC<br />
MC68HC11<br />
P300 &<br />
P111<br />
- 24 -<br />
<strong>Power</strong><br />
Module<br />
Server Client<br />
<strong>Power</strong><br />
<strong>Line</strong>s<br />
MC68HC11<br />
P300 &<br />
P111<br />
Figure 4-2 Final Hardware Block Diagram
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
Chapter 5<br />
5.1 S<strong>of</strong>tware Implementation<br />
This chapter will look at the s<strong>of</strong>tware design issues that were considered for the<br />
system. <strong>The</strong>se design decisions will be looked at with reference to the<br />
specifications in chapter three and the restrictions imposed by the hardware<br />
chosen in chapter four.<br />
5.2 Microprocessor Code<br />
<strong>The</strong> first task that the code in both the client and server microprocessor must<br />
complete is the communications with the P300 network chip. <strong>The</strong>se<br />
communications require the use <strong>of</strong> the SPI interface on the microprocessor. <strong>The</strong><br />
format for data that is being sent to the P300 is a command byte, and length byte<br />
then zero or more bytes <strong>of</strong> data. A similar format is used for reading data from<br />
the P300. Firstly a command byte is sent by the microprocessor. <strong>The</strong>n the P300<br />
returns a length byte followed by the specified amount <strong>of</strong> data bytes.<br />
An interrupt driven transmission is the easiest way to transmit the data. In this<br />
format, the main body <strong>of</strong> the code initiates the transmission. Once the<br />
transmission has started, the SPI interrupt code in the microprocessor completes<br />
the rest <strong>of</strong> the transmission. <strong>The</strong> flowchart in figure 5-1 demonstrates the write<br />
operation [15]. <strong>The</strong> read operation is very similar to this. <strong>The</strong> main difference is<br />
that the microprocessor must feed in dummy data to generate a clock signal for<br />
the P300 to transmit its data out on.<br />
- 25 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
Figure 5-1 Write operation for the P300<br />
<strong>The</strong> server microprocessor also has to communicate with the PC through the SCI<br />
interface. Since the server microprocessor has no other functions to perform, it<br />
was decided to make the microprocessor appear transparent to the PC.<br />
<strong>The</strong>refore, the same format for data transmission was used in the SCI code. In<br />
this way, the majority <strong>of</strong> the computation can be done on the PC, which has<br />
more resources than the microprocessor.<br />
- 26 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
<strong>The</strong> client microprocessor must collect data from the power measurement<br />
circuitry. An ADC on the microprocessor will be used to collect this data by<br />
sampling the output from the power measurement circuit at a rate <strong>of</strong> 100Hz.<br />
<strong>The</strong>se samples will then averaged over a minute and the result will then be sent<br />
to the server. <strong>The</strong> sample rate <strong>of</strong> 100Hz, sixty samples and one byte per sample<br />
gives 6k bytes storage required.<br />
5.3 PC Operating System<br />
<strong>The</strong> choice <strong>of</strong> operating system for the PC needed to be made between DOS,<br />
Windows9x and Linux. Windows9x was discounted almost immediately due to<br />
the added complexity <strong>of</strong> programming in the visual environment. Also, network<br />
and TCP/IP programming under windows is much more difficult due to the<br />
Micros<strong>of</strong>t implementation <strong>of</strong> TCP/IP. This left the choice between DOS and<br />
Linux.<br />
Of these two, Linux was deemed to be a more suitable choice. Linux is a multi-<br />
tasking operating system, which lends itself better to the use <strong>of</strong> a web server. It<br />
also has built-in TCP/IP support that DOS does not have. Finally, there are<br />
embedded versions <strong>of</strong> Linux, such as ELKS, which could be used to port<br />
s<strong>of</strong>tware with a minimum <strong>of</strong> fuss should this system be converted to use an<br />
embedded processor.<br />
5.4 Web Server & PC Interface<br />
<strong>The</strong> PC interface to the microprocessor is fairly simple. It consists <strong>of</strong> setting up<br />
the serial port correctly then transmitting data in the format specified for the<br />
P300 network chip. <strong>The</strong> actual interface does not need to perform many<br />
operations, just to turn the adapter on or <strong>of</strong>f and to read a power value back from<br />
the client. A short program will be written to perform each <strong>of</strong> these operations.<br />
- 27 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
<strong>The</strong>se programs will be initiated by a Perl CGI script, which will be linked to the<br />
web page. By using links <strong>of</strong> the web page, the script will be invoked with<br />
different parameters, which will call the different interface programs. <strong>The</strong> web<br />
server will be responsible for invoking the CGI scripts when the web page links<br />
are followed. <strong>The</strong> web server that was chosen for this thesis is the Linux Apache<br />
web server. This is a very popular web server that includes support for CGI<br />
scripts.<br />
5.5 S<strong>of</strong>tware Summary<br />
This chapter has looked at the various s<strong>of</strong>tware design decisions that were made.<br />
<strong>The</strong>se decisions have been made on the basis <strong>of</strong> the hardware that has been<br />
chosen. An overview <strong>of</strong> how the s<strong>of</strong>tware fits together is given in figure 5-2.<br />
<strong>The</strong> next chapter will look at the design evaluation <strong>of</strong> the thesis.<br />
Web<br />
Server<br />
CGI<br />
Script<br />
Control<br />
Code<br />
- 28 -<br />
SCI<br />
Interface<br />
SPI<br />
Interface<br />
<strong>Power</strong><br />
Measurement<br />
Code<br />
SPI<br />
Interface<br />
Server Client<br />
Figure 5-2 S<strong>of</strong>tware Overview
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
Chapter 6<br />
6.1 Design Evaluation<br />
This chapter will be an evaluation <strong>of</strong> the design and will look at whether the<br />
design met the specifications or not. After this the actual performance <strong>of</strong> the<br />
power line communication will be evaluated.<br />
<strong>The</strong> overall specification was to create a system that would prove that power line<br />
communications is a viable medium for communications in a home automation<br />
system. <strong>The</strong> further specifications for the system were that the client be a power<br />
adapter with the ability to be switched on and <strong>of</strong>f with a server that was<br />
connected to the <strong>Internet</strong> and could control the client.<br />
<strong>The</strong>se objectives were partially met. <strong>The</strong> connection to the <strong>Internet</strong> was<br />
successful and functions as expected. Also, the power measurement circuit will<br />
function as intended, which is to say that the results are inaccurate but accuracy<br />
was never a requirement. However, the other parts <strong>of</strong> the server do not work as<br />
expected. <strong>The</strong> problem lies in the communications between the microprocessors<br />
and the P300 network interface chip. However, it is hoped that in the next two<br />
weeks that these problems will be solved.<br />
6.2 <strong>Power</strong> <strong>Line</strong>s Communication Evaluation<br />
An evaluation <strong>of</strong> the power line communication chip could be carried out using<br />
the development boards. This evaluation looked at aspects <strong>of</strong> the system such as<br />
reliability, data rates and noise / load immunity.<br />
- 29 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
<strong>The</strong> data rates achieved by the development boards were close to 9600 bits per<br />
second. This figure matches fairly closely with the specifications for the CEBus<br />
standard, which states that all command channel data should be transmitted at<br />
10k bits per second regardless <strong>of</strong> medium.<br />
<strong>The</strong> reliability and noise / load immunity all relate to each other. Generally, the<br />
noise immunity was good. <strong>The</strong> testing was conducted in the Axon building,<br />
which has many pieces <strong>of</strong> electrical equipment & computers in use at one time.<br />
In tests it was found that the boards could communicate well across the entire<br />
building provided that they were on the same power phase. Overall, while on the<br />
same phase the boards achieved close to perfect data transmission.<br />
However, when a computer was plugged into the power lines between the two<br />
boards, the performance decreased. Computers are a special problem due to the<br />
large capacitance in their power supply. This capacitance tends to filter out the<br />
communications signal. When the boards used unacknowledged signals, the<br />
reliability <strong>of</strong> transmission dropped to almost zero. However, when the boards<br />
used the acknowledged modes, the reliability <strong>of</strong> transmission only dropped to<br />
80-90%. This shows that using the more reliable modes, although slower, are<br />
much more effective even when large loads are being used in the circuit.<br />
<strong>The</strong> last sets <strong>of</strong> tests were conducted with the boards attempting to communicate<br />
across the different power phases in the building. <strong>The</strong> results from these tests<br />
indicated low reliability. However, it is impressive that there was any<br />
communication at all since the phases in the building are not directly coupled.<br />
Since some homes will use different phases for different parts <strong>of</strong> the house, it is<br />
important that power line communications for home automation systems must<br />
be able to communicate across phases. <strong>The</strong> normal solution for this is to directly<br />
couple the phases. This can be done with some commercially available devices,<br />
or more simply, a correctly rated capacitor can be connected across the two<br />
phases. This is usually sufficient to allow communication to occur.<br />
Unfortunately, we were unable to test this.<br />
- 30 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
<strong>The</strong> next chapter will review the design and the design process. It will also look<br />
at what improvements could be made to this design in the future.<br />
- 31 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
Chapter 7<br />
7.1 Review <strong>of</strong> the Design<br />
This chapter will be looking at the design <strong>of</strong> the system, with the benefit <strong>of</strong><br />
hindsight, and how the design was carried out. <strong>The</strong> three main sub-sections <strong>of</strong><br />
the system will be examined, the power measurement unit, the <strong>Internet</strong><br />
connectivity and the power line communications.<br />
Overall, the biggest problem that was encountered with the design was defining<br />
the topic. Linked with this problem was the original scope <strong>of</strong> the topic as well.<br />
Initially there was a grand plan as to what could be accomplished and it was not<br />
realized until too late, that the plan was not feasible to implement in the<br />
timeframe available. As a result, time was wasted on areas that have not been<br />
included in the final product. This is a problem with the way that the thesis was<br />
approached by the students, and as (soon-to-be) pr<strong>of</strong>essional engineers, it is an<br />
area upon which they need to improve.<br />
<strong>The</strong> areas that were approached ambitiously were that <strong>of</strong> the <strong>Internet</strong><br />
connectivity and the power measurement. Part <strong>of</strong> the original plan was to use an<br />
embedded web server to connect to the <strong>Internet</strong>. This was chosen since an<br />
embedded processor is much cheaper than a PC (the option that we took in the<br />
end). Embedding the web server also has the advantage that the device is<br />
dedicated and can devote all its time to servicing requests whereas a PC will<br />
<strong>of</strong>ten be used for other applications. Although most homes have PCs these days<br />
it is unlikely that most home automation users would be able to install and use<br />
Linux and Apache. <strong>The</strong> final advantage <strong>of</strong> the embedded system is that it is<br />
much more portable than a PC.<br />
<strong>The</strong> power measurement also started as part <strong>of</strong> the grand plan that needed to be<br />
cut back. <strong>The</strong> design <strong>of</strong> accurate watt-hour meters is a complex topic that can be<br />
- 32 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
an entire thesis topic in itself, according to one <strong>of</strong> the department’s lecturers. It<br />
is also an area much more suited to design by a power or electrical engineering<br />
student, rather than a computer systems engineering student. Even when the<br />
topic was reduced to a simple meter that was not accurate, the full implications<br />
<strong>of</strong> designing an interface to the mains supply did not sink in. Resistors only<br />
come with power ratings up to a certain value and so what may have been<br />
feasible for low voltages rapidly become non-feasible for larger voltages.<br />
<strong>The</strong> end result <strong>of</strong> this is that more time should and could have been spent<br />
working on the main focus <strong>of</strong> this thesis, which is the power line<br />
communications. If the topic had been defined earlier and more clearly, then this<br />
thesis would have been completed in a much more efficient manner.<br />
7.2 Future Direction<br />
<strong>The</strong> future direction that this thesis could take is self-evident. Moving back to<br />
the original plan would realize a product much more suitable for use in a modern<br />
home automation system. With an embedded web server the entire server end <strong>of</strong><br />
the system could control and monitor many adapters around the home, all <strong>of</strong><br />
which would gather information about the power consumption within a home.<br />
<strong>The</strong>n either the server itself or an external user could make decisions about<br />
which appliances to run depending upon their power consumption.<br />
This step would involve changing the microprocessor at least in the server. A<br />
suitable processor for the web server would probably be 32 bit with 4Mb <strong>of</strong><br />
external RAM. This should be sufficient to run ELKS or a similar operating<br />
system. <strong>The</strong>n all that is needed is dedicated web server code to handle the HTTP<br />
requests and some code to control the client via the power line communications<br />
network chip. <strong>The</strong> options to connect the web server are either an Ethernet link<br />
or a modem. Considering that most homes these days do not have an Ethernet<br />
<strong>Internet</strong> connection, the use <strong>of</strong> a modem is probably the better choice.<br />
- 33 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
<strong>Internet</strong> security was not looked at in this thesis and this is an important area for<br />
any physical device attached to the <strong>Internet</strong>. An implementation <strong>of</strong> security so<br />
that only authorized users can access the house is essential for any commercial<br />
home automation product.<br />
At the other end <strong>of</strong> the system, the power module could benefit from a much<br />
more accurate design. With an accurate power module, this system could be a<br />
valuable addition to a home automation system even without the <strong>Internet</strong><br />
connectivity. For accuracy, the power module should account for the effects <strong>of</strong><br />
reactive loads for accurate measurements as the current module only measures<br />
the apparent power.<br />
- 34 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
Chapter 8<br />
8.1 Conclusion<br />
<strong>The</strong> overall aim <strong>of</strong> this thesis was to prove that power lines are a feasible<br />
medium through which home automation systems can communicate. <strong>The</strong><br />
method <strong>of</strong> proving this was to design and construct a simple home automation<br />
system that measured the power consumed by an appliance attached to the<br />
system. This system used a client and a server to communicate across the power<br />
lines and exchange information.<br />
Overall, this thesis accomplished some <strong>of</strong> its aims. Although the primary aim <strong>of</strong><br />
proving the power line medium was accomplished, the complete design <strong>of</strong> the<br />
adapter was not. Problems encountered with the power measurement unit were<br />
the main obstacle to the completion <strong>of</strong> the design.<br />
However, power lines were successfully demonstrated to be a viable medium for<br />
communicating within a home automation system, when faced with electrical<br />
conditions not normally found within the average home. <strong>The</strong> ease <strong>of</strong> installation<br />
and the reliability <strong>of</strong> the system show that the power lines are probably the most<br />
cost efficient method <strong>of</strong> communicating within a house.<br />
- 35 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
Appendix A – Schematics<br />
development board<br />
newbrd.sc1<br />
+5V +5V SW_BOT<br />
SW_BOT +5V<br />
+5V<br />
GND<br />
SW_TOP<br />
MODE<br />
E_SO<br />
P_INT*<br />
RXD<br />
MISO<br />
P_RST*<br />
P_CS*<br />
LED_RED<br />
LED_GRN<br />
E_CS*<br />
E_SI<br />
E_SCK<br />
TXD<br />
MOSI<br />
SCK<br />
Modification to Development Board<br />
- 36 -<br />
additional circuitry<br />
other.sc2<br />
SW_TOP<br />
MODE<br />
E_SO<br />
P_INT*<br />
RXD<br />
MISO<br />
P_RST*<br />
P_CS*<br />
LED_RED<br />
LED_GRN<br />
E_CS*<br />
E_SI<br />
E_SCK<br />
TXD<br />
MOSI<br />
SCK<br />
GND
Wall Module<br />
POWER<br />
SW3<br />
J1<br />
1 12 VAC<br />
VAA<br />
20<br />
19<br />
18<br />
17<br />
16<br />
15<br />
14<br />
13<br />
12<br />
11<br />
10<br />
9<br />
8<br />
7<br />
6<br />
5<br />
4<br />
3<br />
2<br />
1<br />
2<br />
3<br />
Neutral<br />
C7<br />
1.0UFX<br />
C18<br />
1.0UFX<br />
ALTERNATE HOST<br />
J2<br />
+5V<br />
20 PIN<br />
USER I/O<br />
D15<br />
P6KE10A<br />
D16<br />
P6KE10A<br />
B_MODE<br />
B_TOP<br />
B_LOAD<br />
B_BOTTOM<br />
E_CS*<br />
E_SO<br />
E_SI<br />
E_SCK<br />
P_4MHZ<br />
P_CS*<br />
P_INT*<br />
P_SCLK<br />
P_SDO<br />
P_SDI<br />
P_RST*<br />
P_RST*<br />
P_CS*<br />
LED_RED<br />
LED_GRN<br />
E_CS*<br />
E_SI<br />
E_SCK<br />
1 2<br />
P_RST*<br />
P_CS*<br />
B_LOAD<br />
B_MODE<br />
E_CS*<br />
E_SI<br />
E_SCK<br />
1<br />
2<br />
L3<br />
820 UH<br />
3 4<br />
VAA<br />
R20<br />
180<br />
TP5 (NI)<br />
1<br />
2<br />
D13<br />
1N5819<br />
T1<br />
12:12<br />
20000392<br />
F1<br />
FUSE<br />
JP2<br />
BUSS WIRE<br />
L1<br />
1.8UH NLC<br />
D6<br />
1N5819<br />
VAA<br />
R4<br />
1K<br />
VAA<br />
D1<br />
1N4002<br />
R6<br />
10K<br />
D2<br />
1N4002<br />
C38<br />
2200UF,25V<br />
C2<br />
0.1UFZ<br />
LED2 D10<br />
R7 LED1<br />
LN31GPHL<br />
10K<br />
(GREEN)<br />
SW2<br />
TXD<br />
MOSI<br />
SCK<br />
C34<br />
.01UFX<br />
JP3<br />
BUSS WIRE<br />
Q1<br />
MMBT3904<br />
TXD<br />
P_SDI<br />
P_SCLK<br />
L5<br />
120UH<br />
D3<br />
1N4002<br />
1<br />
2<br />
3<br />
4<br />
5<br />
6<br />
7<br />
8<br />
D4<br />
1N4002<br />
U5 SSC_P111<br />
VSS<br />
VDD<br />
VSS<br />
TXO<br />
VSS<br />
VDD<br />
TP0<br />
TS<br />
C27<br />
0.1UFZ<br />
L4<br />
180UH<br />
C36<br />
3300PFX<br />
+5V<br />
PB<br />
NC<br />
VSS<br />
NC<br />
CEXT<br />
NC<br />
BIAS<br />
VDD<br />
TXI<br />
+5V<br />
16<br />
15<br />
14<br />
13<br />
12<br />
11<br />
10<br />
9<br />
C35<br />
3300PFX<br />
C37<br />
1500PFX<br />
P_INT*<br />
P_INT*<br />
E_SO<br />
E_SO<br />
B_BOTTOM<br />
SW_BOT<br />
B_TOP<br />
SW_TOP<br />
MODE_JMPR<br />
MODE<br />
RXD<br />
RXD<br />
P_SDO<br />
MISO<br />
C28<br />
22UF,25V<br />
D8<br />
NEWBAV99<br />
C20<br />
3300PFX<br />
1<br />
C23<br />
0.1UFZ<br />
U4<br />
LM2940T-10<br />
Vin<br />
C26<br />
1.0UFX<br />
D5<br />
GND<br />
2<br />
R1<br />
510<br />
NEWBAS16<br />
R26<br />
1.2K<br />
Vout<br />
3<br />
L2<br />
180UH<br />
VAA<br />
TRADE SECRETS<br />
THIS DRAWING AND ITS CONTENTS ARE TRADE SECRETS AND<br />
CONFIDENTIAL BUSINESS INFORMATION OF INTELLON CORPORATION<br />
1<br />
U1<br />
LM7805C<br />
HEAT SINK<br />
C3<br />
0.1UFZ<br />
R22<br />
1K<br />
HEAT SINK<br />
C19<br />
470UF,16V<br />
D12<br />
LN31GPHL<br />
(GREEN)<br />
VAA<br />
R16<br />
75K<br />
1%<br />
+5A<br />
R5<br />
1K<br />
R27<br />
18K<br />
C25<br />
1500PFX<br />
R24<br />
47<br />
D11<br />
LN21RPHL<br />
(RED)<br />
R9<br />
10K<br />
Q2<br />
MMBT3904<br />
+5A<br />
R29<br />
1K<br />
Q3<br />
MMBT3904<br />
C22<br />
3300PFX<br />
Q4<br />
MMBT3904<br />
JP1<br />
MON<br />
TP1 (NI)<br />
POWER<br />
SW1<br />
Vin<br />
R2<br />
13K<br />
AND ARE NOT TO BE USED OR DISCLOSED FOR ANY PURPOSE WITHOUT<br />
THE PRIOR WRITTEN PERMISION OF AN OFFICER OF INTELLON CORPORATION.<br />
PB<br />
VAA<br />
R19<br />
100<br />
+5V<br />
GND<br />
2<br />
R13<br />
10K<br />
R10<br />
10K<br />
C21<br />
3300PFX<br />
NOTE 1: MODEL EB P200: U2 = SSC P200 IC (10000662)<br />
MODEL EB P300: U2 = SSC P300 IC (10000739)<br />
Original Development board Schematic with Modifications<br />
+5V<br />
GND<br />
3<br />
2<br />
1<br />
Vout<br />
3<br />
C9<br />
220PFC<br />
C1<br />
0.1UFZ<br />
R3<br />
1K<br />
+5V<br />
1<br />
P_INT* 2<br />
3<br />
4<br />
R12<br />
10K<br />
P_CS*<br />
P_RST*<br />
5<br />
6<br />
MODE_JMPR 7<br />
8<br />
B_BOTTOM 9<br />
B_LOAD 10<br />
B_TOP 11<br />
B_MODE 12<br />
MTG<br />
MTG<br />
TP4 (NI)<br />
M1<br />
PB0<br />
PB1<br />
PB2<br />
PB3<br />
PB4<br />
PB5<br />
PB6<br />
PB7<br />
13<br />
14<br />
15<br />
16<br />
17<br />
18<br />
19<br />
20<br />
21<br />
22<br />
C15<br />
33PFC<br />
C14<br />
33PFC<br />
C8<br />
0.1UFZ<br />
C5<br />
0.1UFZ<br />
RST*<br />
IRQ*<br />
NC<br />
NC<br />
PA7<br />
PA6<br />
PA5<br />
PA4<br />
PA3<br />
PA2<br />
PA1<br />
PA0<br />
PB0<br />
PB1<br />
PB2<br />
PB3<br />
NC<br />
PB4<br />
PB5<br />
PB6<br />
PB7<br />
VSS<br />
C13<br />
470UF,10V<br />
+5V<br />
Y1<br />
12 MHz<br />
NEWBAS16 R15<br />
100K<br />
VDD<br />
OSC1<br />
OSC2<br />
TCAP<br />
PD7<br />
NC<br />
TCMP<br />
PC0<br />
PC1<br />
PC2<br />
PC3<br />
PC4<br />
PC5<br />
PC6<br />
PC7<br />
NC<br />
U3 MC68HC705C9A (NI)<br />
MOUNTING HOLES<br />
M2<br />
M3<br />
M4<br />
M5<br />
D7<br />
R14<br />
1M<br />
C4<br />
0.1UFZ<br />
31<br />
30<br />
29<br />
28<br />
27<br />
26<br />
25<br />
24<br />
23<br />
C10<br />
0.1UFZ<br />
+5V<br />
CONTRACT NO:<br />
APPROVALS DATE<br />
CHECKED:<br />
ENGINEERING:<br />
MANUFACTURING:<br />
10<br />
USED ON NEXT ASSY<br />
1<br />
2<br />
3<br />
4<br />
5<br />
6<br />
7<br />
8<br />
9<br />
C29<br />
0.1UFZ<br />
C12<br />
C30<br />
44<br />
100PFC<br />
+5V<br />
0.1UFZ<br />
43<br />
42<br />
41<br />
40<br />
39<br />
P_4MHZ<br />
TP3 (NI)<br />
TCAP<br />
R28<br />
10K<br />
C31<br />
0.1UFZ<br />
TP2 (NI)<br />
38 TCMP TCMP<br />
37<br />
PD5/SS*<br />
36 P_SCLK<br />
PD4/SCK<br />
35 P_SDI<br />
PD3/MOSI<br />
34 P_SDO<br />
PD2/MISO<br />
33 TXD<br />
PD1/TDO<br />
32 RXD<br />
PD0/RDI<br />
M6<br />
R17<br />
10<br />
PC2<br />
PC3<br />
E_CS*<br />
E_SO<br />
E_SI<br />
E_SCK<br />
R25<br />
100<br />
R18<br />
0 OHM<br />
R21<br />
100K<br />
REVISIONS<br />
REV ZONE DESCRIPTION APPROVAL DATE<br />
4<br />
ECO #1299<br />
U2 SEE NOTE 1<br />
4MHZ<br />
CS*<br />
VSSD<br />
XIN<br />
XOUT<br />
VDDD<br />
INT*<br />
SCLK<br />
SDO<br />
SDI<br />
+5V<br />
1<br />
CS* VCC<br />
2<br />
SO HLD*<br />
3<br />
WP* SCK<br />
4<br />
VSS SI<br />
8<br />
7<br />
6<br />
5<br />
1<br />
2<br />
3<br />
4<br />
5<br />
6<br />
7<br />
8<br />
VSSD<br />
TP0<br />
VDDA<br />
SI<br />
C1<br />
C2<br />
SO<br />
VSSA<br />
RST*<br />
TS<br />
20<br />
19<br />
18<br />
17<br />
16<br />
15<br />
14<br />
13<br />
12<br />
11<br />
C32<br />
0.1UFZ<br />
U6 MAX232<br />
16<br />
C1+ VCC<br />
15<br />
V+ GND<br />
14<br />
C1- T1OUT<br />
13<br />
C2+ R1IN<br />
12<br />
C2- R1OUT<br />
11<br />
V-<br />
T1IN<br />
10<br />
T2OUT T2IN<br />
9<br />
R2IN R2OUT<br />
RS-232<br />
U7 25C080 R11<br />
10K<br />
EEPROM<br />
Error : LOGO.WMF file not found.<br />
+5V<br />
R8<br />
10K<br />
C6<br />
0.1UFZ<br />
C17<br />
680PFX<br />
C33<br />
1.0UFX<br />
+5A<br />
C11<br />
0.1UFZ<br />
C16<br />
680PFX<br />
INTELLON CORPORATION<br />
5100 WEST SILVER SPRINGS BLVD.<br />
OCALA, FL 34482<br />
TITLE:<br />
SCHEMATIC<br />
EB P200/EB P300 EVALUATION BOARD<br />
SIZE<br />
B<br />
NUMBER:<br />
60000682<br />
REV:<br />
4<br />
PRINT DATE: 13-Oct-1999<br />
SHEET: 1 OF 1<br />
FILE: C:\<strong>The</strong>sis\..\newbrd.sc1 DRAWN: G. LASBY<br />
+5V<br />
C39<br />
R30<br />
33<br />
100UF,16V<br />
RX<br />
RTS<br />
TX<br />
CTS<br />
GND<br />
J3<br />
DB9<br />
1<br />
6<br />
2<br />
7<br />
3<br />
8<br />
4<br />
9<br />
5
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
- 38 -<br />
MODA/LIR<br />
3<br />
PA3/OC5/OC1<br />
31<br />
PA7/PAI/OC1<br />
27<br />
PC0/AD0<br />
9<br />
PC1/AD1<br />
10<br />
PC2/AD2<br />
11<br />
PC3/AD3<br />
12<br />
PC4/AD4<br />
13<br />
PC5/AD5<br />
14<br />
PC6/AD6<br />
15<br />
PC7/AD7<br />
16<br />
PD0/RXD<br />
20<br />
PD1/TXD<br />
21<br />
PD2/MISO<br />
22<br />
PD3/MOSI<br />
23<br />
PD4/SCK<br />
24<br />
PD5/SS<br />
25<br />
RST<br />
17<br />
STRA/AS<br />
4<br />
IRQ<br />
19<br />
EXTAL<br />
7<br />
MODB/VSTBY<br />
2<br />
PA0/IC3<br />
34<br />
PA1/C2<br />
33<br />
PA2/C1<br />
32<br />
PE0/AN0<br />
43<br />
PE1/AN1<br />
45<br />
PE2/AN2<br />
47<br />
PE3/AN3<br />
49<br />
PE4/AN4<br />
44<br />
PE5/AN5<br />
46<br />
PE6/AN6<br />
48<br />
PE7/AN7<br />
50<br />
VRH<br />
52<br />
VRL<br />
51<br />
XIRQ/VPP<br />
18<br />
E<br />
5<br />
PA4/OC4/OC1<br />
30<br />
PA5/OC3/OC1<br />
29<br />
PA6/OC2/OC1<br />
28<br />
PB0/A8<br />
42<br />
PB1/A9<br />
41<br />
PB2/A10<br />
40<br />
PB3/A11<br />
39<br />
PB4/A12<br />
38<br />
PB5/A13<br />
37<br />
PB6/A14<br />
36<br />
PB7/A15<br />
35<br />
STRB/R/W<br />
6<br />
XTAL<br />
8<br />
Vss<br />
1<br />
Vdd<br />
26<br />
UN1<br />
MC68HC11E2(52)<br />
+5v<br />
SW_BOT<br />
SW_TOP<br />
MODE<br />
E_SO<br />
GND<br />
+5V<br />
SW_BOT<br />
SW_TOP<br />
MODE<br />
E_SO<br />
+<br />
CN1<br />
4.7uF_pol<br />
CN2<br />
0.1uF<br />
+5V<br />
+5V<br />
XN1<br />
8Mhz<br />
RN1<br />
10M<br />
CN4<br />
~18pF<br />
CN3<br />
~18pF<br />
RN2<br />
4.7k<br />
RN3<br />
4.7k<br />
+5V<br />
RN4<br />
1k<br />
C5<br />
1uF<br />
IN<br />
2<br />
RSET<br />
1<br />
GND<br />
3<br />
UN2<br />
MC34064<br />
+5V<br />
/RST<br />
/RST<br />
RN5<br />
10k<br />
RN6<br />
4.7K<br />
1<br />
1<br />
2<br />
2<br />
3<br />
3<br />
4<br />
4<br />
5<br />
5<br />
6<br />
6<br />
7<br />
7<br />
8<br />
8<br />
JPN1<br />
PORTE<br />
1<br />
2<br />
3<br />
4<br />
5<br />
6<br />
7<br />
8<br />
JPN2<br />
PORTA<br />
PE0<br />
PE1<br />
PE2<br />
PE3<br />
PE4<br />
PE5<br />
PE6<br />
PE7<br />
PA0<br />
PA1<br />
PA2<br />
PA3<br />
PA4<br />
PA5<br />
PA6<br />
PA7<br />
PE0<br />
PE1<br />
PE2<br />
PE3<br />
PE4<br />
PE5<br />
PE6<br />
PE7<br />
PA0<br />
PA1<br />
PA2<br />
PA3<br />
PA7<br />
RXD<br />
TXD<br />
MISO<br />
P_INT*<br />
PA4<br />
PA5<br />
PA6<br />
P_RST*<br />
P_CS*<br />
LED_RED<br />
LED_GRN<br />
SW_BOT<br />
SW_TOP<br />
MODE<br />
E_CS*<br />
E_SO<br />
E_SI<br />
E_SCK<br />
MOSI<br />
SCK<br />
RN7<br />
10k<br />
+5v<br />
P_INT*<br />
P_INT*<br />
RXD<br />
RXD<br />
MISO<br />
MISO<br />
P_RST*<br />
P_RST*<br />
P_CS*<br />
P_CS*<br />
LED_RED<br />
LED_RED<br />
LED_GRN<br />
LED_GRN<br />
E_CS*<br />
E_CS*<br />
E_SI<br />
E_SI<br />
E_SCK<br />
E_SCK<br />
TXD<br />
TXD<br />
MOSI<br />
MOSI<br />
SCK<br />
SCK<br />
Schematic <strong>of</strong> Additionas to Development Board
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
Appliance<br />
0.1R 7W<br />
33K<br />
47nF<br />
33K<br />
<strong>Power</strong> Measurement Circuit Design<br />
47nF<br />
3<br />
2<br />
- 39 -<br />
On / Off<br />
+5V<br />
8<br />
4<br />
5A FUSE<br />
U1A<br />
1<br />
LM358<br />
10K<br />
56K<br />
100K<br />
+5V<br />
1K<br />
PNP<br />
RELAY-SPST<br />
5<br />
6<br />
220K<br />
U1B<br />
560K<br />
7<br />
LM358<br />
<strong>Power</strong> Active<br />
To ADC<br />
<strong>Power</strong> Neutral
Appendix B – Printed Circuit Board<br />
Top Layer <strong>of</strong> the PCB<br />
Middle <strong>Power</strong> Layers <strong>of</strong> the PCB
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
Bottom Layer <strong>of</strong> the PCB<br />
- 41 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
Appendix C – Code Flowcharts<br />
Flowchart for reading from the P300 Network Chip<br />
- 42 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
Flowchart for Initialization <strong>of</strong> the P300 Network Chip<br />
- 43 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
Appendix D – Assembler Code Listing<br />
*--------------------------------------------------------------------<br />
* tser7.asc<br />
* P300 Initialisation and Serial (SPI) link<br />
* Author: Tony Truong<br />
*--------------------------------------------------------------------<br />
TCTL1 EQU $1020<br />
TCTL2 EQU $1021<br />
TFLG1 EQU $1023<br />
TFLG2 EQU $1025<br />
PORTB EQU $1004<br />
PORTC EQU $1003<br />
PORTD EQU $1008<br />
PORTA EQU $1000<br />
PORTE EQU $100A<br />
DDRC EQU $1007<br />
DDRD EQU $1009<br />
PACTL EQU $1026<br />
TMSK2 EQU $1024<br />
TOC2 EQU $1018<br />
TIC3 EQU $1014<br />
ADCTL EQU $1030<br />
ADR1 EQU $1031<br />
OPTION EQU $1039<br />
BAUD EQU $102B<br />
SCCR1 EQU $102C<br />
SCCR2 EQU $102D<br />
SCSR EQU $102E<br />
SCDR EQU $102F<br />
SPDR EQU $102A<br />
SPCR EQU $1028<br />
SPSR EQU $1029<br />
CONTROL EQU $8000 *LCD control<br />
DATA EQU $8001 *LCD data<br />
BIT0 EQU $01<br />
BIT1 EQU $02<br />
BIT2 EQU $04<br />
BIT3 EQU $08<br />
BIT4 EQU $10<br />
BIT5 EQU $20<br />
BIT6 EQU $40<br />
BIT7 EQU $80<br />
MASK1 EQU $80<br />
REG EQU $1000<br />
TIE EQU $88<br />
RECVEN EQU $24<br />
TRANSEN EQU $88<br />
TRUE EQU $01<br />
ISRIDLE EQU $01<br />
ISRXLEN EQU $02<br />
ISRX EQU $03<br />
ISRRLEN EQU $20<br />
ISRRCV EQU $30<br />
*****************************<br />
* Variables<br />
*****************************<br />
ORG $0000<br />
COUNT RMB 1<br />
MODE RMB 1<br />
*SCIFLAG RMB 1<br />
*SPIFLAG RMB 1<br />
POINTER RMB 2<br />
POINTR2 RMB 2<br />
POINTR3 RMB 2<br />
DIVTMP RMB 2<br />
*RCVCNT RMB 1<br />
- 44 -<br />
*TRNCNT RMB 1<br />
LENGTH RMB 1<br />
STORE FDB $0020<br />
STORE2 FDB $0030<br />
*----------------------------<br />
* IRQ Interrupt vector<br />
*----------------------------<br />
ORG $00EE<br />
JMP ISR<br />
*----------------------------<br />
* auto jump vector<br />
*----------------------------<br />
ORG $B600<br />
JMP BEGIN<br />
*****************************<br />
ORG $C000 *Start <strong>of</strong> program<br />
*****************************<br />
*--------------------------------------------------------------------<br />
* init stack and other setup stuff<br />
*--------------------------------------------------------------------<br />
BEGIN LDAA OPTION<br />
ORAA #BIT5<br />
STAA OPTION<br />
* hardware reset for the P300<br />
CLR PORTB<br />
LDS #$00C3<br />
* setup IO ports for output only<br />
LDAA #$FF<br />
STAA DDRC<br />
* setup data direction for portD for master<br />
LDAA #$38<br />
STAA DDRD<br />
* setup serial peripheral interface w/O interrupt<br />
LDAA #$5C<br />
STAA SPCR<br />
* setup input capture 2<br />
LDAA #BIT2<br />
STAA TCTL2<br />
LDAA #$01<br />
STAA TMSK2<br />
CLR COUNT<br />
*--------------------------------------------------------------------<br />
* LCD INITIALIZATION<br />
*--------------------------------------------------------------------<br />
LDY #CONTROL<br />
CONFIG1 BRSET 0,Y,#BIT7,CONFIG1<br />
LDAA #$30 * FUNCTION SET<br />
STAACONTROL<br />
CONFIG2 BRSET 0,Y,#BIT7,CONFIG2<br />
LDAA #$0F * DISPLAY SETTING<br />
STAACONTROL<br />
CONFIG3 BRSET 0,Y,#BIT7,CONFIG3<br />
LDAA #$07 * SET CURSOR MOVEMENT<br />
STAACONTROL<br />
CONFIG4 BRSET 0,Y,#BIT7,CONFIG4<br />
LDAA #$01 * CLEAR DISPLAY<br />
STAACONTROL<br />
CONFIG5 BRSET 0,Y,#BIT7,CONFIG5<br />
LDAA #$90<br />
STAA CONTROL * DD RAM START LOCATION<br />
LDAB OPTION
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
LDAA #$00<br />
JSR DIVIDE<br />
*--------------------------------------------------------------------<br />
* Setup the buffer for the layer config commands and data<br />
*--------------------------------------------------------------------<br />
* setup the layer config info <strong>of</strong> the P300<br />
CLR COUNT<br />
LDX STORE<br />
STX POINTER<br />
* store the bytes<br />
LDAA #$03 * command byte<br />
STAA 0,X<br />
INX<br />
LDAA #$07 * length byte<br />
STAA 0,X<br />
INX<br />
LDAA #$78 * data byte 0 ?<br />
STAA 0,X<br />
INX<br />
* store the next 6 data bytes with 0<br />
STDATA LDAA #6<br />
CMPA COUNT * check if COUNT has<br />
reached 6 yet<br />
BEQ LAYER * goto LAYER if it has<br />
INC COUNT * otherwise increment<br />
COUNT<br />
LDAA #0 * and store 0<br />
STAA 0,X * to position indexed by<br />
register X<br />
INX * and increment the index<br />
pointer<br />
BRA STDATA<br />
*--------------------------------------------------------------------<br />
* Start <strong>of</strong> Main Program<br />
*--------------------------------------------------------------------<br />
* send the layer config info<br />
LAYER CLR COUNT<br />
CLR LENGTH<br />
CLR MODE<br />
LDAA #$FF<br />
STAA PORTC * deassert CS*<br />
STAA PORTB * deassert RST*<br />
* wait for 52ms to allow P300 to come out <strong>of</strong> reset state<br />
LDD #26000 * 52 ms<br />
ADDD TOC2<br />
STD TOC2<br />
TIMER LDY #TFLG1<br />
BRCLR 0,Y,#BIT6,TIMER<br />
LDAA #BIT6<br />
STAA TFLG1<br />
LDAB #44 * debug<br />
LDAA #0 * debug<br />
JSR DIVIDE * debug<br />
CLR PORTC * assert CS*<br />
* -----------------------<br />
* wait for push button<br />
*------------------------<br />
WAIT LDY #TFLG1<br />
BRCLR 0,Y,#BIT1,WAIT<br />
LDAA #BIT1<br />
STAA TFLG1<br />
*-----------------------<br />
* send the LW command<br />
*-----------------------<br />
LDX STORE * Get the address <strong>of</strong> the<br />
LW buffer<br />
STX POINTER * Save it as an index pointer<br />
- 45 -<br />
LDAB 0,X * Get the command byte<br />
LDAA #$00<br />
JSR DIVIDE * debug<br />
INX * Advance the index<br />
pointer<br />
STX POINTER<br />
STAB SPDR * start the SPI transfer<br />
* wait for the transfer to finish<br />
WAIT2 LDAA SPSR<br />
BPL WAIT2<br />
LDAB #ISRXLEN * Set the mode to...<br />
STAB MODE ...transmitting length<br />
CLI * turn on interrupt<br />
* wait for all the bytes to be sent<br />
WAIT3 LDAA #ISRIDLE<br />
CMPA MODE<br />
BNE WAIT3<br />
LDD #$0000<br />
LDAB COUNT<br />
JSR DIVIDE<br />
*-----------------------<br />
* wait for push button<br />
*-----------------------<br />
WAIT4 LDY #TFLG1<br />
BRCLR 0,Y,#BIT1,WAIT4<br />
LDAA #BIT1<br />
STAA TFLG1<br />
*-----------------------<br />
* send the IR command<br />
*-----------------------<br />
CREAD CLR COUNT<br />
CREAD2 LDX STORE2<br />
STX POINTR2<br />
LDAA #$04<br />
STAA SPDR<br />
CREAD3 LDAA SPSR<br />
BPL CREAD3<br />
LDAA #ISRRLEN<br />
STAA MODE<br />
CLI<br />
CREADTS LDAA #ISRIDLE<br />
CMPA MODE<br />
BNE CREADTS<br />
LDAA #$FF<br />
STAA PORTC<br />
***************************************************<br />
* ISR<br />
***************************************************<br />
ISR PSHA<br />
PSHB<br />
PSHX<br />
* check for which mode, idle, transfer, if neither then read<br />
LDAA MODE<br />
CMPA #ISRIDLE * is it idling now?<br />
BEQ ISROFF<br />
CMPA #ISRX * is it transmitting the<br />
data?<br />
BEQ ISRW
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
CMPA #ISRXLEN * is it transmitting the<br />
length?<br />
BEQ ISRWLEN<br />
CMPA #ISRRCV * is it receiving the data?<br />
BEQ ISRR<br />
CMPA #ISRRLEN * is it receiving the<br />
length?<br />
BEQ ISRLEN<br />
BRA ISRDONE<br />
*-------------------------------------------------------------<br />
* write command: transfer length byte<br />
*-------------------------------------------------------------<br />
ISRWLEN LDX POINTER * Retrieve<br />
current index<br />
LDAA 0,X * Get<br />
length<br />
STAA LENGTH * Store length<br />
STAA SPDR * Start<br />
the transfer <strong>of</strong> the length<br />
WLWAIT LDAA SPSR * Wait for<br />
the transfer...<br />
BPL WLWAIT ...to finish<br />
LDAA #ISRX * Change<br />
the mode...<br />
STAA MODE ...to transmitting data<br />
INX<br />
STX POINTER<br />
BRA ISRDONE<br />
*--------------------------------------------------------------<br />
* write command: transfer data<br />
*--------------------------------------------------------------<br />
ISRW LDAA LENGTH * Test for<br />
the interrupt...<br />
CMPA COUNT ...after the last byte<br />
BEQ ISROFF<br />
LDX POINTER * Retrieve the current<br />
index<br />
LDAA 0,X * Get the<br />
data<br />
STAA SPDR * Start<br />
the transfer <strong>of</strong> the data<br />
INC COUNT *<br />
Increment number <strong>of</strong> data sent<br />
INX *<br />
Advance the index pointer<br />
STX POINTER<br />
WWAIT LDAA SPSR * Wait for the transfer...<br />
BPL WWAIT ...to finish<br />
BRA ISRDONE<br />
*--------------------------------------------------------------<br />
* read command: get the length byte<br />
*--------------------------------------------------------------<br />
ISRLEN LDAA #0 * Start the transfer with<br />
a...<br />
STAA SPDR ...dummy input <strong>of</strong> 0<br />
LWAIT LDAA SPSR * Wait for the transfer...<br />
BPL LWAIT ...to finish<br />
LDAA SPDR * Get the<br />
length value...<br />
STAA LENGTH ...and store it<br />
LDX POINTR2 * Get the store index<br />
pointer...<br />
STAA 0,X ...and<br />
store it<br />
INX *<br />
Advance the pointer<br />
STX POINTR2<br />
- 46 -<br />
LDAA #ISRRCV * Change the mode...<br />
STAA MODE ...to receiving data<br />
BRA ISRDONE<br />
* If you have read this please underline.<br />
*---------------------------------------------------------------<br />
* read command: get data and wait for interrupt after last<br />
byte<br />
*---------------------------------------------------------------<br />
ISRR LDAA LENGTH * Test for the interrupt...<br />
CMPA COUNT ...after the last byte<br />
BEQ ISROFF<br />
LDAA #0 * Start<br />
the transfer with a...<br />
STAA SPDR ...dummy input <strong>of</strong> 0<br />
RWAIT LDAA SPSR * Wait for the transfer...<br />
BPL RWAIT ...to finish<br />
LDX POINTR2 * Get the store index<br />
pointer<br />
LDAA SPDR * Get the<br />
data<br />
STAA 0,X * Store<br />
the data<br />
INX *<br />
Advance the store index pointer<br />
STX POINTR2<br />
INC COUNT *<br />
Increment the data count<br />
BRA ISRDONE<br />
*----------------------------------------------------------------<br />
ISROFF LDAA #ISRIDLE<br />
STAA MODE<br />
SEI<br />
ISRDONE PULX<br />
PULB<br />
PULA<br />
RTRN RTI * return<br />
from interrupt<br />
*****************************************************************<br />
**<br />
*--------------------------------------------------------------------<br />
* WRITE SUBROUTINE<br />
*--------------------------------------------------------------------<br />
WRITES LDAA MODE<br />
LDX POINTER<br />
LDAB 0,X * get the<br />
next byte<br />
STAB SPDR * start the<br />
SPI transfer<br />
INC COUNT<br />
* wait for the transfer to finish<br />
WRWAIT LDAA SPSR<br />
BPL WRWAIT<br />
INX<br />
STX POINTER<br />
RTS<br />
*--------------------------------------------------------------------<br />
* READ SUBROUTINE<br />
*--------------------------------------------------------------------<br />
* load dummy byte to start xfers<br />
READS LDAA #$00<br />
STAA SPDR<br />
* wait for spif (when xfer complete)<br />
ISRWAIT LDAA SPSR
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
BPL ISRWAIT<br />
* read the recieved data and store in buffer<br />
RSTORE LDAA SPDR<br />
RSTORE2 LDX POINTR2<br />
STAA 0,X<br />
INX<br />
STX POINTR2<br />
INC COUNT<br />
RTS<br />
*--------------------------------------------------------------------<br />
* DIVIDE SUBROUTINE<br />
*--------------------------------------------------------------------<br />
DIVIDE PSHX<br />
LDX #100<br />
IDIV * DIVIDE D REG WITH<br />
100 TO GET THE HUNDREDS<br />
STD DIVTMP * STORE THE<br />
REMAINDER<br />
XGDX * PUT THE RESULT IN D<br />
TBA * SINCE D IS A&B SWAP<br />
SO WE CAN JUMP TO LCD SUB<br />
JSR LCD<br />
LDX #10<br />
LDD DIVTMP * GET OUR REMAINDER<br />
IDIV * DIVIDE BY 10 TO GET<br />
OUR TENS<br />
STD DIVTMP * STORE OUR<br />
REMAINDING ONES<br />
XGDX<br />
TBA<br />
JSR LCD<br />
LDX #1<br />
LDD DIVTMP * GET OUR REMAINDER<br />
IDIV * DON'T ASK WHY BUT<br />
IT DOESN'T WORK OTHER WAYS<br />
XGDX<br />
TBA<br />
JSR LCD<br />
PULX<br />
RTS<br />
*--------------------------------------------------------------------<br />
* LCD SUBROUTINE<br />
*--------------------------------------------------------------------<br />
LCD PSHY<br />
LDY #CONTROL<br />
CMPA #0<br />
BEQ ZERO<br />
CMPA #1<br />
BEQ ONE<br />
CMPA #2<br />
BEQ TWO<br />
CMPA #3<br />
BEQ THREE<br />
CMPA #4<br />
BEQ FOUR<br />
CMPA #5<br />
BEQ FIVE<br />
CMPA #6<br />
BEQ SIX<br />
CMPA #7<br />
BEQ SEVEN<br />
CMPA #8<br />
BEQ EIGHT<br />
- 47 -<br />
CMPA #9<br />
BEQ NINE<br />
BRA DEFAULT<br />
ZERO BRSET 0,Y,#BIT7,ZERO<br />
LDAA #$30<br />
STAA DATA<br />
BRA LCDDONE<br />
ONE BRSET 0,Y,#BIT7,ONE<br />
LDAA #$31<br />
STAADATA<br />
BRA LCDDONE<br />
TWO BRSET 0,Y,#BIT7,TWO<br />
LDAA #$32<br />
STAADATA<br />
BRA LCDDONE<br />
THREE BRSET 0,Y,#BIT7,THREE<br />
LDAA #$33<br />
STAADATA<br />
BRA LCDDONE<br />
FOUR BRSET 0,Y,#BIT7,FOUR<br />
LDAA #$34<br />
STAADATA<br />
BRA LCDDONE<br />
FIVE BRSET 0,Y,#BIT7,FIVE<br />
LDAA #$35<br />
STAADATA<br />
BRA LCDDONE<br />
SIX BRSET 0,Y,#BIT7,SIX<br />
LDAA #$36<br />
STAADATA<br />
BRA LCDDONE<br />
SEVEN BRSET 0,Y,#BIT7,SEVEN<br />
LDAA #$37<br />
STAADATA<br />
BRA LCDDONE<br />
EIGHT BRSET 0,Y,#BIT7,EIGHT<br />
LDAA #$38<br />
STAADATA<br />
BRA LCDDONE<br />
NINE BRSET 0,Y,#BIT7,NINE<br />
LDAA #$39<br />
STAADATA<br />
DEFAULT BRA LCDDONE<br />
LCDDONE PULY<br />
RTS<br />
END<br />
*--------------------------------------------------------------------<br />
* tser.asm<br />
* receive data from PC and send to PORTB<br />
* Serial (SCI) link<br />
* $Author: Quentin Alick & Tony Truong<br />
*--------------------------------------------------------------------<br />
TCTL1 EQU $1020<br />
TCTL2 EQU $1021<br />
TFLG1 EQU $1023<br />
TFLG2 EQU $1025<br />
PORTB EQU $1004<br />
PORTC EQU $1003<br />
PORTD EQU $1008<br />
PORTA EQU $1000<br />
PORTE EQU $100A<br />
DDRC EQU $1007<br />
DDRD EQU $1009<br />
PACTL EQU $1026<br />
TMSK2 EQU $1024<br />
TOC2 EQU $1018
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
TIC3 EQU $1014<br />
ADCTL EQU $1030<br />
ADR1 EQU $1031<br />
OPTION EQU $1039<br />
BAUD EQU $102B<br />
SCCR1 EQU $102C<br />
SCCR2 EQU $102D<br />
SCSR EQU $102E<br />
SCDR EQU $102F<br />
CONTROL EQU $8000 *LCD control<br />
DATA EQU $8001 *LCD data<br />
BIT0 EQU $01<br />
BIT1 EQU $02<br />
BIT2 EQU $04<br />
BIT3 EQU $08<br />
BIT4 EQU $10<br />
BIT5 EQU $20<br />
BIT6 EQU $40<br />
BIT7 EQU $80<br />
MASK1 EQU $80<br />
REG EQU $1000<br />
TIE EQU $88<br />
RECVEN EQU $24<br />
TRANSEN EQU $88<br />
*****************************<br />
* Variables<br />
*****************************<br />
ORG $0000<br />
COUNT RMB 1<br />
SCIFLAG RMB 1<br />
POINTER RMB 2<br />
POINTR2 RMB 2<br />
POINTR3 RMB 2<br />
DIVTMP RMB 2<br />
RCVCNT RMB 1<br />
TRNCNT RMB 1<br />
LENGTH RMB 1<br />
STORE FDB $0020<br />
*----------------------------<br />
* SCI interrupt vector<br />
*----------------------------<br />
ORG $00C4<br />
JMP SCIISR<br />
*----------------------------<br />
* SPI Interrupt vector<br />
*----------------------------<br />
*****************************<br />
ORG $C000 *Start <strong>of</strong> program<br />
*****************************<br />
*--------------------------------------------------------------------<br />
* init stack and other setup stuff<br />
*--------------------------------------------------------------------<br />
LDS #$00C3<br />
* setup IO ports for output only<br />
LDAA #$FF<br />
STAA DDRC<br />
STAA DDRD<br />
* init SCI interface, 9600, 8N1, recv<br />
LDAA #$30<br />
STAA BAUD<br />
LDAA #$00<br />
STAA SCCR1 * 8N1<br />
LDAA #RECVEN * enable recv w/ ints<br />
STAA SCCR2 * recv<br />
* STAA RDATA * set init state<br />
- 48 -<br />
* init the storage index and set input capture 2 for low -<br />
high<br />
LDX STORE<br />
STX POINTER<br />
STX POINTR2<br />
LDAA #BIT2<br />
STAA TCTL2<br />
* init variables<br />
CLR RCVCNT<br />
CLR TRNCNT<br />
CLR LENGTH<br />
CLI<br />
START LDX STORE<br />
STX POINTR3<br />
CLR COUNT<br />
* poll for a pushbutton on IC2 (PA1)<br />
LOOP LDY #TFLG1<br />
BRCLR 0,Y,#BIT1,LOOP<br />
LDAA #BIT1 * clear flag<br />
STAA TFLG1<br />
LDD #$0000<br />
LDAB LENGTH<br />
JSR DIVIDE<br />
INC COUNT<br />
LDX POINTR3<br />
LDAA 0,X * output the data<br />
STAA PORTB<br />
INX<br />
STX POINTR3<br />
* check if we have output all the data<br />
* reset variables if so otherwise move onto next data<br />
LDAA LENGTH<br />
INCA<br />
INCA<br />
CMPA COUNT<br />
BEQ START<br />
BRA LOOP<br />
***************************************************<br />
* SCI ISR<br />
***************************************************<br />
SCIISR LDAB SCSR<br />
STAB SCIFLAG *store flags for later checks<br />
* check for valid recv interrupt<br />
BRSET SCIFLAG,#BIT5,RECV<br />
* check for valid trans interrupt<br />
BRSET SCIFLAG,#BIT7,TRANS<br />
* else invalid interrupt<br />
BRA RTRN<br />
*---------------------------------------<br />
* valid receive interrupt<br />
*---------------------------------------<br />
RECV LDAB SCDR * read the data reg<br />
LDY POINTER * load the index pointer<br />
STAB 0,Y * store at index<br />
INC RCVCNT<br />
CHECK1 LDAB #$02 * check to see if<br />
CMPB RCVCNT * its the second packet<br />
BNE CHECK2 * if not then goto CHECK2...<br />
LDY POINTER * if it is the second packet<br />
LDAB 0,Y * we have the length byte
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
STAB LENGTH * so store it in a variable<br />
CHECK2 LDAB LENGTH * check to see if the number<br />
<strong>of</strong><br />
INCB * packet received is equal to<br />
INCB * == length <strong>of</strong> data + first command<br />
byte + length byte<br />
CMPB RCVCNT * i.e is length + 2 = rcvcnt ?<br />
BNE DONE * if not then goto DONE<br />
* if the length <strong>of</strong> data + 2 is equal to the num <strong>of</strong><br />
packet receive<br />
* then do something here, like echo back.<br />
* turn on the transmit interrupt and disable the<br />
receive interrupt<br />
* note that TDRE is already set so once this routine<br />
is returned<br />
* it will call an interrupt<br />
LDAA #TRANSEN<br />
STAA SCCR2<br />
DONE LDY POINTER * increase<br />
INY * the index pointer<br />
STY POINTER * by one<br />
JMP RTRN<br />
*---------------------------------------<br />
* valid transmit interrupt<br />
*---------------------------------------<br />
TRANS LDAB LENGTH * check to see if the number<br />
<strong>of</strong><br />
- 49 -<br />
INCB * packet transmitted is equal to<br />
INCB * == length <strong>of</strong> data + first command<br />
byte + length byte<br />
CMPB TRNCNT * ie. is length + 2 = trncnt ?<br />
BNE MORE * if not then goto MORE<br />
* the entire message has been sent so disable the<br />
transmit interrupt<br />
* and enable the receive interrupt again.<br />
* for now just turn <strong>of</strong>f the entire thing<br />
* LDY STORE<br />
* STY POINTR2<br />
* CLR TRNCNT<br />
CLR SCCR2<br />
MORE LDY POINTR2 * get the message current<br />
location<br />
LDAB 0,Y * get the byte in the message<br />
STAB SCDR * store it in the data reg, this also<br />
clears TDRE<br />
INC TRNCNT * increase the transmitted byte<br />
count<br />
INY<br />
STY POINTR2<br />
RTRN RTI * return from int
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
Appendix E – C Code Listing<br />
* Trying to add recieve (hc11 transmit) to the programme<br />
- needed for overrun<br />
*<br />
* Quenten Alick<br />
* 3/8/99<br />
*<br />
* Modified by Tony Truong<br />
* 17/8/99<br />
*/<br />
#include <br />
#include <br />
#include <br />
#include <br />
#include <br />
#include <br />
#include <br />
#include <br />
/* baudrate settings are defined in ,<br />
which is<br />
included by */<br />
#define BAUDRATE B9600<br />
/* change this definition for the correct port */<br />
#define SERIALDEVICE "/dev/ttyS1"<br />
#define _POSIX_SOURCE 1 /* POSIX compliant source<br />
*/<br />
#define FALSE 0<br />
#define TRUE 1<br />
#define DATA 0x0d<br />
volatile int STOP=FALSE;<br />
void main(void)<br />
{<br />
int fd,c, res;<br />
double i;<br />
int j;<br />
int cnt;<br />
int baud_ok;<br />
struct termios oldtio,newtio;<br />
unsigned char buffer;<br />
unsigned char recvbuf;<br />
/*<br />
Open serial device for reading and writing and not as<br />
controlling tty<br />
because we don't want to get killed if linenoise sends<br />
CTRL-C.<br />
*/<br />
fd = open(SERIALDEVICE, O_RDWR | O_NOCTTY |<br />
O_NONBLOCK);<br />
if (fd
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
if (errno == 11) {<br />
fprintf (stdout, "this error ok, data not there yet.<br />
implementation for retries / timeout not done!\n");<br />
exit(1);<br />
}<br />
else {<br />
fprintf (stdout, "read error!\tbytes read: %d\terrno:<br />
%d\n", cnt, errno);<br />
}<br />
}<br />
printf("receive: -%p-\n", recvbuf);<br />
/*<br />
* delay to prevent overruns, will have to be<br />
implemented with ack - checking OR flag in hc11<br />
*/<br />
for(i = 0; i < 500000; i++)<br />
;<br />
/*sleep(1);*/<br />
}<br />
}<br />
/*<br />
* Original Author: Stan JK<br />
*<br />
* Modified by: Tony Truong<br />
*<br />
* File: mod_main.c<br />
*/<br />
#define _mod_main_owner<br />
#include "standard.h"<br />
void main( void )<br />
{<br />
DisableInterrupts();<br />
ResetStackPtr();<br />
/*<br />
* initialize all ports, set all directions as inputs and<br />
* clear all control registers<br />
*/<br />
PORTB = 0xff;<br />
PORTC = 0;<br />
PORTD = 0x20; /* keep SS* <strong>of</strong>f */<br />
DDRA = 0;<br />
DDRB = 0;<br />
DDRC = 0;<br />
DDRD = 0;<br />
SPCR = 0;<br />
SCCR1 = 0;<br />
SCCR2 = 0;<br />
RST = LOW;<br />
COPCR = 0; /* Disable watchdog */<br />
DDRC = PORTCdirection;<br />
DDRD = PORTDdirection;<br />
/*<br />
* set master mode<br />
* set SCK polarity at logic 1<br />
* set SCK phase to edge after 1 st to latch<br />
* set SPI clock rate<br />
* and enable SPI<br />
*/<br />
SPCR = MSTR | CPOL | CPHA | SPR | SPE;<br />
NIC_CS = HIGH;<br />
EEROM_CS = HIGH;<br />
RST = HIGH;<br />
- 51 -<br />
/*<br />
* wait for NIC to complete its internal reset<br />
* wait for approx 51.2 msec.<br />
*/<br />
*i = GetLowResTimeByte() + 100;<br />
while(*i != GetLowResTimeByte()) ;<br />
/*<br />
* Initialize utilities/layers and execute application:<br />
*/<br />
InitializeTimer();<br />
EnableInterrupts();<br />
InitializeSerial();<br />
/*<br />
* wait for initailize to compete<br />
*/<br />
if(InitializeEval()) {<br />
While(1)<br />
UpdateEval();<br />
}<br />
}<br />
/*<br />
* Original Author: Stan JK<br />
*<br />
* Modified and adapted for the MCHC11A1 by: Tony<br />
Truong<br />
*<br />
* File: evaluate.c<br />
*/<br />
#include "standard.h"<br />
/*<br />
* transmitter device to RS232 host command functionIDs<br />
*/<br />
#define ABORT_CMD ('A')<br />
#define DELAY_CMD ('D')<br />
#define NIC_ID_CMD ('N')<br />
#define PROGRESS_CMD ('P')<br />
#define QUERY_CMD ('Q')<br />
#define RUNNING_CMD ('R')<br />
#define STATS_CMD ('S')<br />
#define TRANS_START_CMD ('T')<br />
/*<br />
* transmitter device to remote device info field headers<br />
*/<br />
#define SETUP_PKT 0x01<br />
#define LOOPBACK_PKT 0x02<br />
#define COUNT_RESP_PKT 0x03<br />
#define RESET_COUNT 0x04<br />
#define GET_COUNT_PKT 0x05<br />
#define TRANS_PKT 0x0f<br />
/*<br />
* timer value based on 131msec/tick<br />
*/<br />
#define TWO_SECS 14<br />
void RecdRunningCmd(void);<br />
void RecdSetupPkt(void);<br />
void XmitOriginal(void);<br />
void StatsToHost(boolean recdPkts);<br />
boolean ProcessTransmitEnd(boolean forced);<br />
void ProcessValidPacket(void);<br />
booleans EV;<br />
booleans EV2;
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
#define transmitter (EV.b0) /* set when<br />
transmitter device */<br />
#define transmitCompleted (EV.b1)<br />
#define GetCountRecd (EV.b2)<br />
#define TransPktRecd (EV.b3)<br />
#define transmitting (EV.b4)<br />
#define responseTimerRunning (EV.b5)<br />
#define waitingForLoopback (EV.b6)<br />
#define testRunning (EV.b7)<br />
#define LoopbackPktReady (EV2.b0)<br />
uint8 type;<br />
/*<br />
* transmitter device counters<br />
*/<br />
unsigned short int txMax;<br />
unsigned short int txSuccess;<br />
unsigned short int txRcvValid;<br />
uint8 txLength;<br />
uint8 txService;<br />
unsigned short int txCount;<br />
/*<br />
* timer used while waiting for looped back or response<br />
packet from remote device<br />
*/<br />
uint8 response_timer;<br />
/*<br />
* remote device counters<br />
*/<br />
unsigned short int rxCount;<br />
unsigned short int rxValidCount;<br />
uint8 InitializeEval( void )<br />
{<br />
#define MAX_RESTARTS 0x0f<br />
boolean validPacket;<br />
boolean Initialized = FALSE;<br />
/*<br />
* initialize flags and progress LED<br />
*/<br />
LED_1 = OFF;<br />
responseTimerRunning = FALSE;<br />
waitingForLoopback = FALSE;<br />
transmitCompleted = FALSE;<br />
testRunning = FALSE;<br />
LoopbackPktReady = FALSE;<br />
GetCountRecd = FALSE;<br />
TransPktRecd = FALSE;<br />
config.modeByte = DLL | (MAX_RESTARTS
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
/*<br />
* continually update logical link background process<br />
*/<br />
UpdateLL();<br />
/*<br />
* REMOTE DEVICE:<br />
*<br />
* after the "get count" packet has been received, and<br />
when the transmit<br />
* buffer becomes available, load the "received valid<br />
counter" value<br />
* and transmit to the transmitter device<br />
*/<br />
if(GetCountRecd && TxBfrAvailable) {<br />
GetCountRecd = FALSE;<br />
txLPDU.LPDUheader = rxLPDU.LPDUheader;<br />
txLPDU.DA.LSB = 0x01;<br />
txLPDU.DA.MSB = 0x00;<br />
txLPDU.DHC.LSB = config.systemAddr.LSB;<br />
txLPDU.DHC.MSB = config.systemAddr.MSB;<br />
txLPDU.SA.LSB = config.unitAddr.LSB;<br />
txLPDU.SA.MSB = config.unitAddr.MSB;<br />
txLPDU.SHC.LSB = config.systemAddr.LSB;<br />
txLPDU.SHC.MSB = config.systemAddr.MSB;<br />
txLPDU.LSDU[0] = COUNT_RESP_PKT;<br />
txLPDU.LSDU[1] = HIGH_BYTE_OF(rxValidCount);<br />
txLPDU.LSDU[2] = LOW_BYTE_OF(rxValidCount);<br />
txLPDU.LPDUlength = CEBUS_HEADER_LEN + 3;<br />
transmitCompleted = FALSE;<br />
TransmitPacket(USE_WTI | USE_DELAY); /* use<br />
WTI w/ delay */<br />
/*<br />
* background processing is complete--free<br />
receive packet buffer resource<br />
*/<br />
RxBfrAvailable = TRUE;<br />
}<br />
/*<br />
* REMOTE DEVICE:<br />
*<br />
* after the "transmit" packet has been received, and<br />
when the transmit buffer becomes available, validate the<br />
received "transmit" packet and, if valid, create the "loop<br />
back" packet and queue the transmission via<br />
LoopbackPktReady (see ProcessValidPacket())<br />
*<br />
* toggle progress LED after every 10 packets with valid<br />
counts<br />
* NOTE: A "valid" packet contains valid count AND<br />
valid info in rest<br />
* <strong>of</strong> body (see ProcessValidPacket())<br />
*/<br />
if (TransPktRecd && TxBfrAvailable) {<br />
TransPktRecd = FALSE;<br />
/*<br />
* get received packet's count<br />
*/<br />
tempCtr = (((unsigned short int)rxLPDU.LSDU[1]) rxCount) {<br />
rxCount = tempCtr + 1;<br />
ProcessValidPacket();<br />
}<br />
if ((rxCount % 10) == 0)<br />
LED_1 = !LED_1;<br />
/*<br />
* background processing is complete--free<br />
receive packet buffer resource<br />
*/<br />
RxBfrAvailable = TRUE;<br />
}<br />
/*<br />
* TRANSMITTER & REMOTE DEVICES:<br />
* get current transmit status and process<br />
*/<br />
status = ConfirmTransmitPacket();<br />
if (status==SUCCESS || status==FAILURE)<br />
if(transmitting && (status==SUCCESS) )<br />
txSuccess++;<br />
transmitCompleted = TRUE;<br />
}<br />
/*<br />
* TRANSMITTER DEVICE:<br />
* when currently transmitting and after completing a<br />
transmit and when<br />
* no longer waiting for the remote device to loop back<br />
the packet,<br />
* process the next transmit packet unless the transmit<br />
test is ended<br />
*/<br />
if (transmitting && !waitingForLoopback &&<br />
transmitCompleted)<br />
if(!ProcessTransmitEnd(FALSE)) /* if not end,<br />
transmit next packet */<br />
XmitOriginal();<br />
/*<br />
* REMOTE DEVICE:<br />
* when loopback packet is loaded and transmit<br />
completed, send loopback<br />
* packet to transmitter device<br />
*/<br />
if(LoopbackPktReady && transmitCompleted) {<br />
LoopbackPktReady = FALSE;<br />
transmitCompleted = FALSE;<br />
TransmitPacket(USE_WTI | USE_DELAY);<br />
}<br />
/*<br />
* TRANSMITTER DEVICE:<br />
* if "loopback" or response packet has not been<br />
received from remote device<br />
* in two seconds, continue with next transmit or send<br />
transmitter device ONLY<br />
* statistics to host<br />
*/<br />
if(responseTimerRunning) {<br />
if(response_timer == GetVeryLowResTimeByte()<br />
) else {<br />
responseTimerRunning = FALSE;<br />
if(waitingForLoopback) {<br />
if(!ProcessTransmitEnd(FALSE)) /* if not end, transmit<br />
next packet */<br />
XmitOriginal();<br />
} else {
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
}<br />
}<br />
}<br />
StatsToHost(FALSE);<br />
/*<br />
* TRANSMITTER DEVICE:<br />
* process commands from host<br />
*/<br />
if (rbufferValid) { /* command from RS232 */<br />
if(transmitter) {<br />
if(rbuffer.functionID == RUNNING_CMD) {<br />
/*<br />
* process "run" command<br />
*/<br />
RecdRunningCmd();<br />
} else if (rbuffer.functionID == ABORT_CMD) {<br />
/*<br />
* clear running flags<br />
*/<br />
testRunning = FALSE;<br />
transmitting = FALSE;<br />
responseTimerRunning = FALSE;<br />
} else if(rbuffer.functionID ==<br />
DELAY_CMD) {<br />
/*<br />
* set interpacket delay flag (remote device gets<br />
updated at<br />
* start <strong>of</strong> test via "reset count" packet)<br />
*/<br />
if(rbuffer.buf[0] == 0)<br />
UseDelay = FALSE;<br />
else<br />
UseDelay = TRUE;<br />
} else if(rbuffer.functionID == QUERY_CMD) {<br />
host<br />
/*<br />
* set running flags, retrieve statistics and send to<br />
*/<br />
transmitter = TRUE;<br />
testRunning = TRUE;<br />
ProcessTransmitEnd(TRUE); /* force end */<br />
} else if(rbuffer.functionID ==<br />
TRANS_START_CMD) {<br />
/*<br />
* accept "start" command only if not already in test<br />
*<br />
* retrieve parameters from host<br />
* send "reset counter" and interpacket delay flag to<br />
remote device<br />
* set waitingForLoopback to kick <strong>of</strong>f the transmission <strong>of</strong><br />
packets<br />
*/<br />
if (!testRunning) {<br />
LED_1 = OFF;<br />
testRunning = TRUE;<br />
txMax = (((unsigned short int)rbuffer.buf[1])<br />
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
* TRANSMITTER DEVICE and test in<br />
process:<br />
*<br />
* validate "loop back" packet and set<br />
counter accordingly<br />
*/<br />
if<br />
LOOPBACK_PKT) {<br />
(rxLPDU.LSDU[0] ==<br />
responseTimerRunning =<br />
FALSE; /* kill wait timer */<br />
/*<br />
* compare received to transmitted<br />
*/<br />
validCompare = TRUE;<br />
if (( (rxLPDU.LPDUheader &<br />
~SEQUENCE_NO) ==<br />
(txLPDU.LPDUheader<br />
~SEQUENCE_NO) ) &&<br />
(rxLPDU.SA.LSB == 0x02) &&<br />
(rxLPDU.SA.MSB == 0x00) &&<br />
&<br />
(rxLPDU.SHC.LSB<br />
config.systemAddr.LSB) &&<br />
==<br />
(rxLPDU.SHC.MSB<br />
config.systemAddr.MSB) &&<br />
==<br />
(rxLPDU.LPDUlength<br />
txLPDU.LPDUlength) ) {<br />
==<br />
for(i=1;i
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
* TRANSMITTING DEVICE:<br />
*<br />
* retrieve house code and initialize NIC<br />
*/<br />
config.systemAddr.MSB = rbuffer.buf[1];<br />
config.systemAddr.LSB = rbuffer.buf[0];<br />
config.unitAddr.LSB = 0x01;<br />
config.unitAddr.MSB = 0x00;<br />
transmitter = TRUE; /* set transmitter device<br />
status */<br />
testRunning = FALSE;<br />
DisableInterrupts();<br />
rbuffer.state = REC_IDLE; /* reset serial state to<br />
idle */<br />
EnableInterrupts();<br />
InitializeLL();<br />
/*<br />
* transmit "setup" packet to remote device if transmit<br />
buffer available<br />
*/<br />
if(TxBfrAvailable) {<br />
txLPDU.LPDUheader = UNACK |<br />
STD_PRIORITY | BASIC_SERVICE;<br />
txLPDU.DA.LSB = 0x00;<br />
txLPDU.DA.MSB = 0x00;<br />
txLPDU.DHC.LSB = 0x00;<br />
txLPDU.DHC.MSB = 0x00;<br />
txLPDU.SA.LSB = config.unitAddr.LSB;<br />
txLPDU.SA.MSB = config.unitAddr.MSB;<br />
txLPDU.SHC.LSB = config.systemAddr.LSB;<br />
txLPDU.SHC.MSB = config.systemAddr.MSB;<br />
txLPDU.LSDU[0] = SETUP_PKT;<br />
*(uint16 *)&txLPDU.LSDU[1] = config.systemAddr;<br />
txLPDU.LPDUlength = CEBUS_HEADER_LEN + 3;<br />
transmitCompleted = FALSE;<br />
TransmitPacket(0); /* use PT command w/o delay */<br />
/*<br />
* respond to host with NIC type<br />
*/<br />
if(!tbufferInUse) {<br />
tbuffer.functionID = NIC_ID_CMD;<br />
tbuffer.buf = &type;<br />
ResponseToHost(size<strong>of</strong>(uint8));<br />
}<br />
transmitting = FALSE; /* wait for "start"<br />
command */<br />
}<br />
}<br />
void RecdSetupPkt( void )<br />
{<br />
/*<br />
* REMOTE DEVICE:<br />
*<br />
* retrieve house code and initialize NIC<br />
*/<br />
config.systemAddr.MSB = rxLPDU.LSDU[2];<br />
config.systemAddr.LSB = rxLPDU.LSDU[1];<br />
config.unitAddr.LSB = 0x02;<br />
config.unitAddr.MSB = 0x00;<br />
transmitter = FALSE; /* set remote device<br />
status*/<br />
InitializeLL();<br />
/*<br />
* reset counters<br />
*/<br />
rxCount = 0;<br />
rxValidCount = 0;<br />
}<br />
- 56 -<br />
void XmitOriginal( void )<br />
{<br />
uint8 i; /* local counter */<br />
static uint8 temp[2]; /* temporary storage */<br />
/*<br />
* TRANSMITTING DEVICE:<br />
*<br />
* load contents <strong>of</strong> transmit buffer (if available) with<br />
running transmit<br />
* count and fill rest <strong>of</strong> info field (up to host specified<br />
length)<br />
* with predictable data (for comparison purposes at<br />
remote device)<br />
*/<br />
if (TxBfrAvailable) {<br />
txLPDU.LPDUheader = txService |<br />
STD_PRIORITY | BASIC_SERVICE;<br />
txLPDU.DA.LSB = 0x02;<br />
txLPDU.DA.MSB = 0x00;<br />
txLPDU.DHC.LSB = config.systemAddr.LSB;<br />
txLPDU.DHC.MSB = config.systemAddr.MSB;<br />
txLPDU.SA.LSB = config.unitAddr.LSB;<br />
txLPDU.SA.MSB = config.unitAddr.MSB;<br />
txLPDU.SHC.LSB = config.systemAddr.LSB;<br />
txLPDU.SHC.MSB = config.systemAddr.MSB;<br />
txLPDU.LSDU[0] = TRANS_PKT;<br />
txLPDU.LSDU[1] = HIGH_BYTE_OF(txCount);<br />
txLPDU.LSDU[2] = LOW_BYTE_OF(txCount);<br />
for(i=0;i
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
*<br />
* send statistics to host<br />
*/<br />
if (!tbufferInUse) {<br />
tbuffer.functionID = STATS_CMD;<br />
temp[0] = LOW_BYTE_OF(txSuccess);<br />
temp[1] = HIGH_BYTE_OF(txSuccess);<br />
if (recdPkts) {<br />
temp[2] = rxLPDU.LSDU[2];<br />
temp[3] = rxLPDU.LSDU[1];<br />
}<br />
else {<br />
temp[2] = 0;<br />
temp[3] = 0;<br />
}<br />
temp[4] = LOW_BYTE_OF(txRcvValid);<br />
temp[5] = HIGH_BYTE_OF(txRcvValid);<br />
tbuffer.buf = temp;<br />
ResponseToHost(6);<br />
testRunning = FALSE;<br />
}<br />
}<br />
boolean ProcessTransmitEnd( boolean forced )<br />
{<br />
/*<br />
* TRANSMITTING DEVICE:<br />
*<br />
* when forced (as result <strong>of</strong> "query" host command) or<br />
when the running<br />
* transmit counter equals the number <strong>of</strong> host<br />
determined packets, send<br />
* "get count" packet to remote device<br />
*<br />
* return TRUE only if "get count" packet sent to remote<br />
device<br />
*/<br />
if (forced || (txCount == txMax)) {<br />
transmitting = FALSE;<br />
/*<br />
* transmit "get count" packet<br />
*/<br />
if (TxBfrAvailable) {<br />
txLPDU.LPDUheader = txService |<br />
STD_PRIORITY | BASIC_SERVICE;<br />
txLPDU.DA.LSB = 0x02;<br />
txLPDU.DA.MSB = 0x00;<br />
txLPDU.DHC.LSB = config.systemAddr.LSB;<br />
txLPDU.DHC.MSB = config.systemAddr.MSB;<br />
txLPDU.SA.LSB = config.unitAddr.LSB;<br />
txLPDU.SA.MSB = config.unitAddr.MSB;<br />
txLPDU.SHC.LSB = config.systemAddr.LSB;<br />
txLPDU.SHC.MSB = config.systemAddr.MSB;<br />
txLPDU.LSDU[0] = GET_COUNT_PKT;<br />
txLPDU.LPDUlength = CEBUS_HEADER_LEN +<br />
1;<br />
transmitCompleted = FALSE;<br />
TransmitPacket(USE_WTI | USE_DELAY); /*<br />
use WTI command w/ delay */<br />
response_timer = GetVeryLowResTimeByte() +<br />
TWO_SECS;<br />
responseTimerRunning = TRUE;<br />
waitingForLoopback = FALSE;<br />
return TRUE;<br />
} else {<br />
return FALSE;<br />
}<br />
} else {<br />
return FALSE;<br />
}<br />
}<br />
- 57 -<br />
void ProcessValidPacket( void )<br />
{<br />
boolean validCompare; /* comparison flag */<br />
uint8 i; /* local counter */<br />
validCompare = TRUE;<br />
for(i=3;i
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
#define WTIX 0x0f /* NPDU_Field Write with Index */<br />
#define WRS46 0x46 /* DLL_Access_Control Write */<br />
#define RRS4 0x84 /* DLL_Rc_Link_Status Read */<br />
/*<br />
* Access control flags<br />
*/<br />
#define ENABLE_AUTO_RETRY 0x80 /* bit in NIC<br />
DLL_Access_Control structure */<br />
#define ENABLE_IMMEDIATE_RETRY 0x40<br />
#define ADRUNACK_TRIES_4 0x02<br />
#define DELAY_100MS 0x10<br />
#define DELAY_200MS 0x20<br />
#define DELAY_300MS 0x30<br />
/*<br />
* ServiceISR transmit/receive state machine states<br />
*/<br />
#define ISR_IDLE 0<br />
#define ISR_XMIT_LEN 1<br />
#define ISR_XMIT_BUF 2<br />
#define ISR_RCV_LEN 3<br />
#define ISR_RCV_BUF 4<br />
#define ISR_ATTN 5<br />
#define packetReceived (LL.b2)<br />
#define rawPacketReceived (LL.b3)<br />
#define receivePacketPending (LL.b4)<br />
#define receiveHeaderPending (LL.b5)<br />
void ReadCommand (uint8 command, @near uint8*<br />
rawData, uint8* length);<br />
void WriteCommand(uint8 command, @near uint8*<br />
rawData, uint8 length);<br />
uint8 basicTransmitStatus;<br />
uint8 ISRstate;<br />
TRANS_BFR transBfr;<br />
boolean delayTimerRunning;<br />
uint8 delayTimer;<br />
boolean UseWTI;<br />
uint8 NICtype;<br />
uint8 GetNICtype ( void )<br />
{<br />
/*<br />
* ID values in "status read" info from NIC<br />
*/<br />
#define P200_ID 0x03<br />
#define P300_ID 0x04<br />
#define ID_MASK 0x0f<br />
uint8 statusStore[6]; /* for "status read" info */<br />
uint8 len; /* length <strong>of</strong> expected data */<br />
/*<br />
** execute "status read" command and set NICtype<br />
accordingly<br />
*/<br />
ReadCommand(SR,statusStore,&len);<br />
NICtype = UNKNOWN_NIC;<br />
statusStore[5] &= ID_MASK;<br />
if(statusStore[5] & P300_ID)<br />
NICtype = P300;<br />
return NICtype;<br />
}<br />
uint8 InitializeLL ( void )<br />
{<br />
uint8 save[2]; /* local store */<br />
/*<br />
* initialize flags<br />
*/<br />
- 58 -<br />
UseDelay = FALSE;<br />
delayTimerRunning = FALSE;<br />
UseWTI = FALSE;<br />
/*<br />
* write current "config" to NIC<br />
*/<br />
WriteCommand(LW,&config.modeByte,size<strong>of</strong>(CONFIG));<br />
/*<br />
* ignore extended service CEBus packets<br />
*/<br />
save[0] = 0;<br />
save[1] = IGNORE_EXTENDED;<br />
WriteCommand(CW,save,2);<br />
save[0] = ENABLE_AUTO_RETRY |<br />
ENABLE_IMMEDIATE_RETRY | ADRUNACK_TRIES_4;<br />
WriteCommand(WRS46,save,1);<br />
/*<br />
* Initialize logical link semaphores/flags<br />
*/<br />
basicTransmitStatus = IDLE;<br />
TxBfrAvailable = TRUE;<br />
RxBfrAvailable = TRUE;<br />
receivePacketPending = FALSE;<br />
receiveHeaderPending = FALSE;<br />
packetReceived = FALSE;<br />
rawPacketReceived = FALSE;<br />
return TRUE;<br />
}<br />
boolean ReceivePacket ( void )<br />
{<br />
if(packetReceived) {<br />
packetReceived = FALSE;<br />
return TRUE;<br />
} else {<br />
return FALSE;<br />
}<br />
}<br />
boolean ReceiveRawPacket ( void )<br />
{<br />
if(rawPacketReceived) {<br />
rawPacketReceived = FALSE;<br />
return TRUE;<br />
} else {<br />
return FALSE;<br />
}<br />
}<br />
interrupt void ServiceISR( void )<br />
{<br />
/*<br />
switch(ISRstate) {<br />
case ISR_XMIT_LEN:<br />
SPDR = transBfr.len;<br />
while(!spif) ; /* wait for transfer complete */<br />
ISRstate = ISR_XMIT_BUF; /* change state */<br />
break;<br />
case ISR_XMIT_BUF:<br />
if(transBfr.index == transBfr.len) {<br />
ISRstate = ISR_IDLE; /* done */<br />
} else {<br />
SPDR = transBfr.buf[transBfr.index];<br />
transBfr.index++;<br />
while(!spif) ; /* wait for transfer complete */
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
}<br />
break;<br />
/*<br />
* Read command: get length byte<br />
*/<br />
case ISR_RCV_LEN:<br />
SPDR = 0;<br />
while(!spif) ; /* wait for transfer complete */<br />
transBfr.len = SPDR;<br />
ISRstate = ISR_RCV_BUF; /* change state */<br />
break;<br />
case ISR_RCV_BUF:<br />
if(transBfr.index == transBfr.len) {<br />
ISRstate = ISR_IDLE; /* done */<br />
} else {<br />
SPDR = 0;<br />
while(!spif) ;<br />
if (transBfr.len
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
}<br />
}<br />
if(UseWTI) {<br />
TransmitPacket(USE_WTI);<br />
} else {<br />
TransmitPacket(0);<br />
}<br />
}<br />
void ReadCommand( uint8 command,<br />
near uint8* rawData, /* O: page 1 data from NIC */<br />
uint8* length ) /* O: length <strong>of</strong> data from NIC */<br />
{<br />
StartErrorTimer();<br />
while((ISRstate!=ISR_IDLE) &&<br />
(ISRstate!=ISR_ATTN)) {<br />
TestErrorTimer(); /* test error timer and restart if<br />
expired */<br />
}<br />
NIC_CS = LOW;<br />
ISRstate = ISR_RCV_LEN;<br />
transBfr.buf = rawData;<br />
transBfr.index = 0; /* initialize index */<br />
WriteToSPI(command);<br />
StartErrorTimer();<br />
while(ISRstate != ISR_IDLE) {<br />
TestErrorTimer();<br />
}<br />
*length = transBfr.len;<br />
NIC_CS = HIGH;<br />
}<br />
void riteCommand( uint8 command,<br />
near uint8* rawData, /* I: page 1 data to NIC */<br />
uint8 length ) /* I: length <strong>of</strong> data to NIC */<br />
{<br />
StartErrorTimer();<br />
while((ISRstate!=ISR_IDLE) &&<br />
(ISRstate!=ISR_ATTN)) {<br />
TestErrorTimer();<br />
}<br />
NIC_CS = LOW;<br />
ISRstate = ISR_XMIT_LEN;<br />
transBfr.buf = rawData;<br />
transBfr.len = length;<br />
transBfr.index = 0;<br />
WriteToSPI(command);<br />
StartErrorTimer();<br />
while(ISRstate != ISR_IDLE) {<br />
- 60 -<br />
TestErrorTimer(); /* test error timer and restart<br />
if expired */<br />
}<br />
NIC_CS = HIGH;<br />
}<br />
/*<br />
* Original Author: Stan JK<br />
*<br />
* Modified by: Tony Truong<br />
*<br />
* File: stamdard.h<br />
*/<br />
typedef unsigned char uint8;<br />
typedef struct<br />
{<br />
uint8 LSB;<br />
uint8 MSB;<br />
} uint16;<br />
typedef struct /* allows 8 boolean flags to coexist in<br />
single uint8 */<br />
{<br />
uint8 b0 : 1;<br />
uint8 b1 : 1;<br />
uint8 b2 : 1;<br />
uint8 b3 : 1;<br />
uint8 b4 : 1;<br />
uint8 b5 : 1;<br />
uint8 b6 : 1;<br />
uint8 b7 : 1;<br />
} booleans;<br />
typedef uint8 boolean;<br />
#define FALSE 0<br />
#define TRUE 1<br />
#define INVALID 0<br />
#define VALID 1<br />
#define OFF 0<br />
#define ON 1<br />
#define LOW 0<br />
#define HIGH 1<br />
#define NULL 0<br />
#define DisableInterrupts() _asm("\tsei\n")<br />
#define EnableInterrupts() _asm("\tcli\n")<br />
#define ResetStackPtr() _asm("\trsp\n")
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
References & Bibliography<br />
[1] Buffkin E., CEBus, LonWorks heading for ‘homeLAN’, Electronic Engineering<br />
Times, May 8, 1995, n847 pp.58-61.<br />
[2] Datasheet for the Domosys CEWay PL-One is available from Domosys<br />
Corporation <strong>Internet</strong> page: http://www.domosys.com<br />
[3] Evans G, Digital Consumer Electronics Handbook, McGraw-Hill, N.Y., 1997,<br />
pp29.1-29.19<br />
[4] Hambley A.R, Electronics: A Top-Down Approach to Computer-Aided Circuit<br />
Design, Prentice Hall, Englewood Cliffs New Jersey, 1994, pp525-527<br />
[5] Holst W, Intelligent Homes (and X-10)<br />
http://web.cs.ualberta.ca/~wade/HyperHome/top.html<br />
[6] Information regarding the Apache Web Server is available from the Apache<br />
<strong>Internet</strong> page: http://www.apache.org/<br />
[7] Information regarding the IT5000 is available from ITRAN Communication<br />
<strong>Internet</strong> page: http://www.itrancomm.com<br />
[8] Information regarding embedded Linux is available from the <strong>Internet</strong> page:<br />
http://www.thinlinux.org/<br />
[9] Information regarding Linux serial communications is available from the<br />
<strong>Internet</strong> pages:<br />
http://sunsite.unc.edu/LDP/HOWTO/Serial-Programming-HOWTO.html<br />
http://sunsite.unc.edu/LDP/HOWTO/Serial-HOWTO.html<br />
- 61 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
[10] Information regarding the LONWorks standard is available from Echlons<br />
<strong>Internet</strong> page:<br />
http://www.echolon.com/<br />
[11] Information regarding the <strong>Power</strong> <strong>Line</strong> Modem is available from VTT<br />
Electronics <strong>Internet</strong> page: http://vtt.oulu.fi/<br />
[12] Information regarding the RTU is available from Unique Collectric <strong>Internet</strong><br />
page: http://www.unique.co.il/ColPrdct/1-WayMU/W-1-WayMU.html<br />
[13] Intellon Corporation, CEBus <strong>Power</strong> <strong>Line</strong> Encoding and Signaling, Intellon<br />
White Paper #0027 Version 0.1, March 1997.<br />
[14] Intellon Corporation, SSC P111 PL Media Interface IC, Technical Data Sheet<br />
Revision 7, August 1998.<br />
[15] Intellon Corporation, SSC P300 PL Network Interface Controller, Technical<br />
Data Sheet Version 1.1, January 1998.<br />
[16] Intellon Corporation, SSC P485 PL Transceiver IC, Technical Data Sheet<br />
Version 1.1, July 1998.<br />
[17] Miller G H, Microcomputer Engineering, Prentice Hall, Englewood Cliffs New<br />
Jersey, 1993<br />
[18] Strassberg D, Home-automation buses: protocols really hit home, EDN article,<br />
April 13, 1995, v40 n8 pp.69-79.<br />
[19] Truong, Tony; <strong>The</strong> <strong>Internet</strong> <strong>Power</strong> <strong>Line</strong> <strong>Adapter</strong>, [<strong>The</strong>sis], Dept. <strong>of</strong> Computer<br />
Science and Electrical Engineering, <strong>University</strong> <strong>of</strong> <strong>Queensland</strong>, October, 1999<br />
- 62 -
Home Automation, <strong>Power</strong> <strong>Line</strong>s and the <strong>Internet</strong> Quenten Alick<br />
[20] Wacks K, <strong>The</strong> Impact <strong>of</strong> Home Automation On <strong>Power</strong> Electronics, Proceedings<br />
<strong>of</strong> International Conference on Consumer Electronics, June 7, 1996.<br />
[21] Wright M, Home-automation networks mature while the PC industry chases a<br />
new home LAN, EDN article, June 4, 1998, v43 n12 pp.101-1012.<br />
- 63 -