You are on page 1of 7

Design And Development Of PIC 1

Microcontroller Based Vehicle Monitoring


System Using Controller Area Network (CAN)
Protocol
Presi.T.P
Department of Applied electronics and instrumentation
MES college of engineering
Malappuram, India
presitnr@yahoo.com

is allowed to send its data while the others return to receive


mode.
Abstract— Controller Area Network (CAN) is an attractive CAN distinguishes four message formats [2] viz. data, remote,
alternative in the automotive and automation industries due to its error, and overload frames. A data frame begins with the
ease in use, low cost and provided reduction in wiring
Start-Of-Frame (SOF) bit. It is followed by an eleven-bit
complexity. It was developed by Robert Bosch for
communication between various digital devices inside an identifier and the Remote Transmission Request (RTR) bit.
automobile where heavy electrical interferences and mechanical The identifier and the RTR bit form the arbitration field. The
vibrations are present. This project is aimed at the control field consists of six bits and indicates how many bytes
implementation of CAN protocol using PIC for vehicle of data follow in the data field. The data field can be zero to
monitoring system. The main feature of the system includes eight bytes. The data field is followed by the Cyclic
monitoring of various vehicle parameters such as Temperature, Redundancy Checksum (CRC) field, which enables the
presence of CO level in the exhaust, Battery Voltage and Light receiver to check if the received bit sequence was corrupted.
due to spark or fire. The software part is done in MPLab IDE The two-bit acknowledgment (ACK) field is used by the
using Embedded C. Schematic is prepared using OrCAD.
transmitter to receive an acknowledgment of a valid frame
Hardware is implemented and software porting is done.
from any receiver. The end of a message frame is signaled
Index Terms—Battery voltage, Controller Area Network through a seven-bit End-Of Frame (EOF). There is also an
(CAN) protocol, CO level in the exhaust, Light due to spark or extended data frame with a twenty-nine-bit identifier (instead
fire, MPLAB IDE, OrCAD, PIC microcontroller of eleven bits).
Error detection and error handling are important for the
performance of CAN. Error detection is done in five different
I. INTRODUCTION ways in Vehicle Applications of Controller Area Network: bit

T HE Controller Area Network (CAN) is an attractive


alternative in the automotive and automation industries
due to its ease in use, low cost and provided reduction in
monitoring and bit stuffing, as well as frame check, ACK
check, and CRC.
This project targets in the development of a system where
wiring complexity. The priority based message scheduling we can monitor various vehicle parameters such as
used in CAN has a number of advantages, some of the most Temperature, CO percentage in the exhaust, Battery Voltage
important being the efficient bandwidth utilization, flexibility, and LDR through CAN protocol. The block diagram is as
simple implementation and small overhead. CAN is a serial shown in Fig.1.
bus communications protocol developed by Bosch [3] (an
electrical equipment manufacturer in Germany) in the early
1980s. Thereafter, CAN was standardized as ISO-11898 and
ISO-11519, establishing itself as the standard protocol for in-
vehicle networking in the auto industry. By networking the
electronics in vehicles with CAN, however, they could be
controlled from a central point, the Engine Control Unit
(ECU), thus increasing functionality, adding modularity, and
making diagnostic processes more efficient. CAN offer an
efficient communication protocol between sensors, actuators,
controllers, and other nodes in real-time applications, and is
known for its simplicity, reliability, and high performance [5].
The CAN protocol is based on a bus topology [1], and only
two wires are needed for communication over a CAN bus. The
bus has a multi master structure where each device on the bus
can send or receive data. Only one device can send data at any
time while all the others listen. If two or more devices attempt Fig.1.Block diagram
to send data at the same time, the one with the highest priority
2

Two PIC microcontrollers are used; both having the CAN III. HARDWARE
protocol in built in it.
A. Peripheral Interface Controller (PIC)
II. LITERATURE REVIEW PIC [7] is a family of Harvard architecture microcontrollers
TABLE I
made by Microchip Technology to control peripheral devices,
HISTORY OF CAN [13] alleviating the load from the main CPU. Compared to a human
being, the brain is the main CPU and the PIC is equivalent to
1985 Start of development of CAN at Robert the autonomic nervous system. PIC is very cost effective,
Bosch GmbH that is the different model PIC’s are available with
1986 V1.0 specification of CAN proportional cost. There is chance to choose the PIC suitable
1991 Specifications of the extended CAN2.0 for the application. When operated at its maximum clock rate
protocol Part 2.0A –11-bit identifier Part a PIC executes most of its instructions in 0.2 microseconds or
2.0B –29-bit identifier (extended frame 5 instructions / microsecond. [6] A watchdog timer resets the
format) PIC if the chip ever malfunctions and deviates from its normal
1992 CAN in Automation (CiA) established as operations. Three versatile timers can be characterizing inputs,
the international users and manufacturers control outputs and provide internal timings for program
group execution. Up to 12 independent interrupt sources [4], which
1993 First car, a Mercedes S-class, equipped with can provide useful interrupting as and when needed.
CAN Ultraviolet erasable, programmable parts support
1994 First standardization at ISO is completed development. Lower cost on time programmable parts support
1995 CAN open protocol introduced both small and large productions runs. The PIC micro
1998 Development phase of time-triggered CAN controller has a number of inbuilt modules like ADC, CAN
(TTCAN) networks that increase versatility of micro controller.
1999 Explosion of CAN-linked equipment in all
motor vehicle and industrial applications B. CAN Transceiver
Fairchild et al., [15] in 2002 and Johnson et al., in 2004, in The MCP2551 [8] shown in Fig.2 is a high-speed CAN,
their research paper published that the engine temperatures fault-tolerant device that serves as the interface between a
generally do not exceed 110oC, and exhaust system CAN protocol controller and the physical bus. The MCP2551
components can reach upwards of 600oC. provides differential transmit and receive capability for the
Jakob Axelsson et al., [16] in 2003 done a comparative case CAN protocol controller and is fully compatible with the ISO-
study of distributed network architectures for different 11898 standard, including 24V requirements. It will operate at
automotive applications and published a table indicating this,
speeds of up to 1 Mb/s. Typically, each node in a CAN system
which is shown in Table II.
TABLE II
must have a device to convert the digital signals generated by
COMPARITIVE CASE STUDY a CAN controller to signals suitable for transmission over the
bus cabling (differential output).

Αnaetaeioe.Α.Οikonomidhe et al., in 2007 gave Fig.2.Transceiver PIN diagram [10]


introduction to In-Vehicle Networking: Generic Protocols and It also provides a buffer between the CAN controller and the
in this paper a brief analysis of the generic protocols that are high-voltage spikes that can be generated on the CAN bus
used in the area of in-vehicle networking is described. In- (Fig.3) by outside sources.
vehicle networking, also known as multiplexing, is a method
for transferring data among distributed electronic modules via
a serial data bus. Also a case study of in-Vehicle Network
Systems for Volvo passenger car is done in this paper.
CO emission rate [14] according to BS IV regulations April
2010 has been found out as 0.5 g/km for diesel engines and
1.0 g/km for petrol engines.
3

C. LM7805
The operating voltage range of PIC18F458 is 2.0V to 5.5V.
So LM7805 which is a +5.0V 1A voltage regulator, is used. It
is a linear voltage regulator that produces a relatively constant
output voltage of +5VDC. There is an input pin, which must
generally be greater than +7VDC, a ground pin, and an output
pin as shown in Fig.6.

Fig.3.CAN Bus [8]


The main features are it supports 1 Mb/s operation. It is
suitable for 12V and 24V systems. It is a low current standby
operation. There is protection against damage due to short-
circuit conditions (positive or negative battery voltage). Also
Fig.6. LM7805 circuit
there is protection against high-voltage transients. Up to 112
nodes can be connected. D. MCLR
PIC18F458 is connected to CAN Transceiver at the engine
side as shown in the Fig.4. Temperature sensor and battery PIC18FXX8 devices have a noise filter in the Master Clear
voltage circuit is connected to RA0 and RA1 ports. Gas sensor (MCLR) Reset path. The filter will detect and ignore small
and LDR is connected to RC0 and RC1 ports. In order to pulses. This pin is an active low Reset to the device which is
display in LCD, Data and control lines are connected to port shown in Fig.7. It should be noted that a WDT Reset does not
D. CANH and CANL of engine is connected to CANH and drive MCLR pin low.
+5V
CANL of dashboard side.

2
R2
VCC 10K

SW1

1
PIC18F458 VCC RESET
1 2 1 R3 2 MCLR
R1
MCLR C2
10K
1 40
MCLR RB7

1
2 39 3 4
TEMP sensor RAO RB6 U2
3 38 10uF /63V
Battery v olt RA1 RB5 +
4 37 1 8 R
5 RA2 RB4 36 2 TXD RS 7 C3
6 RA3 RB3 35 3 v ss CANH 6
7 RA4 RB2 34 4 v dd CANL 5 CANH 2
8 RA5 RB1 33 RXD VREF
J1
9 RE0 RB0 32
10 RE1 VDD 31 1
RE2 VSS mcp 2
11 30
12 VDD RD7 29 CON2
VSS RD6
Y2
13
14
15
OSC1
OSC2
RD5
RD4
28
27
26
EnableLCD
Fig.7. MCLR circuit
C3 C4
CO2
LDR
16
17
RC0
RC1
RC2
RC7
RC6
RC5
25
24
RS_LCD
R3
R
The behavior of the ESD protection on the MCLR pin
DBO
18
19
20
RC3
RD0
RC4
RD3
23
22
21 J2
differs from previous devices of this family. Voltages applied
to the pin that exceed its specification can result in both Resets
RD1 RD2 UART_RX
DB1 1
2
DB2
pic18f
UART_TX
CON2 and current draws outside of device specification during the
DB3 CANL
Reset event. For this reason, Microchip recommends that the
MCLR pin no longer be tied directly to VDD. The use of an
RC network, is suggested.
Fig.4.Engine side schematic III. MONITORING SYSTEM
The second PIC18F458 is connected to CAN Transceiver at
the dashboard side as shown in the Fig.5. An external key is A. Temperature sensor LM35
connected to RB7. By pressing this key, it can request data The LM35 is an integrated circuit sensor [11] shown in
from engine. This data can be seen through LCD. Fig.8 that can be used to measure temperature with an
VCC
electrical output proportional to the temperature (in oC). It
PIC18F458
KEY
VCC
measures temperature more accurately than a using a
MCLR
1
MCLR RB7
40 C2
R1
thermistor. The sensor circuitry is sealed and not subject to
oxidation, etc. The LM35 generates a higher output voltage
2 39
3 RAO RB6 38 U2
4 RA1 RB5 37 1 8 R
5 RA2 RB4 36 2 TXD RS 7

than thermocouples and may not require that the output


6 RA3 RB3 35 3 v ss CANH 6
RA4 RB2 v dd CANL CANH
7 34 4 5
8 RA5 RB1 33 RXD VREF
J1
9 RE0 RB0 32
10
11
12
RE1
RE2
VDD
VSS
VDD
VSS
RD7
RD6
31
30
29
mcp2551
1
2
CON2
voltage be amplified. It has an output voltage that is
proportional to the Celsius temperature. The scale factor is
13 28
14 OSC1 RD5 27
Y2 EnableLCD
15 OSC2 RD4 26
RC0 RC7

.01V/oC. The LM35 does not require any external calibration


16 25 R3
C3 C4 17 RC1 RC6 24
RC2 RC5 RS_LCD R
18 23
19 RC3 RC4 22
DBO RD0 RD3

or trimming and maintains an accuracy of +/-0.4oC at room


20 21 J2
RD1 RD2 UART_RX
DB1 1
2

temperature and +/- 0.8oC over a range of 0oC to +100oC.


DB2 UART_TX
pic18f CON2
DB3 CANL

Another important characteristic of the LM35 is that it draws


only 60 micro amps from its supply and possesses a low self-
Fig.5.Dashboard side schematic heating capability. The sensor self-heating causes less than
4

0.1 oC temperature rise in still air. The sensor has a sensitivity C. Battery voltage
of 10mV / oC. The operating voltage range of PIC18F458 is 2.0V to 5.5V.
U6 LM35 So a 5.1V Zener diode is connected to get a regulated output
voltage as shown in Fig.11.

GND
Vout
+5V

Vs
1
2
3
TEMPERATURE

Fig.8. LM35 circuit


B. Light dependent resistor
Fig.11.Battery voltage circuit
A light-dependent resistor, alternatively called an LDR, is
a variable resistor whose value decreases with increasing D. Gas sensor
incident light intensity.
Gas sensor used here is MQ-6. It has high sensitity to
Propane, Butane and LPG, also response to Natural gas. [12]
The sensor could be used to detect different combustible gas,
especially Methane, it is with low cost and suitable for
different application. Sensitive material of MQ-6 gas sensor is
SnO2, which with lower conductivity in clean air. Gas sensor
output voltage is connected to LM358. If V+ >V- , then the
output voltage is high and the LED connected to the output is
ON. If V+ < V- , then the output voltage is low and LED is
OFF. Gas sensor circuit is shown in Fig.12.
Fig.9. LDR circuit
An LDR is made of a high-resistance semiconductor. If
light falling on the device is of high enough frequency,
photons absorbed by the semiconductor give bound electrons
enough energy to jump into the conduction band. The
resulting free electron (and its hole partner) conduct
electricity, thereby lowering resistance. A photoelectric device
can be either intrinsic or extrinsic. In intrinsic devices, the
only available electrons are in the valence band, and hence the
photon must have enough energy to excite the electron across
the entire bandgap. Extrinsic devices have impurities added,
which have a ground state energy closer to the conduction
band - since the electrons don't have as far to jump, lower
energy photons (i.e. longer wavelengths and lower
frequencies) are sufficient to trigger the device. The sensor is
connected as shown in Fig.9.
LDR sensor is connected to LM358 shown in Fig.10. The Fig.12. Gas sensor circuit
LM358 series consists of two independent, high gain,
internally frequency compensated operational amplifiers E. Liquid Crystal Display
which were designed specifically to operate from a single
power supply over a wide range of voltages. Operation from Dashboard is an information cluster located at the edge of
split power supplies is also possible and the low power supply the driver’s primary field of view. It provides the current state
current drain is independent of the magnitude of the power of some important parameters like speed, engine rpm, distance
supply voltage. One input of LM358 is LDR and the other travelled, engine coolant temperature etc. to the driver.
input is a reference voltage. When light falls, LDR resistance Although most of the cars use mechanical dashboards,
decreases and the negative terminal voltage is less compared electronic implementation of the same will have enough
to reference voltage and at that time LED turns ON. This flexibility to cater to varying customers’ choice without too
concept can be used to detect if there occurs fire in the engine. much additional cost. Liquid Crystal Displays (LCDs) are a
good choice for the electronic dashboards [9] as they operate
at low voltages, consume very little power and are also
economical. In fact high-end cars have LCD panels in their
dashboards. A simple 8-bit 16x2 LCD is used to interface
with PIC 18F458. This means there are 16 characters per line
by 2 lines. There are three control signals Register select,
Enable and Read/Write. There are two important registers in
Fig.10. PIN diagram of LM358 LCD. Command Code register and Data register. If an 8-bit
5

data bus is used, the LCD will require a total of 11 data lines microcontroller’s receiver pin. MAX232 needs four external
(3 control lines plus the 8 lines for the data bus). When RS is capacitors whose value ranges from 1µF to 22µF.
low (0), the data is to be treated as a command or a special
instructions (such as clear screen, position cursor, etc). When
RS is high (1), the data being sent is text data which should be
displayed on the screen. R/W input allows the user to write
information to LCD or read information from it. When RW
line is low (0), the information on the data bus is being written
to the LCD. When R/W is high (1), the program is registers
effectively querying (or reading) the LCD. The enable Pin is
used by the LCD to latch information at its data pins. When
data is supplied to data pins, a high to low pulse must be
applied to this pin in order for the LCD to latch the data
present in the data pins. We have to prepare an LCD properly
before the character we need, has to be displayed. For this a
number of commands have to be provided to the LCD before
inputting the required data. LCD doesn’t know about the
content (data or commands) supplied to its data bus. It is the Fig.13. MAX232 circuit
user who has to specify whether the content at its data pins are IV. DESIGN OF CAN BASED MONITORING SYSTEM
data or commands. Here 2 ports PORT B and PORT C of PIC
18F458 are taken. PORT B is used for providing control A. AT THE ENGINE SIDE
signals and PORT C is used for providing Data signals.
CAN 2.0B is a network protocol that was specially
F. Universal Synchronous Asynchronous Receiver developed for connecting the sensors, actuators and ECUs of a
Transmitter vehicle. CAN 2.0B supports data rates from 5kbps to 1Mbps,
The Universal Synchronous Asynchronous Receiver which allows the CAN network to be used to share status
Transmitter (USART) module is one of the three serial I/O information and real time control. It can transfer upto 8 data
modules incorporated into PIC18FXX8 devices. (USART is bytes within a single message.
also known as a Serial Communications Interface or SCI.) The In this project 2 nodes are used for monitoring
USART can be configured as a full-duplex asynchronous parameters. The various sensors used are temperature, battery
system that can communicate with peripheral devices, such as voltage, LDR and CO sensors. Temperature and battery
CRT terminals and personal computers, or it can be voltage are connected to ADC. LDR and CO2 sensors are
configured as a half-duplex synchronous system that can connected to digital ports. Values are transferred to
communicate with peripheral devices, such as A/D or D/A microcontrollers in the dashboard from ADC and digital ports
integrated circuits, serial EEPROMs, etc. The USART can be via CAN Protocol at an interval of 10 seconds and is displayed
configured in the following modes: in the LCD. Also the message can be seen through computer
• Asynchronous (full-duplex) via UART. If any data is required by the dashboard, the CAN
• Synchronous – Master (half-duplex) controller at the engine side checks the identifier transmitted
• Synchronous – Slave (half-duplex). by it. After 10 seconds, the engine side controller sends the
The SPEN (RCSTA register) and the TRISC<7> bits have to required data to the dashboard. The flowchart is shown in
be set and the TRISC<6> bit must be cleared in order to Fig.14.
configure pins RC6/TX/CK and RC7/RX/DT as the USART.
The MAX232 IC is used to convert the TTL/CMOS logic
levels to RS232 logic levels during serial communication of
microcontrollers with PC. The controller operates at TTL logic
level (0-5V) whereas the serial communication in PC works
on RS232 standards (-25 V to + 25V). This makes it difficult
to establish a direct link between them to communicate with
each other. The intermediate link is provided through
MAX232 which is shown in Fig.13. It is a dual driver/receiver
that includes a capacitive voltage generator to supply RS232
voltage levels from a single 5V supply. Each receiver converts
RS232 inputs to 5V TTL/CMOS levels. These receivers
(R1 & R2) can accept ±30V inputs. The drivers (T1 & T2),
also called transmitters, convert the TTL/CMOS input level
into RS232 level. The transmitters take input from controller’s
serial transmission pin and send the output to RS232’s
receiver. The receivers, on the other hand, take input from
transmission pin of RS232 serial port and give serial output to
6

B. AT THE DASHBOARD SIDE


Here the CAN controller checks if any data is available at
the receive buffers. If there is any, then that value is displayed
through LCD. While pressing the key, which is placed on the
dashboard, the data is requested by sending an identifier. Then
after 10 seconds the message is obtained from engine section
via CAN Protocol.

Fig.14.Flow chart for CAN based monitoring in the engine Fig.15.Flow chart for CAN based monitoring in the dashboard
7

V. RESULTS AND CONCLUSIONS The Handbook of Networked and Embedded Control Systems
Control Engineering, 2005, VI, pp.741-76
This thesis is concerned about implementation of CAN [2] Renjun Li, Chu Liu and Feng Luo, “A Design for Automotive
nodes for monitoring parameters. The monitoring parameters CAN Bus Monitoring System”, IEEE Vehicle Power and
Propulsion Conference (VPPC), September 3-5, 2008, Harbin,
are temperature, battery voltage, light due to spark or fire and China
CO level in the exhaust. For monitoring the above parameters, [3] CAN specification version 2.0. Robert Bosch GmbH, Stuttgart,
LM35 sensor, 9V battery, LDR and MQ6 sensors are used. Germany, 1991.
For implementing this, the programming of LED, ADC and [4] Wilfried Voss, “A Comprehensible Guide to J1939”, Published by
Copperhill Technologies Corporation
LCD interfacing with microcontroller is done using Embedded [5] Steve Corrigan, “Introduction to the Controller Area Network”,
C. Then the Simulation results are obtained using Proteus Published by Texas Instruments Application Report,SLOA101A,
professional schematic software. The programming of August 2002–Revised July 2008
microcontroller interfacing using CAN Protocol is verified [6] O. González, M. Rodríguez, A. Ayala, J. Hernández and S.
Rodríguez, “Application of PICs and microcontrollers in the
using a general purpose board. Hardware schematic is drawn measurement and control of parameters in industry”, Proc of the
using OrCAD. Implemented hardware and software is ported International Journal of Electrical Engineering Education 41/3,
to it. pp.265-274, Feb 2001
The temperature of the engine, battery voltage, presence of [7] Microchip Technology Inc. DS41159E: PIC18FXX8 Data Sheet
Pat Richards, “A CAN physical layer discussion”, Microchip
light and CO level in the exhaust are transferred from engine Technology Inc. DS00228A
to dashboard via CAN Protocol and these readings are [8] Dogan Ibrahim, “Microcontroller based temperature monitoring
displayed through LCD on the dashboard. An external key is and control”, ISBN: 0750655569, Elsevier Science & Technology
connected to the dashboard for requesting data from engine Books
when required. When key is pressed the requesting data are [9] P.M. Knoll and B.B. Kosmowski, “Liquid crystal display unit for
reconfigurable instrument for automotive applications”, Opto-
transmitted from the engine and displayed through LCD. The Electronics Review, 10(1), 75 (2002)
complete hardware setup is shown in Fig.15. [10] MCP 2551 High speed CAN Transceiver Datasheet.
[11] National Semiconductor, “LM35 Precision Centigrade Temperature
Sensors Data sheet”, National Semiconductor Corporation,
November 2000.
[12] MQ-6 Gas sensor Datasheet.
[13] J.Axelsson, J.Froberg, H.A.Hansson, C.Norstrom, K.Sandstorm and
B.Villing, “Correlating Bussines Needs and Network Architectures
in Automotive Applications – a Comparative Case Study”,Proc of
FET’03,pp.219-228, July 2003.
[14] BS IV regulations April 2010.
[15] Fairchild, Ray, M., Snyder, Rick B., Berlin, Carl W.,Sarma, D. H. R
“Emerging Substrate Technologies for Harsh-Environment
Automotive Electronics Applications", Society of Automotive
Engineers Technical Paper Series 2002-01-1052(2002).
[16] Johnson, R. Wayne, Evans, John L. Jacobsen, Peter, Thompson,
James R, Christopher, Mark. "The Changing Automotive
Environment: High-Temperature Electronics", IEEE Transactions
on Electronics Packaging Manufacturing pp.164-176, 27(2004 )

Fig.16 Complete Hardware Setup

VI. SCOPE FOR FUTURE WORK


• This thesis is limited to a two node network. This can
be extended to four nodes, eight nodes, 16 nodes etc.
for vehicle monitoring applications.
• Response time analysis can be done. Response time
analysis for CAN aims to provide a method of
calculating the worst-case response time of each
message. These values can then be compared to the
message deadlines to determine if the system is
schedulable. Initially we provide analysis assuming
no errors on the CAN bus. This analysis is then
extended, to account for errors on the bus.
• Cost analysis can be done.

REFERENCE
[1] Karl Henrik Johansson, Martin Törngren, and Lars Nielsen,
“Vehicle Application of Controller Area Network”.proc of

You might also like