Can
Can
Summary
Atmel has developed a family of CAN Controllers for the various applications that use this serial bus to interconnect Smart system. With its multi-master capability, built in error detection and correction capability, and large industry acceptance, the CAN bus is an attractive standard with a bright future.
Atmel Corporation 2325 Orchard Parkway San Jose, CA 95131 TEL (408) 441-0311 FAX (408) 487-2600 Web Site: http://www.atmel.com
Table of Contents
Atmel Microcontrollers for Controller Area Network (CAN)................... 1 Background overview ............................................................................... 3 CAN Bus ..................................................................................................... 4
Controller ........................................................................................................................4 Physical Layer ................................................................................................................7
Conclusion ............................................................................................... 18
References ...................................................................................................................18
4069A CAN02/04
Background overview
Robert Bosch introduced the Controller Area Network (CAN) serial bus in 1986, for automotive engine control communication. Most of todays passenger cars have a CAN bus under the hood. Some also use CAN for body control also called Multiplexing. In the early nineties, two initiatives took place on both side of the Atlantic ocean. In Europe at Holger Zeltwanger initiative, the CAN In Automation (CiA) was created with many Manufacturers from different industries joining forces. Shortly after the CANopen higher layer protocol was defined as a framework for programmable systems. The CANopen communication profile paved the way for the multiple applications dedicated profiles that exist today. At the same time in North America Allen-Bradley and Honeywell teamed up to develop a CAN higher layer protocol for factory automation. The outcome of this initiative was the DeviceNet High Layer Protocol used in most of the factory automation systems in North America nowadays. DeviceNet is now supported by the Open DeviceNet Vendor Association (ODVA). The OSEK higher Layer Protocol has been adopted by the automotive industry. CAN OSEK is a prerequisite for system used by the big three: Ford, GM, Daimler Chrysler. Other specialty CAN higher layer protocols were developed too. Since year 2000, we can see the emergence of CAN in non-traditional applications (i.e. outside Automotive and Factory Automation). This is the result of smaller industries adopting a well proven standard for communications. Credit has to be paid to CANopen which offers a framework and CAN In Automation that promotes and facilitate such initiatives. The CAN deployment in Medical application and the CANopen in operating room are good examples. On a different note, vacationers in Las Vegas riding the monorail up and down the strip shouldnt be surprise to learn that their comfort and safety rely on CAN for the automatic door control. The next step in the CAN story is the definition and introduction of CAN Safety for critical applications. As explained later on in this document, inside a network the critical nodes will carry an extra layer (safety layer) while regular nodes on this given network will run standard CAN.
4069A CAN02/04
CAN Bus
The CAN bus is a 2 wires serial bus with Multi-Master capability. This means that multiple devices sitting on a single 2 wires bus can talk to one another. CAN includes a CSMA/CD (Carrier Sense Multiple Access with Collision Detection). Each device can transmit a message and will retry if it loses the arbitration to another device. Each device listen to the bus and thus a device trying to transmit can determine easily if the message ongoing is the same than the one it tries to transmit. If it is different, it will release the bus immediately. This arbitration mechanism insures that one master will always win, thus no messages will be lost to a collision. This mechanism differs significantly from Ethernet LAN bus. In Ethernet, a device trying to transmit a frame will monitor the line and wait until the line is available then starts transmitting. If 2 or more transmitters start, a collision will occur. All transmitters will stop. Each transmitter will then wait a random time interval before attempting a transmission again. In summary, there is a lost of time and frame transmission is aborted every time a collision occur on an Ethernet LAN. This explains why in most of todays Ethernet LAN applications, nodes are connected point to point to a Bridge or Router. To illustrate this point, lets take the example of a bottling line. On this lines, sensors will be deployed, conveyor will be moved by drives, Valves will be installed, scanners and Programmable Logic Controllers (PLC) will be deployed too. With a CAN implementation, one single cable will probably connect all devices while, with an Ethernet LAN implementation a star cabling scheme will be used to connect each device to a bridge. In CAN, errors are detected with a CRC check. Message are acknowledged at the end of the frame by a special acknowledge bit. Receivers assert the ACK bit acknowledge proper reception. With all the above, The CAN bus can offer a 100% data integrity in the harsh environment found in cars and manufacturing floors. The CAN robustness has a cost. All nodes are synchronized on the same bit time period. The group delay cannot exceed a fraction of the bit time period which lead to the maximum bus throughput being a function of the bus length. The maximum throughput is 1Mb/s with up to 40m bus length and 50Kb/s with up to 1km bus length. With point-to-point Ethernet LAN connection between a device and a bridge with a UTP5 cable 10Mb/s could be achieved up to 100m.
Controller
The CAN controller handles the delineation of incoming frames, and extraction of the various payload information carried by the frame. The CAN controller assembles the frames on the transmit side, then attempts to send it on the bus while monitoring it. It will drop the line if it loses the arbitration. The CAN message Frame format is described in the figure below.
4069A CAN02/04
del
Bus Frame
Duration in Data Bit
ARBITRATION
CTRL 6
DATA 064
del
EOF 7
IFS 3
SOF Start of Frame CRC Cyclic Redundancy Code del Delimiter ACK Acknowledge
Remote Transmission Request Substitute Remote Request Reserved bits Data Length Code
The arbitration mechanism is explained in the following figure. Figure 2. Arbitration mechanism
Start of Frame Arbitration Field Node 1: TxD Node 2: TxD Node 3: TxD CAN Bus
As we can see in the figure above, the node1 wins the arbitration and continues on with its message transmission while node2 and node3 wait the end of frame before re-attempting to send their messages. See below in the Physical Layer paragraph the description the dominant bit 0 / recessive bit 1 mechanism involved in the arbitration. Each messages start with an address field. As addresses are unique, the arbitration will be completed at the end of address transmission on the bus, and only one device will carry-on with the message transmission. CAN protocol have specified 2 addressing schemes: CAN2.0A with 11 bit address CAN2.0B with 29 bit address
11 bit address CAN2.0A is used for small networks with 2048 different addresses maximum. As we will see later on in the Higher Layer Protocol section, simple nodes can use about 10 Addresses (IDE). 2048 different addresses translate in 200 nodes maximum. CAN2.0B with 29-bit address push the limit much farther.
4069A CAN02/04
In CAN the Address Field is called ID/IDE (Identifier: Identifier Extension). Reader familiar with Telecom ISDN will see the similarity with SAPI/TEI. It is curious to note that ISDN LAPD arbitration is somewhat similar to CAN arbitration too. Figure 3. CAN2.0A and CAN2.0B frame formats
Bit Stuffing
SOF
ACK
del
Bus Frame
Duration in Data Bit
ARBITRATION
CTRL 6
RTR RB0 IDE
DATA 064
CRC 15
del
EOF 7
IFS 3
1 SOF
12- 32
CAN - V2.0A
Duration in Data Bit
ID 11
ARBITRATION
DLC 4
DATA
1 CTRL
SRR
ID[28..18] 11
RTR
IDE
CAN - V2.0B
Duration in Data Bit
SOF
RB1
RB0
ID[17..0]
DLC 4
DATA
1 18 ARBITRATION
1 CTRL
SOF Start of Frame CRC Cyclic Redundancy Code del Delimiter ACK Acknowledge
Remote Transmission Request Substitute Remote Request Reserved bits Data Length Code
The data field is CAN2.0A and CAN2.0B is 8 bytes. This is dimensioned for the short messages exchanged in CAN applications. The DLC field indicates how many data bytes are present in the data field (max 8). higher layer protocols provide a way to exchange messages with more than 8 bytes data. This is called fragmented messages. A simple example to illustrate this feature is the field reprogramming of devices installed on a network. This will be detailed later on and a specific section will deal about Field reprogramming. While the transmitter drive the bus from the Start Of Frame (SOF) to the CRC and Delay bit, the receiver drive the ACK bit. This is the way the transmitter is informed that receivers received the frame. Bit stuffing is implemented on the message as indicated in the figure above. Bit stuffing consists upon adding a bit of the opposite value following a sequence of 5 consecutive bits at the same value. Bit stuffing provides a minimum density of edges to help devices stay in synchronization. Detailed description of the bit field not described here can be found in CAN recommendation or in Atmel CAN controller datasheets.
4069A CAN02/04
Physical Layer
The CAN physical medium is a two-wire bus line with common return terminated at both ends by resistors. Differential signal is used for better immunity. The following figure shows a transmit signal from a CAN controller, the differential signal emitted on the line and the receive signal received by the CAN controller to monitor the CAN bus. Figure 4. CAN Physical Layer
TXd TXd CAN Controller RXd CAN Transceiver CANh CANl CANh CANl Do minant RXd Do minant Recessive
A typical CAN bus in a factory automation application is a single line bus with stubs to connect equipments such as PLC, Sensors, Drives etc as illustrated by the figure below Figure 5. Typical CAN bus implementation
CAN Bus (up to 40m @1Mb/ s, up to 1km @50Kb/ s) Stub Device #1 Device #2 Device #3 Device #n
4069A CAN02/04
CAN Applications
Introduction
Many industries have adopted the CAN bus standard, and gained a lot in reliability and flexibility. For some applications, the cost and speed to deploy or reconfigure a communication network is critical such as a factory floor for instance. A CAN bus can be laid out, then equipments can be added thanks to the plug and play capability of CAN with Higher Layer Protocols.
4069A CAN02/04
A second category of maritime application is fishing industry as well as recreational boat. In such application we can find GPS, radar, sonar, fish finder, control dashboard, display plus various safety sensors. This represents a large volume business with fierce competition, especially in North America where recreation boats are numerous. All above equipments require CAN controllers with low power consumption, a lot of digital I/Os and analog I/Os, field reprogramming capability over the CAN bus, and overall, low cost.
4069A CAN02/04
For instance, a 10 stories building with 2 elevators will roughly have 100 CAN nodes (2 button panels + 2 display panels per floor + 1 button panel and 1 display panel per elevator + 40 proximity sensors + motor control + maintenance panel.). The controllers used in these systems will have to run a full protocol stack + offer digital I/Os and possibly Analog Input and PWM output. A button controller will have nothing more that the protocol stack to run and can use a low pin-count, minimum memory controller. The electric doors at the entrance of the building as well as the elevator doors will control motor drives that require a significant MIPS horsepower and memory (code + data) on top of the higher layer protocol. It will also have Analog Input and PWM control output plus digital I/O to control switches. This can round up to another 50 or so CAN nodes.
10
4069A CAN02/04
11
4069A CAN02/04
Now that we saw how the master communicate with the slave, lets see how slaves can exchange information directly using Process Data Object Communication (PDO) PDO allow portion of the Object dictionary to be sent. The simplest example is I/O devices that will send the bit value of an input every time a change on this input occur (event driven). Conversely this I/O can respond to a polling request or synchronized with a SYN message. Typical slave applications will have between 5 and 10 different PDOs In total, a typical slave application will have 7 to 12 different Identifiers (PDO+SDO). If a CAN controller can handle the different IDs concurrently this will greatly simplify the software and speed-up the CANopen stack execution time. See the next chapter on the message object description. CANopen like DeviceNet and other protocols support segmented transfer (fragmented messages in DeviceNet). This is the technique used to send a packet of information larger than 8 bytes. A good example of segmented messages is the re-flash system to reprogram a peripheral as defined by the CIA-DSP302 recommendation. In CANopen segmented messages will use the first 4 bytes to carry indexes and control status information while the real data will reside in the remaining 4 bytes data payload. CANopen or DeviceNet Slave implementations typically need 10 to 32Kbytes code. The RAM size is dimensioned by the size of the object dictionary.
Safety Bus
For safety critical applications, redundancy is used to increase the safety. We can identify 2 levels of critical systems nodes. Cost sensitive safety node (significant volume) Highly critical node (limited volume, not cost sensitive)
For the first category, the main controller transmit and receive on the CAN line while a second controller is added to monitor the CAN line. Both controllers then compare their result (compare the frame) exchanging over a dedicated serial line between them (UART or SPI) For highly critical devices, a more complex system will be used. It is under definition at this time.
12
4069A CAN02/04
Transceiver
Transmit
Receive
Transmit
Receive
Main Controller
Serial Port Cross-check
Monitoring Controller
Serial Port
13
4069A CAN02/04
All CAN Microcontrollers have a set of common features: Flash memory for code E2PROM RAM In Application Programming capability assisted by a bootloader. Same CAN engine to simpliify Software Migration. Low voltage capability (2.7 volts min) Enough MIPS to run high layer protocol + application
5-MIPS C51 core based controllers where first introduced between Y2000 and Y2003. In Y2004 Atmel is introducing the first AVR CAN controller with up to 16MIPS performance, and the set of memories and peripherals necessary to tackle higher-end applications.
5 MIPS Microcontrollers
3 controllers: T89C51CC01, T89C51CC02, AT89C51CC03 exist. With 5 MIPS at 5 volts and 16KBytes to 64KBytes Flash they cover a broad range of slave applications such as proximity sensor, DeviceNet I/O, textile machine I/O and many other applications. For low voltage applications, the 3 controllers maintain up to 3.3MIPS down to 2.7 volts. The T89C51CC02 with 16Kbytes Flash and 0.5Kbytes RAM + a simple 4 message objects CAN engine packaged into a Small Pin Count package cover low end applications where a minimum DeviceNet or CANopen slave stack is used. It is the perfect low cost product for a CAN controller push-button. The 4 message objects of the CAN engine are sufficient to cover simple slave applciations (see the high layer protocol detail description chapter to see the rational between application complexity and number of Message Object. The T89C51CC02 features a 2Kbytes E2PROM and a 2Kbytes Boot Flash for field in application reflashing. The T89C51CC01 was the first product introduced. With 32Kbytes Flash and 1.2 Kbytes RAM it is the perfect match for Slave applications. From 8 to 16 Kbytes of flash and at least 3 MIPS are left for the application on top of a CANopen or DeviceNet stack. The chip sports an 8 channels 10 bit A/D converter 3 timers, 5 high speed input/outpout timer units and 32 I/Os . The 15 message objects and the
14
4069A CAN02/04
1.2Kbytes RAM make the chip suitable for rather complex I/O systems. See the high layer protocol detail description chapter to see the rational between application complexity and number of message object. As each message objects can be programmed as a transmit or receive and has a unique ID address, it make it possible for a CANopen protocol stack for instance to assign one message object for each and every SPO and PDO which drastically simplify the software, reduce the amount of SRAM and allow the stack to run faster. The T89C51CC01 has a CAN or UART bootloader making it suitable for field in application reprogramming. It also has the 2Kbytes E2PROM necessary to save configuration set-up and data-log requested by higher layer protocol. The AT89C51CC03 is Atmel response to customer using the T89C51CC01 and in need for up to 32Kbytes Flash for the application program itself, and 2Kbytes RAM for larger Object Dictionary. The SPI port included also help in communication with other devices. The 15 message Objects are kept as well as the 2Kbytes Bootloader and 2Kbytes E2PROM.
The 3 controllers above share the same set of tools (C Compilers, Emulators) high layer protocol stacks developed by Software Tool Vendors run on all 3 products.
16 MIPS Microcontrollers
Atmel is introducing a CAN controller using the very successful AVR RISC architecture. The first controller is coming with 128Kbytes Flash, 4Kbytes RAM, and 4Kbytes E2PROM and offer 16MIPS. It immediately positions itself as the high-end controller of the CANary family. All the experience gained by Atmel in CAN applications was used in defining the AT90CAN128, the first CAN controller with AVR architecture. CAN engine: Software tool vendors requested an improvement on the CAN Engine Interrupt system in order to include a hardware sort mechanism which presents value of the first message object channel. This save up to 30S compared to the standard software sort procedure. 30S is 65% of a CAN frame period (@1Mb/s) With this improvement, the risk of frame overflow is eliminated, and software stacks do not need to assign 2 message objects to a single channel to overcome the risk of overflow. Other benefits were found in applications where the CAN controller acts as a CAN coprocessor of a 32-bit processor. The CAN engine also includes a mechanism called buffer. Multiple message objects can be grouped in one buffer. This is especially useful for fragmented message applications. We will use 2 examples to illustrate that Transmit fragmented message in a slave CANopen I/O : A slave I/O may have to reply to a PLC with a part of its Object Dictionary that is larger than 8-Bytes. In this case fragmented messages will be used. A buffer can be set-up with as many message Objets necessary for the buffer to contain in full all data to be returned to the PLC (see in the CANopen detail chapter the description of fragmented/Segmented message). Every time the PLC send a polling request, the I/O will spell out the complete response with a minimum CPU involvement. Receive fragmented message in a slave device : The reflash mechanism for field reprogramming can use fragmented messages. The configurator and the device can negotiate the width of the buffer, then the slave can tie as many message object as necessary into a receive buffer to read block of data.
15
4069A CAN02/04
In Application programming: Atmel developed for the T89C51CC01 a minimum bootloader program that can be used to reprogram in the field a device without disrupting the activity on the bus. Although this feature was well received, customers asked for a larger boot program, so they could squeeze a minimum DeviceNet or CANopen stack in the boot. This is possible with the AT90CAN128 where a special configurable part of the flash (from 0 to 8Kbytes) can be used for a custom boot program. Code size: Some applications need a large program space on top of the high layer protocol stack, with more than 64KBytes in total. With 128Kbytes flash, the AT90CAN128 perfectly address this request. RAM size: We saw earlier in the CANopen detailed description that typical slave Object Dictionary is using 1Kbytes RAM. This means that higher-end Slave applications will need significantly more, not to mention that the application itself may need a significant amount of RAM too. The AT90CAN128 with 4Kbytes RAM address this request. On chip debug support unit: A lot of applications using CAN, the CAN transceiver and controller are tucked in a small cabinet. It is not always possible to plug an emulator. On Chip Debug Support Unit becomes a very useful feature in such system. AT90CAN128 has a JTAG debug support unit that can also be used for flash programming. Rail-to-Rail Analog to Digital converter: In a lot of applications, analog input signal cover the full GND to VCC range. An Analog to Digital Converter that can convert such a signal is called a Rail-to-Rail ADC. The AT90CAN128 has a Rail-to-Rail ADC with 8 channels and 10 bit precision CAN Safety: As described in the CAN Safety chapter of this document, A fast serial link is required between the main controller and the monitoring controller. On this channel they will exchange the complete payload of a CAN receive message to verify that they both received the same information. If the true, then the main controller will consider the message otherwise it will be ignored. Two AT90CAN128 can be used in a CAN Safety application connected together over the SPI port. The AT90CAN128 is fast enough to support the extra load of the real-time check. The AT90CAN128 has many nice peripherals such as timers; it has a low mW/MIPS ratio. And is compatible with the Mega128 which simplify the development of a CAN application for the many customers and consultant already familiar with the Atmel Mega AVR family.
16
4069A CAN02/04
15 message objects 4 message objects 15 message objects 15 message objects No 3 to 5.5 10-bit, 8 channels 5 channels Timers 0/1/2 1 Port 0/1/2/3 UART / CAN TQFP44, PLCC44, CA-BGA64 No 3 to 5.5 10-bit, 8 channels 2 channels Timers 0/1/2 1 Port 1/2/3 UART / CAN SOIC24, SOIC28, TQFP32, PLCC28 Yes 3 to 5.5 10-bit, 8 channels 5 channels Timers 0/1/2 1 Port 0/1/2/3 same UART / CAN as T89C51CC01 TQFP44, PLCC44, CA-BGA64 Yes 2.7 to 5.5 10-bit, 8 channels No Timers 0/1/2/3 2 Port A/B/C/D/E/F/G UART / CAN
Packages
TQFP64, QFN64
17
4069A CAN02/04
Conclusion
CAN networking offers the reliability and large life span of a thoroughly thought solutions with industry leaders committed to it and working to continuously improve it. In return a significant number of semiconductor vendors offer CAN controllers. This makes it an attractive solution for customers looking at piggy-backing on a proven standard rather than inventing their own. This brings new applications some with large volume. The next positive factor is the willingness from customers to jointly specify special application software profiles. This attracts Software vendors to develop them. All together this create a win win situation from which everybody benefit. Atmel is well positioned to support the CAN networking with a state of the art microcontroller flash technology and the experience gained in CAN networking from an early start.
References
1. 2. CAN in Automation http://www.can-cia.com Michel Passemard (Atmel), Bob Pickering (Minit-Charger), Olaf Pfeiffer (ESA): Implementation of the CAN open profile for battery and charger ISO 11783 http://www.can-cia.org/icc/9/index.html ODVA the organization that supports network technologies built on the Common Industrial Protocol (CIP) DeviceNet, EtherNet/IP, CIP Sync and CIP Safety. http://www.odva.org/
3.
18
4069A CAN02/04
Editor's Notes
About Atmel Corporation
Founded in 1984, Atmel Corporation is headquartered in San Jose, California with manufacturing facilities in North America and Europe. Atmel designs, manufactures and markets worldwide, advanced logic, mixed-signal, nonvolatile memory and RF semiconductors. Atmel is also a leading provider of system-level integration semiconductor solutions using CMOS, BiCMOS, SiGe, and high-voltage BCDMOS process technologies. Further information can be obtained from Atmels Web site at www.atmel.com. Contact: Michel Passemard Industrial Control Business Development Director, Atmel Nantes, France, Tel: (+33) (0) 2 40 18 19 65, e-mail: [email protected]
Atmel Corporation 2004. All rights reserved. Atmel, AVR, megaAVR and combinations thereof are the registered trademarks of Atmel Corporation or its subsidiaries. DeviceNet is a trade mark of Open DeviceNet Vendor Association Inc. Other terms and product names in this document may be the trademarks of others.
19
4069A CAN02/04