project plan
DESCRIPTION
Project PlanTRANSCRIPT
-
UNIVERSITY OF HUDDERSFIELD
SCHOOL OF COMPUTING AND ENGINEERING
PLANNING AN ADVANCED
TECHNICAL PROJECT REPORT
Topic:
PIC NETWORK USING 2-WIRE RS485
TRANSMISSION SYSTEM
Student: TRUONG TUAN VU
STUDENT ID: U1469803
Instructor: DR B.MEHRDADI
-
Project Plan: PIC network using 2-wire RS485 transmission system
1
CONTENTS
CONTENTS ................................................................................................................ 1
LIST OF FIGURES ..................................................................................................... 2
LIST OF TABLES ...................................................................................................... 3
Chapter 1. Introduction ......................................................................................... 4
1.1. Aims ............................................................................................................... 4
1.2. Project Specifications .................................................................................... 4
Chapter 2. Background ......................................................................................... 5
2.1. RS485 Standard ............................................................................................. 5
2.2. RS485 Network ............................................................................................. 6
2.3. Cyclic Redundancy Check (CRC) ................................................................. 7
2.4. UART Connection ......................................................................................... 7
Chapter 3. Problem Analysis and Solutions.......................................................... 9
3.1. Problem Analysis ........................................................................................... 9
3.2. Proposed Solution ........................................................................................ 10
3.2.1. Driver Circuit ........................................................................................ 10
3.2.2. Programming Devices........................................................................... 12
Chapter 4. Project Plan ........................................................................................ 15
Chapter 5. Resources and Issues ......................................................................... 17
REFERENCES .......................................................................................................... 18
-
Project Plan: PIC network using 2-wire RS485 transmission system
2
LIST OF FIGURES
Figure 2.1: Signal on 2 wires of RS485 bus ............................................................... 6
Figure 2.2: Twisted pair wires .................................................................................... 6
Figure 2.3: RS485 network ......................................................................................... 7
Figure 2.4: Transmit status and control register[2] ..................................................... 8
Figure 2.5: Receive status and control register[2] ...................................................... 8
Figure 3.1: Network structure ..................................................................................... 9
Figure 3.2: Work breakdown structure ..................................................................... 10
Figure 3.3: MAX485 Top view [3] ........................................................................... 11
Figure 3.4: Typical application circuit [3] ................................................................ 12
Figure 3.5: Message format from master and slave .................................................. 13
Figure 3.6: Working principle of master ................................................................... 13
Figure 3.7: Working principle of slave devices ........................................................ 14
Figure 4.1: Gantt chart of project plan ...................................................................... 15
-
Project Plan: PIC network using 2-wire RS485 transmission system
3
LIST OF TABLES
Table 3.1: MAX485 Pin description [3] ................................................................... 11
Table 5.1: Project resources ...................................................................................... 17
-
Project Plan: PIC network using 2-wire RS485 transmission system
4
Chapter 1. Introduction
1.1. Aims
The main purpose of this project is to create a network of a number of
identical PIC boards using RS485 connection. A master PIC will control the traffic
across the network. Slave PICs will gather information and execute actions when
there is command from the master.
1.2. Project Specifications
The network needs at least 3 boards, perfectly 5 boards.
Devices on the network are connected to external modules such as LCD,
sensor, switches, LEDs.to be able to gather information or execute actions.
Line driver is used to convert data from microcontroller to suitable signal to
transmit on bus. MAX485 chip is a suitable driver.
Data words are transmitted in an asynchronous format using 9 bits to
transmit and receive data with bit 9 to distinguish between address and data
byte.
The message includes: 1 byte of address, 1 byte of command, data bytes and
Cyclic Redundancy Check (CRC) byte.
-
Project Plan: PIC network using 2-wire RS485 transmission system
5
Chapter 2. Background
This section describes the background knowledge about RS485 standard,
RS485 network and UART connection of PIC16F877A.
2.1. RS485 Standard [1]
RS485 connection is used for data acquisition at a long distance and control
the device. The significant features of RS485 is that it can support a network of up
to 32 stations on the same line, the baud rate can be up to 115.200 for a distance of
4000 feet (1200m). RS485 is used widely in industrial environments where noise is
high and the stability of the system is important.
With balanced transfer mode and the wires are twisted together, when noise
occurs in one wire, it also occurs in the others, i.e the two wires have the same
noise. This makes the voltage difference between the two wires change slightly.
Therefore, the receiver can receive signal properly by special features of the driver
that eliminates noise.
The balanced transmission system includes two signal wires A and B but no
ground wire. The reason is called the balanced system is that the signal in one wire
is reverse with the signal on the other. This means that if signal in wire A is at high
level, the signal in wire B must be at low level and vice versa.
With 2 balanced wires, the high TTL level signal is defined when the voltage
of wire A is higher than the voltage of wire B at least 200 mV. The low TTL level
signal is defined if the voltage of wire A is smaller than wire B at least 200 mV. If
VAB is in range from -200 mV to 200 mV, the signal is considered as in unstable
area.
-
Project Plan: PIC network using 2-wire RS485 transmission system
6
Figure 2.1: Signal on 2 wires of RS485 bus
= ( + ) ( + ) =
As the name implies, twisted pair (Twisted-pair wire) is simply a pair of wire
with equal length and are twisted together. Using twisted pair wire can reduce noise,
especially when transmitting at a long distance and with high speed.
Figure 2.2: Twisted pair wires
2.2. RS485 Network
This protocol allows a number of microcontrollers to be linked using a
twisted pair of wires. It is a half-duplex network. It means that at a time, there is
only one device transmitting or receiving. RS485 uses 9 bits to transmit and receive
data. The 9th
bit is also called the wake up bit. If the information is address, the 9th
bit is 1. If not, it will be 0. One microcontroller will be the master, others are slaves.
Each micro is allocated a unique address.
The master will send the address byte with bit 9 set. It interrupts all the slave
microcontrollers on the network. The only device which matched the transmitted
address responds. Others on the network ignore the incoming data.
-
Project Plan: PIC network using 2-wire RS485 transmission system
7
Figure 2.3: RS485 network
2.3. Cyclic Redundancy Check (CRC)
CRC (Cyclic Redundancy Check) is a method to detect errors by appending
a check block behind the data blocks. CRC is a powerful technique to detect faults,
so it is widely used in all data communication system. The error detection using
CRC is very simple. In the transmission, the CRC is calculated based on the
information bytes and sent along. When the receiving ends, the receiver calculates
the CRC from information byte and compares with received CRC byte. If 2 CRC
bytes are same, the information is considered to have been received correctly. If the
two do not match, it indicates that there are errors in transmission.
Generally, CRC calculation is like arithmetic division where the quotient is
not cared and the remainder is the result. The difference is that CRC calculation
uses carry-less arithmetic. However, this calculation method is computationally
intensive. The easiest CRC is to exclusive OR each data byte with the next.
2.4. UART Connection
The UART connection of microcontroller PIC16F877A is configured and
controller by some register: TXSTA (Transmit status and control register), RCSTA
(Receive status and control register) and SPBRG (Baud rate generator register)
The detailed functions of each register are shown in pictures below.
-
Project Plan: PIC network using 2-wire RS485 transmission system
8
Figure 2.4: Transmit status and control register[2]
With this register, the asynchronous and 9-bit transmission mode that are
required by the network can be chosen.
Figure 2.5: Receive status and control register[2]
The baud rate of UART is calculated by the below formula:
=
16 ( + 1)
Where: X is the value of SPBRG register.
-
Project Plan: PIC network using 2-wire RS485 transmission system
9
Chapter 3. Problem Analysis and Solutions
This chapter describes how the big project is split into smaller targets to
solve and the proposed solution for them.
3.1. Problem Analysis
The main purpose of this project is to design a PIC network using RS485
connection. The general structure of network is shown in the figure below
Figure 3.1: Network structure
According to the network, there are 2 smaller tasks that must be achieved to
finish this project:
Building the driver circuit
Programming devices on the network
The development boards in the laboratory already contain microcontroller
and other external modules such as LCD display, sensor, LEDs, switches.
Therefore, they can be used as the individual device on the network. The driver
circuits are required to connect them together.
Each device on the network should be programmed to use all external
modules when required. Otherwise, it is able to transmit/ receive signal to/ from
other devices. To do that, switching mode mechanism (transmitter/receiver) needs
to be developed, and the devices have to distinguish between address and data
bytes. Generating and checking CRC are also required to detect transmission errors.
-
Project Plan: PIC network using 2-wire RS485 transmission system
10
Figure 3.2: Work breakdown structure
3.2. Proposed Solution
3.2.1. Driver Circuit
To transmit and receive data, the signal from devices needs to be converted
to suitable voltage level. This task requires an external chip. For RS485 network,
MAX845 chip is a suitable driver.
The MAX485 is low-power transceivers for RS-485 and RS-422
communication. The IC contains one driver and one receiver [3]. Some features of
this chip are listed below [3]:
Low quiescent current: 300A
-7V to +12V Common-Mode input voltage range
30ns propagation delays, 5ns Skew
Operate from a single 5V supply
Allows up to 32 transceivers on the bus
Data rate: 2.5 Mbps
-
Project Plan: PIC network using 2-wire RS485 transmission system
11
Figure 3.3: MAX485 Top view [3]
Table 3.1: MAX485 Pin description [3]
No Name Function
1 RO Receive output: if A > B by 200mV, RO will be high; if A < B
by 200mV, RO will be low.
2 RE Receiver Output Enable. RO is enabled when RE is low; RO is
high impedance when RE is high.
3 DE Driver Output Enable. The driver outputs are enabled when
DE is high. They are high impedance when DE is low. If the
driver outputs are enabled, the parts function as line drivers.
While they are high impedance, they function as line receivers
if RE is low.
4 DI Driver input. A low on DI forces output A low and output B
high. Similarly, a high on DI forces output A high and output B
low.
5 GND Ground
6 A Driver Output and Receiver differential input.
7 B Driver Output and Receiver differential input.
8 Vcc Positive Supply: 4.75V Vcc 5.25V
The typical circuit of MAX485 is shown in the figure below.
-
Project Plan: PIC network using 2-wire RS485 transmission system
12
Figure 3.4: Typical application circuit [3]
This chip receives signal from microcontroller through pin DI and send
signal to microcontroller through pin RO, so these two pins are connected to pin
RC6/TX and RC7/RX of microcontroller 16F877A respectively. Since the RS485
network is half-duplex, there is only one device transmitting or receiving at a time.
Therefore, 2 pins RE and DE should be connected together and controlled by one
pin from port C of microcontroller.
3.2.2. Programming Devices
Because of the simplicity of programming other modules, in this section, I
focus on programming UART.
The message from master will consist of: address byte, command byte, data
bytes and CRC byte. After receiving, the slave will calculate CRC and compare
with the CRC byte from master. If there is no error, it will send back a message that
consists of: address byte, data bytes and CRC byte. If there is error, slave will
indicate and send the request to master to retransmit the message.
-
Project Plan: PIC network using 2-wire RS485 transmission system
13
Figure 3.5: Message format from master and slave
The master will start with transmission mode. After finishing sending
message, the master will switch to receiver mode to receive the feedback message
from slave and then switch back to transmission mode. This process is repeated
continually.
Figure 3.6: Working principle of master
-
Project Plan: PIC network using 2-wire RS485 transmission system
14
In contrast, the slave devices start with receiver mode to listen from the
master. After finishing receiving message, if the address is matched, they will
execute the request and switch to transmission mode to send the message back to
master device and then switch back to receiver mode. This process is also repeated
continually.
Figure 3.7: Working principle of slave devices
-
Project Plan: PIC network using 2-wire RS485 transmission system
15
Chapter 4. Project Plan
This part describes the detail plan of this project including logical sequence
of activities and the duration of those activities.
This project was started at the early of May and is planned to finish in July.
The detail plan is shown below.
Figure 4.1: Gantt chart of project plan
-
Project Plan: PIC network using 2-wire RS485 transmission system
16
Until now, some activities were already finished such as researching relevant
knowledge, purchasing MAX485 chip and building test circuit on project board.
This test circuit will be used to test the connection between 2 devices. If this circuit
works, the PCB will be designed. After testing with 2 devices, the program will be
developed and tested for 3, 4 and 5 devices.
The planned finish date is 14th
July, so there is a great deal of time for coping
with unexpected events before the submission date.
-
Project Plan: PIC network using 2-wire RS485 transmission system
17
Chapter 5. Resources and Issues
This part describes the resources that will be used in this project and the
issues that might be relevant to the project.
The table below lists all software and hardware resources, their source and
cost.
Table 5.1: Project resources
No Name Function Source Cost
1 PIC development
boards
Devices on the network Embedded
system
laboratory
Free
2 MAX485 Driver chip Purchase from
Ebay.co.uk
0.895 each
3 Electronic
components
Components of driver
circuit
Electronic
laboratory
Free
4 MikroC PRO for
PIC
Programming
microcontroller
Embedded
system
laboratory
Free
5 Proteus software Simulate the action of
whole system
Design PCB
Internet Free
There is not any ethical or legal issue that might be relevant to this project.
-
Project Plan: PIC network using 2-wire RS485 transmission system
18
REFERENCES
[1] RS-485. Retrieved from http://en.wikipedia.org/wiki/RS-485
[2] Microchip PIC16F87XA datasheet. Retrieved from
http://akizukidenshi.com/download/PIC16F87XA.pdf
[3] MAX485 datasheet. Retrieved from
http://3egadgets.com/attachment.php?id_attachment=23