3.7 Microchip TCP/IP stack - MCurry.co.uk

4.2.1 Specification outlined within ENC28J60 data sheet. 4.3 Selection of a
suitable microcontroller. 4.4 Thermal sensing. 4.5 Mains switching. 4.6
Miscellaneous. 4.7 In-circuit serial programming / debugging. 4.8 Circuit Block
Diagram. 4.9 Design & modification of TCP/IP stack modules. 4.9.1 Modification
of microchip's ...

Part of the document


Embedded Room-By-Room Heating Control System Mr Michael John Curry EO320 Mr Chris S Knight 24 April 2007
Final year report submitted in partial fulfilment of the requirements for
the degree of:
Bachelor of Engineering (Honours) in Electronic & Computer Engineering
Disclaimer
I hereby certify that the attached report is my own work except where
otherwise indicated. I have identified my sources of information; in
particular I have put in quotation marks any passages that have been quoted
word-for-word, and identified their origins.
Signed
..............................................................................
...... Date
..............................................................................
.........
Abstract
This project looks at an implementation of an ethernet local area network
using embedded microchip 'PIC' microcontrollers, whereby each room in a
building is thermally controlled by an embedded ethernet node. Each room
node is then in turn controlled by a central control node which also hosts
an embedded web server, allowing a user to easily control the temperature
of each room through an internet browser. This dissertation accompanies the hardware and software implementation of
two embedded microcontroller ethernet nodes, whereby each can manipulate a
binary heater output, to meet a user specified target temperature by
reading a thermal sensor. One of these nodes has also been configured to be
able to 'discover' the other node on the network and send it a new target
temperature, through an HTML interface (aka. web page). This project covers both the design of the hardware and software, which
must function closely together for an embedded solution to work. Contents Disclaimer i
Abstract ii
Contents iii
List of Figures vi
List of Tables vii
Glossary viii
Acknowledgements x
1 Introduction 1
2 Project Aims, Objectives and Technical Overview 3
2.1 Aims 3
2.2 Objectives 3
2.3 Technical Overview 3
3 Background and Research 5
3.1 Embedded Web Servers 5
3.2 Review of previous embedded-ethernet projects 5
3.3 In-Circuit Debugging and Programming 6
3.4 Microchip 'MCC18' C compiler 7
3.5 ISO-OSI 7 layer reference model & TCP/IP stack model 7
3.6 Transmission Control Protocol / Internet Protocol suite 8
3.6.1 Internet Protocol Version 4 (IPv4, OSI layer 3) - RFC 791 8
3.6.2 Transmission Control Protocol over IPv4 (TCP, OSI layers 4&5) -
RFC 793 9
3.6.3 User Datagram Protocol (UDP, OSI Layer 4) - RFC 768 10
3.7 Microchip TCP/IP stack 11
4 Design of artefact 14
4.1 Possible room-node network mediums 14
4.1.1 X.10 14
4.1.2 CAN (Controller Area Network) 14
4.1.3 IEEE 802.3 Ethernet (wired) 14
4.1.4 IEEE 802.11 Ethernet (WiFi) 15
4.1.5 Conclusion 15
4.2 Physical ethernet connections 16
4.2.1 Specification outlined within ENC28J60 data sheet 16
4.3 Selection of a suitable microcontroller 17
4.4 Thermal sensing 17
4.5 Mains switching 18
4.6 Miscellaneous 18
4.7 In-circuit serial programming / debugging 19
4.8 Circuit Block Diagram 19
4.9 Design & modification of TCP/IP stack modules 20
4.9.1 Modification of microchip's existing modules 20
4.9.1.1 Telnet 20
4.9.1.2 HTTP 21
4.9.1.3 HTTP CGI 21
4.9.1.4 HTTP commands 22
4.9.2 New stack modules written specifically for the project 23
4.9.2.1 GetTemp - Read temperature from TC77 SPI thermal sensor 23
4.9.2.2 SendTemp - Open connection to remote node to update target
temperature and read remote temperature 23
4.9.2.3 TempControl - Controls the state of the heater output 24
4.9.2.4 Socket - Allow the central node to update the local node's
target temperature and read the current temperature 24
4.9.2.5 Discover - Allow the discovery of other microchip nodes
in the IP subnet, presumably acting as room nodes 25
4.9.3 Additional functions written for the task 26
4.9.3.1 Converting a float to a string (within the range -99.9 to
+99.9) 26
4.9.3.2 Converting a user entered IP address decimal dotted quad
string to a 32-bit hexadecimal representation 27
4.9.3.3 Padding of a 16 byte string with 0x20 (space) if less than
15 characters stored 28
4.9.3.4 Reading and Writing Internal EEPROM (single char) 29
4.9.4 Bugs within v4.00RC (beta) of the TCP/IP stack 30
4.9.4.1 TCP socket pointer error 30
4.9.4.2 Intermittent UDP error 31
5 Testing of programme and development of artefact 32
5.1 Major Problems encountered 32
5.1.1 Problem 1 32
5.1.1.1 Symptoms 32
5.1.1.2 Cause / Solution 32
5.1.2 Problem 2 33
5.1.2.1 Symptoms 33
5.1.2.2 Cause / Solution 33
5.2 Debugging using microchip ICD2 34
5.3 Debugging of glitches in code written 35
5.3.1 Reading Temperature 35
5.3.2 Telnet 35
5.3.3 Internal EEPROM read/writing 36
5.3.4 Custom socket for updating of target temperature set point 36
5.3.5 Client for changing set point on remote node 36
5.3.6 HTTP 36
5.3.7 Remote node discovery 37
5.4 Testing of temperature control 38
6 Costing 39
7 Conclusions 40
8 Suggestions for Further Work or Recommendations 41
8.1 Specific to this application 41
8.2 Applicable to a generic PIC ethernet project 41
8.3 URL for future project students interested in this project 41
9 References 42
10 Bibliography 43
11 Appendices 44
11.1 Appendix A - 5v relay suitability testing 44
11.2 Appendix B - Room Node Circuit Diagram 45
11.3 Appendix C - GetTemp.c listing 47
11.4 Appendix D - SendTemp.c listing 49
11.5 Appendix E - TempControl.c listing 53
11.6 Appendix F - Socket.c listing 54
11.7 Appendix G - discover.c listing 57
11.8 Appendix H - Project Gantt Chart 61
List of Figures Figure 1 - Stack structure chart 12
Figure 2 - Stack flowchart 13
Figure 3 - ENC28J60 Ethernet Termination and External Connections [MC1]
16
Figure 4 - Collector follower transistor buffer 18
Figure 5 - ICD2 RJ-12 Pinout 19
Figure 6 - ICD2 PIC connections 19
Figure 7 - Circuit Block Diagram 19
Figure 8 - Test-bed, with heat source off 38
Figure 9 - Test-bed, with heat source on 38 List of Tables Table 1 - Comparison of Projects 5
Table 2 - Comparison of ISO-OSI and TCP/IP layers 8
Table 3 - X.10 advantages / disadvantages 14
Table 4 - CAN advantages / disadvantages 14
Table 5 - Ethernet advantages / disadvantages 15
Table 6 - WiFi advantages / disadvantages 15 Glossary |Term |Definition |
|\n or lf |ASCII character for line feed (hex code 0x0d) |
|\r or cr |ASCII character for carriage return (hex code 0x0a) |
|AJAX |Asynchronous JavaScript & XML |
|ASCII |American Standard Code for Information Interchange |
|CAN |Controller Area Network |
|CGI |Common Gateway Interface |
|CSS |Cascading Style Sheet |
|E2PROM |See EEPROM |
|EEPROM |Electronically Erasable Programmable Read Only Memory |
|EMI |Electro-Magnetic Interference |
|HTML |Hyper-Text Markup Language |
|HTTP |Hyper-Text Transfer Protocol |
|IC |Integrated Circuit |
|ICD |In-Circuit Debugger / Debugging |
|ICSP |In-Circuit Serial Programming |
|IDE |Integrated Development Environment |
|IEEE |Institute of Electrical and Electronics Engineers |
|IP |Internet Protocol |
|ISO |International Standards Organisation |
|MCC18 |Microchip C compiler for 18 series PICs |
|MCU |Microcontroller Unit |
|NIC |Network Interface Controller |
|OSI |Open Systems Interconnect |
|PCB |Printed Circuit Board |
|RFC |Request for comments |
|RM |Reference Model |
|RTC |Real Time Clock |
|RX |Receive / Receiver |
|SPDIP |Slim Plastic Dual In-line Package |
|SPI |Serial Peripheral Interface |
|TCP |Transmission Control Protocol |
|TX |Transmit / Transmitter |
| | |
Acknowledgements
I would like to firstly thank the dedication of the microchip support team
for all their hard work in trying to solve the various problems I had with
their TCP/IP stack. Secondly, I would like to thank the staff of the University of Brighton for
their support throughout the project. Introduction
With the ever increasing amounts of integration of microprocessors and
microcontrollers in electrical goods in today's world and the ever growing
adoption of cheap 'smart home' solutions, it makes sense to integrate some
f