Implementation of Controller Area Network (CAN)
Bus (Building Automation)
S. Ashtekar Shweta1, D. Patil Mukesh2, and B. Nade Jagdish3
Lecturer, Ramrao Adik Institute of Technology, Nerul, Navi-Mumbai
shweta_sa06@yahoo.com
2
Assistant Professor, Ramrao Adik Institute of Technology, Nerul, Navi-Mumbai
mdpatil@iitb.ac.in 3
VDF’s Institute of Technology, Latur
nade.jag@gmail.com
1
Abstract. The Controller Area Network (CAN) is an asynchronous serial CSMA/CD+AMP communication protocol for microcontrollers networks, supporting distributed real-time control (bit rate up to 1Mbps) with a very high level of security. CAN communication protocol is based on a distributed scheme, there is no central unit, allowing a direct data transfer between any two or more nodes without a master node mediation. A Building Automation System (BAS) is an example of a distributed control system. In this paper, the CAN bus lighting network is implemented with a reliable two wire control which is required for saving energy consumption or, creating precision lighting effects as a subunit of a BAS. Security systems is also interlocked to a building automation system to monitor the secure premises, control the operation of the overall system, and authorize legal entries as well as to trigger the alarm. Keywords: CAN protocol, PIC Microcontroller, Building Automation System.
1 Introduction
As consumer electronics, computer peripherals, vehicles, automation and industrial applications add embedded functionality, demand is growing for inexpensive, fast and reliable communication media to serve these applications. Today more and more of the building blocks used in embedded system design are replacing parallel buses with serial buses .CAN serial bus is the most applicative technology in the field of automation, which can transfer data at the rate up to 1Mbps. It has its own unique advantage with its reliability, flexibility and real-time performance .Most significant features of CAN Bus include: Broadcast or Multicast system, Multimaster structure-distributed control, Prioritization of messages, Flexible configuration (“hot pluggable”), Message routing, Remote data request (RTR), Max. speed 1Mbps (40 m) and 50 kbps (1000m), Reliable through error detection and recovery algorithms, automatic retransmission of corrupted messages. Building Automation is an idea of using a control system to monitor and command the mechanical, lighting, security control, or fire alarm systems in a commercial building. The computerized, intelligent network functions to keep building temperature within a specified range, control
S. Unnikrishnan, S. Surve, and D. Bhoir (Eds.): ICAC3 2011, CCIS 125, pp. 507–514, 2011. © Springer-Verlag Berlin Heidelberg 2011
508 S.A. Shweta, D.P. Mukesh, and B.N. Jagdish
lighting, monitor performance of all systems, and send out alarm signals to maintenance engineers or administrators when failure occurs. There are many controls in a building that can be included in a Building Automation System. HVAC controls, lighting controls, electricity controls, hot water controls, fire controls, access controls, security/ surveillance, vehicle parking system, plumbing system, lifts and elevators , gardening system in a Building Automation System[4]. The Building Automation System can be programmed to manage these controls. Commercially available lighting systems like DALI (Digital Addressable Lighting Interface) has disadvantages like Maximum 64 nodes can be interfaced , Slow speed 200 bps, Master/Slave configuration, Non flexible. These limitation can be removed using CAN bus network.
The CAN communication protocol is a CSMA/CD+AMP (Carrier Sense Multiple Access/Collision Detection+Arbitration on Message Priority) protocol. Every node on the network must monitor the bus for a period of no activity before trying to send a message on the bus (Carrier Sense). Also, once this period of no activity occurs, every node on the bus has an equal opportunity to transmit a message (Multiple Access). If two nodes on the network start transmitting at the same time, the nodes will detect the ‘collision’ and take the appropriate action. Messages remain intact after arbitration is completed even if collisions are detected. All of this arbitration takes place without corruption or delay of the higher priority message.
CAN implements three layers of ISO/OSI reference model as physical layer, data link layer and application layer. The Hi-speed CAN physical layer is merely a twisted pair of wires with a 120 ohm termination resistor at each end and twisted wire drops to the individual CAN nodes. . CAN Hi voltage with respect to ground changes between 2.5 to 4 volts nominal. CAN Lo changes from 2.5 to 1 volt. Therefore the difference between the two is either 0 volts (is logical “1”) or 2 volts (is logical “0”). 0 is known as the “recessive” state and 2 volts is the “dominant” state. These two signals, CAN Hi and CAN Lo are 180 degrees out of phase. Bus idle is when the voltage difference is zero .At data link layer, CAN supports four different types of frames as data frame ,error frame ,remote frame and overload frame. Either 11 bit or 29 bit arbitration field to identify the message. In this application we are using 11 bit message identifier in the data frame.
Sequence of transmitting data on CAN bus • Initially Bus is Idle
• All nodes will transmit data
• Highest priority node will get access of the bus and transmit the data , other
nodes will enter into receiving mode
• Transmit node will wait for Acknowledgement
• If acknowledgement is received ,send the next message otherwise wait and
resend the same message again
• Send EOF (End Of Frame)bit and enter into receiving mode Sequence of receiving data on CAN bus • •
If frame is received without errors (by CRC calculations) send the acknowledgement,
If frame is corrupted, wait for the corrected frame
Implementation of Controller Area Network (CAN) Bus (Building Automation) 509
• • • Send the received frame to Acceptance filter mechanism
If frame is accepted-send it to FIFO memory of the controller otherwise discard the frame.
Alert the host processor about the valid frame.
2 System Design: Hardware
The aim of the paper is to implement CAN protocol to control lighting network. Security systems is also interlocked to this network to monitor the secure premises, control the operation of the overall system, and authorize legal entries as well as to trigger the alarm[2].
The CAN protocol is been implemented using microcontroller based system and PC. The communication is done through only two wires. The system will be using two lighting nodes (two microcontroller systems), one interfacing unit node (microcontroller system) with computer and one alarm unit node. The bulbs and LDR sensors will be taken as node points in lighting network. The overall system is based on the integration several subsystems. All the nodes will be communicating with each other by sending different messages with the predefined identifiers. All the nodes present on the CAN bus will receive the same messages but with the frame filtering characteristics of the receiver, only matched identifiers will be accepted and then frame data will be received by the corresponding node. Depending on the different intensity values of the LDRs, relay and bulb on off condition will be changed and simultaneously display on each LCD display as well as computer. For security unit the password is set. Person entering the building must enter the correct password otherwise the entry will be restricted and triggering of alarm unit will be directed to main control unit. The system block diagram is as shown in figure 1.
Fig. 1. Complete System Block Diagram for Building Automation using CAN Bus
Each of the nodes consists of a CAN Transceiver, CAN controller, PIC microcontroller. In a CAN bus system, each of the nodes are connected to the main node which has both the CAN Controller and CAN transceiver. CAN bus require only 2 wires (CANH and CANL) to connect the other nodes. CAN Transceiver MCP2551
510 S.A. Shweta, D.P. Mukesh, and B.N. Jagdish
plays a significant role in determining a successful data transmission over the can bus terminal. CAN transceiver is required to shift the voltage levels of the microcontroller to those appropriate for the CAN bus. This will help to create the differential signal CAN High and CAN Low which are needed in CAN bus.
MCP 2515 is standalone CAN controller has two acceptance masks and six acceptance filters that are used to filter out unwanted messages thereby reducing host MCUs overhead. The MCP 2515 interfaces with host MCU using industry standard SPI (Serial Peripheral Interface) as shown in figure 2 below. The main controller PIC16F877 includes the features like 10-bit, 8 channel ADC module, Synchronous Serial Port (SSP) with SPI and I2C, USART.
COMPONENTS OF A LIGHTING COMPONENTSOFINTERFACINGNODE NODE TO PCTXLDRMAX 232RXAN0 /RN0SDITX RX PIC 16F877SDOUSARTSDI PIC 16F877SDOSI SOMCP 2515RX CANSI SOTX CAN MCP 2515 RX CAN+5VTX CAN+5V RSVSS TXCANHMCP 2551RXCANLVDDRSVSSTX RXCANH MCP 2551 CANLVDDCAN BUSCAN BUS
Fig. 2. Components of Lighting node and Interfacing node
Figure 2 shows different components used in Lighting and interfacing node. In the
lighting nodes, the LDR sensors will measure the intensities of different values. The PIC microcontroller PIC16F877 will convert the data into digital form and through the SPI interface the data is send to CAN controller MCP2515 and CAN transceiver Finally data is sent to interfacing node which in turn will send the frame message to either turn on or off the relay. Lighting nodes will accordingly respond to this with message identifiers which are predefined and displays the required action on the LCD module. This interfacing node sends messages to both lighting nodes as well as to PC through USART interface. The converter MAX232 will convert CAN bus voltages to TTL logic levels [3]. It will transmit as well as receive different messages and controls overall system In case of wrong authentication password ,the error message will be forwarded to alarm unit and entry will be restricted In the keypad node along with PIC controller and CAN controller ,a keypad module is been added using which the initial preset values are entered. Also the preset password is added for the security purpose. If the values exceeds or goes below preset values, the interfacing node will send the corresponding messages to respective nodes.
Implementation of Controller Area Network (CAN) Bus (Building Automation) 511
3 System Design: Software
The programming for PIC microcontroller is done by C- language by setting of different CAN controller registers and CAN configuration registers. The compiler used is Micro C compiler. The program is written for each of the individual nodes through which the message identifiers are set and to matched identifiers the respected node will respond .In case if the correct message is not r received the error message will be generated. The interface node main goal is to translate CAN 2.0A frames into serial port RS232 frames using MAX232 converter and vice versa. The system software allows bidirectional data transfer between nodes and PC through the interfacing node. The window to enter the display updated values of LDR intensities and to enter the password for authentication is developed using Visual Basics.
CANSPI Library routines:
The SPI module is available with a number of the PI C compliant MCUs. The mikroBasic PRO for PIC provides a library for working with CANSPI Add-on boards (with MCP2515 or MCP2510) via SPI interface. Some of them used in the project are,
CANSPIInitialize
sub procedure CANSPIInitialize(dim SJW as byte, dim BRP as byte, dim PHSEG1 as byte, dim PHSEG2 as byte, dim PROPSEG as byte, dim CANSPI_CONFIG_FLAGS as byte)
CANSPIRead
sub function CANSPIRead(dim byref id as longint, dim byref rd_data as byte[8], dim data_len as byte, dim CANSPI_RX_MSG_FLAGS as byte) as byte CANSPIWrite
sub function CANSPIWrite(dim id as longint, dim byref wr_data as byte[8], dim data_len as byte, dim CANSPI_TX_MSG_FLAGS as byte) as byte
Lighting Node algorithm:
• • • • • • • • • • • •
Initialize I/O ports .Clear flags
Configure different CANSPI modules. Read and convert LDR data
Send the data to main control unit with TX_ID=2 After delay, receive message with RX_ID=6
Check first character of message and accordingly turn ON or OFF the relay Set the limit value of nodes and password Process nodes value.
For node 1, if process value>set value then turn on the relay1 For node 2, if process value>set value then turn on the relay2 Receive IR input
Verify password. If yes ,process nodes value. If no ,turn the buzzer on.
Main control unit algorithm:
512 S.A. Shweta, D.P. Mukesh, and B.N. Jagdish
4 Results and Analysis
A screen capture of the system with different lighting nodes and interfacing card is presented in figure 3. Complete hardware and software is tested. The desired results are verified using the designed system.
Fig. 3. Screen capture of system
A lighting node with two different intensity values displayed on the LCD and corresponding turning ON or OFF of the relays is represented in figure 4 and 5.
Fig. 4. Lighting node process value>set value, relay ON
Fig. 5. Lighting node process value Implementation of Controller Area Network (CAN) Bus (Building Automation) 513 Fig. 6. GUI developed in VB for user interface 5 Conclusions A small lighting network along with security provision allowing only authenticated users for building automation is implemented. It is composed of only four nodes ,but the proposal can be expanded to a total number of 2048 network nodes and the use of any other kind of sensors required by individual subunits of BAS are possible[1]. This system requires only two wires and hence more efficient. The distributed processing from different component performed by different nodes reduces load on main controller thus increase in system performance. The proposed system based on microcontroller is found to be more compact, user friendly and less complex, which can readily be used in order to perform several difficult and repetitive tasks. The problems associated with wireless automation like physical obstructions, health concerns, data security, reliability, distance coverage can be overcome by implementing this CAN bus network. The Controller Area Network (CAN) is an asynchronous serial CSMA/CD communication protocol for microcontrollers networks, supporting distributed real-time control (bit rate up to 1Mbps) with a very high level of security. Taking into account the different advantages of CAN bus a complete BAS (Building Automation System) for monitoring and controlling different subunits such as vehicle parking system[5], plumbing system, lifts and elevators,gardening system can be implemented. References [1] Díaz, J., Rodriguez, E., Hurtado, L., Cacique, H., Ramírez, A., Vázquez, N.: LightNet a Reliable Option for Lighting Applications, enics. In: 2008 International Conference on Advances in Electronics and Micro-electronics, pp. 159–164 (2008) [2] Esro, M., Basari, A.A., Siva Kumar, S., Sadhiqin M I, A., Syariff, Z.: Controller Area Network (CAN) Application in Security System. World Academy of Science, Engineering and Technology 59 (2009) [3] Ran, P., Wang, B., Wang, W.: The Design of Communication Convertor Based on CAN Bus. In: Proceedings of the 2008 IEEE/ASME International Conference on Advanced Intelligent Mechatronics, July 2 - 5 (2008) 514 S.A. Shweta, D.P. Mukesh, and B.N. Jagdish [4] Robles1, R.J., Kim1, T.-h.: Applications, Systems and Methods in Smart Home Technology: A Review. International Journal of Advanced Science and Technology 15 (February 2010) [5] Chou, L.-D., Sheu, C.-C., Chen, H.-W.: Design and Prototype Implementation of A Novel Automatic Vehicle Parking System. International Journal of Smart Home 1(1) (January 2007) [6] Dong, X., Wang, K., Zhao, K.: Design and Implementation of an Automatic Weighing System Based on CAN Bus. In: Proceedings of the 2008 IEEE/ASME International Conference on Advanced Intelligent Mechatronics, July 2 - 5 (2008) 因篇幅问题不能全部显示,请点此查看更多更全内容