1. 1
Abstract— 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 wiring
complexity. It was developed by Robert Bosch for
communication between various digital devices inside an
automobile where heavy electrical interferences and mechanical
vibrations are present. This project is aimed at the
implementation of CAN protocol using PIC for vehicle
monitoring system. The main feature of the system includes
monitoring of various vehicle parameters such as Temperature,
presence of CO level in the exhaust, Battery Voltage and Light
due to spark or fire. The software part is done in MPLab IDE
using Embedded C. Schematic is prepared using OrCAD.
Hardware is implemented and software porting is done.
Index Terms—Battery voltage, Controller Area Network
(CAN) protocol, CO level in the exhaust, Light due to spark or
fire, MPLAB IDE, OrCAD, PIC microcontroller
I. INTRODUCTION
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
wiring complexity. The priority based message scheduling
used in CAN has a number of advantages, some of the most
important being the efficient bandwidth utilization, flexibility,
simple implementation and small overhead. CAN is a serial
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
to send data at the same time, the one with the highest priority
is allowed to send its data while the others return to receive
mode.
CAN distinguishes four message formats [2] viz. data, remote,
error, and overload frames. A data frame begins with the
Start-Of-Frame (SOF) bit. It is followed by an eleven-bit
identifier and the Remote Transmission Request (RTR) bit.
The identifier and the RTR bit form the arbitration field. The
control field consists of six bits and indicates how many bytes
of data follow in the data field. The data field can be zero to
eight bytes. The data field is followed by the Cyclic
Redundancy Checksum (CRC) field, which enables the
receiver to check if the received bit sequence was corrupted.
The two-bit acknowledgment (ACK) field is used by the
transmitter to receive an acknowledgment of a valid frame
from any receiver. The end of a message frame is signaled
through a seven-bit End-Of Frame (EOF). There is also an
extended data frame with a twenty-nine-bit identifier (instead
of eleven bits).
Error detection and error handling are important for the
performance of CAN. Error detection is done in five different
ways in Vehicle Applications of Controller Area Network: bit
monitoring and bit stuffing, as well as frame check, ACK
check, and CRC.
This project targets in the development of a system where
we can monitor various vehicle parameters such as
Temperature, CO percentage in the exhaust, Battery Voltage
and LDR through CAN protocol. The block diagram is as
shown in Fig.1.
Fig.1.Block diagram
Design And Development Of PIC
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
T
2. 2
Two PIC microcontrollers are used; both having the CAN
protocol in built in it.
II. LITERATURE REVIEW
TABLE I
HISTORY OF CAN [13]
1985 Start of development of CAN at Robert
Bosch GmbH
1986 V1.0 specification of CAN
1991 Specifications of the extended CAN2.0
protocol Part 2.0A –11-bit identifier Part
2.0B –29-bit identifier (extended frame
format)
1992 CAN in Automation (CiA) established as
the international users and manufacturers
group
1993 First car, a Mercedes S-class, equipped with
CAN
1994 First standardization at ISO is completed
1995 CAN open protocol introduced
1998 Development phase of time-triggered CAN
(TTCAN) networks
1999 Explosion of CAN-linked equipment in all
motor vehicle and industrial applications
Fairchild et al., [15] in 2002 and Johnson et al., in 2004, in
their research paper published that the engine temperatures
generally do not exceed 110o
C, and exhaust system
components can reach upwards of 600o
C.
Jakob Axelsson et al., [16] in 2003 done a comparative case
study of distributed network architectures for different
automotive applications and published a table indicating this,
which is shown in Table II.
TABLE II
COMPARITIVE CASE STUDY
Αnaetaeioe.Α.Οikonomidhe et al., in 2007 gave
introduction to In-Vehicle Networking: Generic Protocols and
in this paper a brief analysis of the generic protocols that are
used in the area of in-vehicle networking is described. In-
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.
III. HARDWARE
A. Peripheral Interface Controller (PIC)
PIC [7] is a family of Harvard architecture microcontrollers
made by Microchip Technology to control peripheral devices,
alleviating the load from the main CPU. Compared to a human
being, the brain is the main CPU and the PIC is equivalent to
the autonomic nervous system. PIC is very cost effective,
that is the different model PIC’s are available with
proportional cost. There is chance to choose the PIC suitable
for the application. When operated at its maximum clock rate
a PIC executes most of its instructions in 0.2 microseconds or
5 instructions / microsecond. [6] A watchdog timer resets the
PIC if the chip ever malfunctions and deviates from its normal
operations. Three versatile timers can be characterizing inputs,
control outputs and provide internal timings for program
execution. Up to 12 independent interrupt sources [4], which
can provide useful interrupting as and when needed.
Ultraviolet erasable, programmable parts support
development. Lower cost on time programmable parts support
both small and large productions runs. The PIC micro
controller has a number of inbuilt modules like ADC, CAN
that increase versatility of micro controller.
B. CAN Transceiver
The MCP2551 [8] shown in Fig.2 is a high-speed CAN,
fault-tolerant device that serves as the interface between a
CAN protocol controller and the physical bus. The MCP2551
provides differential transmit and receive capability for the
CAN protocol controller and is fully compatible with the ISO-
11898 standard, including 24V requirements. It will operate at
speeds of up to 1 Mb/s. Typically, each node in a CAN system
must have a device to convert the digital signals generated by
a CAN controller to signals suitable for transmission over the
bus cabling (differential output).
Fig.2.Transceiver PIN diagram [10]
It also provides a buffer between the CAN controller and the
high-voltage spikes that can be generated on the CAN bus
(Fig.3) by outside sources.
3. 3
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
there is protection against high-voltage transients. Up to 112
nodes can be connected.
PIC18F458 is connected to CAN Transceiver at the engine
side as shown in the Fig.4. Temperature sensor and battery
voltage circuit is connected to RA0 and RA1 ports. Gas sensor
and LDR is connected to RC0 and RC1 ports. In order to
display in LCD, Data and control lines are connected to port
D. CANH and CANL of engine is connected to CANH and
CANL of dashboard side.
VCC
Y2
UART_TX
LDR
VCC
CANH
DB3
J2
CON2
1
2
DB1
J1
CON2
1
2
UART_RX
R1
R
C4
RS_LCD
TEMP sensor
C3
PIC18F458
pic18f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
MCLR
RAO
RA1
RA2
RA3
RA4
RA5
RE0
RE1
RE2
VDD
VSS
OSC1
OSC2
RC0
RC1
RC2
RC3
RD0
RD1 RD2
RD3
RC4
RC5
RC6
RC7
RD4
RD5
RD6
RD7
VSS
VDD
RB0
RB1
RB2
RB3
RB4
RB5
RB6
RB7
R3
R
CO2
U2
mcp
8
7
6
5
1
2
3
4
RS
CANH
CANL
VREF
TXD
vss
vdd
RXD
CANL
C2
DB2
DBO
Battery volt
MCLR
EnableLCD
Fig.4.Engine side schematic
The second PIC18F458 is connected to CAN Transceiver at
the dashboard side as shown in the Fig.5. An external key is
connected to RB7. By pressing this key, it can request data
from engine. This data can be seen through LCD.
DB1
Y2
UART_TX
J1
CON2
1
2
UART_RX
C4
PIC18F458
pic18f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
MCLR
RAO
RA1
RA2
RA3
RA4
RA5
RE0
RE1
RE2
VDD
VSS
OSC1
OSC2
RC0
RC1
RC2
RC3
RD0
RD1 RD2
RD3
RC4
RC5
RC6
RC7
RD4
RD5
RD6
RD7
VSS
VDD
RB0
RB1
RB2
RB3
RB4
RB5
RB6
RB7
DB3
DBO
CANL
VCC
DB2
J2
CON2
1
2
EnableLCD
CANH
U2
mcp2551
8
7
6
5
1
2
3
4
RS
CANH
CANL
VREF
TXD
v ss
v dd
RXD
RS_LCD
KEY
VCC
C2
C3
MCLR
R3
R
R1
R
Fig.5.Dashboard side schematic
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.6. LM7805 circuit
D. MCLR
PIC18FXX8 devices have a noise filter in the Master Clear
(MCLR) Reset path. The filter will detect and ignore small
pulses. This pin is an active low Reset to the device which is
shown in Fig.7. It should be noted that a WDT Reset does not
drive MCLR pin low.
SW1
RESET
1 2
3 4
+
C3
10uF/63V
12
R2
10K
12
+5V
MCLRR3
10K
1 2
Fig.7. MCLR circuit
The behavior of the ESD protection on the MCLR pin
differs from previous devices of this family. Voltages applied
to the pin that exceed its specification can result in both Resets
and current draws outside of device specification during the
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.
III. MONITORING SYSTEM
A. Temperature sensor LM35
The LM35 is an integrated circuit sensor [11] shown in
Fig.8 that can be used to measure temperature with an
electrical output proportional to the temperature (in o
C). It
measures temperature more accurately than a using a
thermistor. The sensor circuitry is sealed and not subject to
oxidation, etc. The LM35 generates a higher output voltage
than thermocouples and may not require that the output
voltage be amplified. It has an output voltage that is
proportional to the Celsius temperature. The scale factor is
.01V/o
C. The LM35 does not require any external calibration
or trimming and maintains an accuracy of +/-0.4o
C at room
temperature and +/- 0.8o
C over a range of 0o
C to +100o
C.
Another important characteristic of the LM35 is that it draws
only 60 micro amps from its supply and possesses a low self-
heating capability. The sensor self-heating causes less than
4. 4
0.1 o
C temperature rise in still air. The sensor has a sensitivity
of 10mV / o
C.
TEMPERATURE
U6 LM35
GND
1
Vout
2
Vs
3
+5V
Fig.8. LM35 circuit
B. Light dependent resistor
A light-dependent resistor, alternatively called an LDR, is
a variable resistor whose value decreases with increasing
incident light intensity.
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
LM358 series consists of two independent, high gain,
internally frequency compensated operational amplifiers
which were designed specifically to operate from a single
power supply over a wide range of voltages. Operation from
split power supplies is also possible and the low power supply
current drain is independent of the magnitude of the power
supply voltage. One input of LM358 is LDR and the other
input is a reference voltage. When light falls, LDR resistance
decreases and the negative terminal voltage is less compared
to reference voltage and at that time LED turns ON. This
concept can be used to detect if there occurs fire in the engine.
Fig.10. PIN diagram of LM358
C. Battery voltage
The operating voltage range of PIC18F458 is 2.0V to 5.5V.
So a 5.1V Zener diode is connected to get a regulated output
voltage as shown in Fig.11.
Fig.11.Battery voltage circuit
D. Gas sensor
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.12. Gas sensor circuit
E. Liquid Crystal Display
Dashboard is an information cluster located at the edge of
the driver’s primary field of view. It provides the current state
of some important parameters like speed, engine rpm, distance
travelled, engine coolant temperature etc. to the driver.
Although most of the cars use mechanical dashboards,
electronic implementation of the same will have enough
flexibility to cater to varying customers’ choice without too
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
LCD. Command Code register and Data register. If an 8-bit
5. 5
data bus is used, the LCD will require a total of 11 data lines
(3 control lines plus the 8 lines for the data bus). When RS is
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
user who has to specify whether the content at its data pins are
data or commands. Here 2 ports PORT B and PORT C of PIC
18F458 are taken. PORT B is used for providing control
signals and PORT C is used for providing Data signals.
F. Universal Synchronous Asynchronous Receiver
Transmitter
The Universal Synchronous Asynchronous Receiver
Transmitter (USART) module is one of the three serial I/O
modules incorporated into PIC18FXX8 devices. (USART is
also known as a Serial Communications Interface or SCI.) The
USART can be configured as a full-duplex asynchronous
system that can communicate with peripheral devices, such as
CRT terminals and personal computers, or it can be
configured as a half-duplex synchronous system that can
communicate with peripheral devices, such as A/D or D/A
integrated circuits, serial EEPROMs, etc. The USART can be
configured in the following modes:
• Asynchronous (full-duplex)
• Synchronous – Master (half-duplex)
• Synchronous – Slave (half-duplex).
The SPEN (RCSTA register) and the TRISC<7> bits have to
be set and the TRISC<6> bit must be cleared in order to
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
microcontroller’s receiver pin. MAX232 needs four external
capacitors whose value ranges from 1µF to 22µF.
Fig.13. MAX232 circuit
IV. DESIGN OF CAN BASED MONITORING SYSTEM
A. AT THE ENGINE SIDE
CAN 2.0B is a network protocol that was specially
developed for connecting the sensors, actuators and ECUs of a
vehicle. CAN 2.0B supports data rates from 5kbps to 1Mbps,
which allows the CAN network to be used to share status
information and real time control. It can transfer upto 8 data
bytes within a single message.
In this project 2 nodes are used for monitoring
parameters. The various sensors used are temperature, battery
voltage, LDR and CO sensors. Temperature and battery
voltage are connected to ADC. LDR and CO2 sensors are
connected to digital ports. Values are transferred to
microcontrollers in the dashboard from ADC and digital ports
via CAN Protocol at an interval of 10 seconds and is displayed
in the LCD. Also the message can be seen through computer
via UART. If any data is required by the dashboard, the CAN
controller at the engine side checks the identifier transmitted
by it. After 10 seconds, the engine side controller sends the
required data to the dashboard. The flowchart is shown in
Fig.14.
6. 6
Fig.14.Flow chart for CAN based monitoring in the engine
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.15.Flow chart for CAN based monitoring in the dashboard
7. 7
V. RESULTS AND CONCLUSIONS
This thesis is concerned about implementation of CAN
nodes for monitoring parameters. The monitoring parameters
are temperature, battery voltage, light due to spark or fire and
CO level in the exhaust. For monitoring the above parameters,
LM35 sensor, 9V battery, LDR and MQ6 sensors are used.
For implementing this, the programming of LED, ADC and
LCD interfacing with microcontroller is done using Embedded
C. Then the Simulation results are obtained using Proteus
professional schematic software. The programming of
microcontroller interfacing using CAN Protocol is verified
using a general purpose board. Hardware schematic is drawn
using OrCAD. Implemented hardware and software is ported
to it.
The temperature of the engine, battery voltage, presence of
light and CO level in the exhaust are transferred from engine
to dashboard via CAN Protocol and these readings are
displayed through LCD on the dashboard. An external key is
connected to the dashboard for requesting data from engine
when required. When key is pressed the requesting data are
transmitted from the engine and displayed through LCD. The
complete hardware setup is shown in Fig.15.
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
The Handbook of Networked and Embedded Control Systems
Control Engineering, 2005, VI, pp.741-76
[2] Renjun Li, Chu Liu and Feng Luo, “A Design for Automotive
CAN Bus Monitoring System”, IEEE Vehicle Power and
Propulsion Conference (VPPC), September 3-5, 2008, Harbin,
China
[3] CAN specification version 2.0. Robert Bosch GmbH, Stuttgart,
Germany, 1991.
[4] Wilfried Voss, “A Comprehensible Guide to J1939”, Published by
Copperhill Technologies Corporation
[5] Steve Corrigan, “Introduction to the Controller Area Network”,
Published by Texas Instruments Application Report,SLOA101A,
August 2002–Revised July 2008
[6] O. González, M. RodrĂguez, A. Ayala, J. Hernández and S.
RodrĂguez, “Application of PICs and microcontrollers in the
measurement and control of parameters in industry”, Proc of the
International Journal of Electrical Engineering Education 41/3,
pp.265-274, Feb 2001
[7] Microchip Technology Inc. DS41159E: PIC18FXX8 Data Sheet
Pat Richards, “A CAN physical layer discussion”, Microchip
Technology Inc. DS00228A
[8] Dogan Ibrahim, “Microcontroller based temperature monitoring
and control”, ISBN: 0750655569, Elsevier Science & Technology
Books
[9] P.M. Knoll and B.B. Kosmowski, “Liquid crystal display unit for
reconfigurable instrument for automotive applications”, Opto-
Electronics Review, 10(1), 75 (2002)
[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 )