Controller Area Network (CAN) is a broadcast, differential serial bus standard, originally developed in the 1980s by Robert Bosch GmbH, for connecting electronic control units (ECUs). CAN was specifically designed to be robust in electromagnetically noisy environments and can utilize a differential balanced line like RS-485. It can be even more robust against noise if twisted pair wire is used. Although initially created for automotive purposes (as a vehicle bus), nowadays it is used in many embedded control applications (e.g., industrial) that may be subject to noise. The messages it sends are small (8 data bytes max) but are protected by a CRC-15 (polynomial 0x62CC) that guarantees a Hamming bit length of 6 (so up to 5 bits in a row corrupted will be detected by any node on the bus).
Bit rates up to 1 Mbit/s are possible at network lengths below 40 m. Decreasing the bit rate allows longer network distances (e.g. 125 kbit/s at 500 m).
The CAN data link layer protocol is standardized in ISO 11898-1 (2003). This standard describes mainly the data link layer — composed of the Logical Link Control (LLC) sublayer and the Media Access Control (MAC) sublayer — and some aspects of the physical layer of the OSI Reference Model. All the other protocol layers are left to the network designer's choice.
CAN features an automatic 'arbitration free' transmission. A CAN message transmitted with highest priority will 'win' the arbitration, and the node transmitting the lower priority message will sense this and back off and wait.
This is achieved by CAN transmitting data through a binary model of "dominant" bits and "recessive" bits where dominant is a logical 0 and recessive is a logical 1. This means open collector, or 'wired or' physical implementation of the bus (but since dominant is 0 this is sometimes referred to as wired-AND). If one node transmits a dominant bit and another node transmits a recessive bit then the dominant bit "wins" (a logical AND between the two).
So, if you are transmitting a recessive bit, and someone sends a dominant bit, you see a dominant bit, and you know there was a collision. (All other collisions are invisible.) The way this works is that a dominant bit is asserted by creating a voltage across the wires while a recessive bit is simply not asserted on the bus. If anyone sets a voltage difference, everyone sees it, hence, dominant. Thus there is no delay to the higher priority messages, and the node transmitting the lower priority message automatically attempts to re-transmit 6 bit clocks after the end of the dominant message.
When used with a differential bus, a Carrier Sense Multiple Access/Bitwise Arbitration (CSMA/BA) scheme is often implemented: if two or more devices start transmitting at the same time, there is a priority based arbitration scheme to decide which one will be granted permission to continue transmitting. The CAN solution to this is prioritised arbitration (and for the dominant message delay free), making CAN very suitable for real time prioritised communications systems.
During arbitration, each transmitting node monitors the bus state and compares the received bit with the transmitted bit. If a dominant bit is received when a recessive bit is transmitted then the node stops transmitting (i.e., it lost arbitration). Arbitration is performed during the transmission of the identifier field. Each node starting to transmit at the same time sends an ID with dominant as binary 0, starting from the high bit. As soon as their ID is a larger number (lower priority) they'll be sending 1 (recessive) and see 0 (dominant), so they back off. At the end of ID transmission, all nodes but one have backed off, and the highest priority message gets through unimpeded.
arrier Sense Multiple Access (CSMA) is a probabilistic Media Access Control (MAC) protocol in which a node verifies the absence of other traffic before transmitting on a shared physical medium, such as an electrical bus, or a band of electromagnetic spectrum.
"Carrier Sense" describes the fact that a transmitter listens for a carrier wave before trying to send. That is, it tries to detect the presence of an encoded signal from another station before attempting to transmit. If a carrier is sensed, the node waits for the transmission in progress to finish before initiating its own transmission.
"Multiple Access" describes the fact that multiple nodes send and receive on the medium. Transmissions by one node are generally received by all other nodes using the medium.
Collisions
Concurrent transmission by multiple nodes results in frame collisions. The multiple transmissions interfere with each other so that all are garbled and receivers are unable to distinguish the overlapping received signals from each other. It is impossible to entirely prevent collisions in CSMA networks, but there are three ways to address them:
* In pure CSMA, only the carrier sense is used to avoid collisions. If two nodes try to send a frame at nearly the same time, neither detects a carrier so both begin transmitting. The transmitters do not detect collisions, so transmit the entire frame (thus wasting the bandwidth used). Receivers cannot distinguish between collisions and other sources of frame errors, so collision recovery relies on the ability of the communicating nodes to detect frame errors and invoke an error recovery procedure. For example, the receiver may not send a required ACK, causing transmitters to time out and retry.
* In Carrier Sense Multiple Access With Collision Avoidance (CSMA/CA), each node must inform other nodes of an intent to transmit. When the other nodes have been notified, the information is transmitted. This arrangement prevents collision because all nodes are aware of a transmission before it occurs. However, collisions are still possible, and are not detected so have the same consequences as in pure CSMA.
* In Carrier Sense Multiple Access With Collision Detection (CSMA/CD), sending nodes are able to detect when a collision occurs and stop transmitting immediately, backing off for a random amount of time before trying again. This results in much more efficient use of the media since the bandwidth of transmitting the entire frame is not wasted. However, it is not possible with all media (e.g., radio), and requires extra electronics (not really an issue with today's technology, but one reason Apple used CSMA/CA-based LocalTalk instead of the then much more expensive Ethernet).
* In Carrier Sense Multiple Access with Bitwise Arbitration (CSMA/BA, also known as CSMA/CR - collision resolution), all of the nodes on the bus are assigned an identification number or priority code. When a collision occurs, one of the nodes that are attempting to send at the same time will be given priority to transmit according to its identification number or priority code (as opposed to waiting a random amount of time and then retransmitting, as in CSMA/CD). Used in CAN communications, often found on vehicles.
* There is another newer technology called Carrier Sense Multiple Access with Collision Prevention (CSMA/CP).
There are three types of collisions
* Local collision
* Remote collision
* Late collision
Protocols Using CSMA
* The ALOHAnet wireless network used pure CSMA
* 802.11 DCF uses a form of CSMA
* Ethernet uses CSMA/CD when in half duplex mode (but not in full duplex mode)
* LocalTalk uses CSMA/CA
* IEEE 802.11 (Wireless LAN) uses CSMA/CA
* CAN uses CSMA/BA
* IEEE 802.15 (Wireless PAN) uses CSMA/CA
Layers
Based on levels of abstraction, the structure of the CAN protocol can be described in terms of the following layers:
* Application Layer
* Object Layer
o Message Filtering
o Message and Status Handling
* Transfer Layer
The Transfer Layer represents the kernel of the CAN protocol. It presents messages received to the object layer and accepts messages to be transmitted from the object layer. The transfer layer is responsible for bit timing and synchronization, message framing, arbitration, acknowledgement, error detection and signaling, and fault confinement. It performs:
o Fault Confinement
o Error Detection
o Message Validation
o Acknowledgement
o Arbitration
o Message Framing
o Transfer Rate and Timing
o Information Routing
* Physical Layer
The physical layer defines how the signals are actually transmitted. Tasks include:
o Signal Level and Bit Representation
o Transmission Medium
Frames
A CAN network can be configured to work with two different message (or "frame") formats: the standard or base frame format (or CAN 2.0 A), and the extended frame format (or CAN 2.0 B). The only difference between the two formats is that the “CAN base frame” supports a length of 11 bits for the identifier, and the “CAN extended frame” supports a length of 29 bits for the identifier, made up of the 11-bit identifier (“base identifier”) and an 18-bit extension (“identifier extension”). The distinction between CAN base frame format and CAN extended frame format is made by using the IDE bit, which is transmitted as dominant in case of an 11-bit frame, and transmitted as recessive in case of a 29-bit frame. CAN controllers, which support extended frame format messages are also able to send and receive messages in CAN base frame format. All frames begin with a start-of-frame (SOF) bit that, obviously, denotes the start of the frame transmission.
CAN has four frame types:
* Data frame: a frame containing node data for transmission
* Remote frame: a frame requesting the transmission of a specific identifier
* Error frame: a frame transmitted by any node detecting an error
* Overload frame: a frame to inject a delay between data and/or remote frames
Data frame
The data frame is the only frame for actual data transmission. There are two message formats:
* Base frame format: with 11 identifier bits
* Extended frame format: with 29 identifier bits
The CAN standard requires the implementation must accept the base frame format and may accept the extended frame format, but must tolerate the extended frame format.
Base frame format
The frame format is as follows:
Field name Length (bits) Purpose
Start-of-frame 1 Denotes the start of frame transmission
Identifier 11 A (unique) identifier for the data
Remote transmission request (RTR) 1 Must be dominant (0)Optional
Identifier extension bit (IDE) 1 Must be dominant (0)Optional
Reserved bit (r0) 1 Reserved bit (it must be set to dominant (0), but accepted as either dominant or recessive)
Data length code (DLC) 4 Number of bytes of data (0-8 bytes)
Data field 0-8 bytes Data to be transmitted (length dictated by DLC field)
CRC 15 Cyclic redundancy check
CRC delimiter 1 Must be recessive (1)
ACK slot 1 Transmitter sends recessive (1) and any receiver can assert a dominant (0)
ACK delimiter 1 Must be recessive (1)
End-of-frame (EOF) 7 Must be recessive (1)
One restriction placed on the identifier is that the first 7 bits cannot be all recessive bits. (I.e., the 16 identifiers 1111111xxxx are invalid.)
Extended frame format
The frame format is as follows:
Field name Length (bits) Purpose
Start-of-frame 1 Denotes the start of frame transmission
Identifier A 11 First part of the (unique) identifier for the data
Substitute remote request (SRR) 1 Must be recessive (1)Optional
Identifier extension bit (IDE) 1 Must be recessive (1)Optional
Identifier B 18 Second part of the (unique) identifier for the data
Remote transmission request (RTR) 1 Must be dominant (0)
Reserved bits (r0, r1) 2 Reserved bits (it must be set dominant (0), but accepted as either dominant or recessive)
Data length code (DLC) 4 Number of bytes of data (0-8 bytes)
Data field 0-8 bytes Data to be transmitted (length dictated by DLC field)
CRC 15 Cyclic redundancy check
CRC delimiter 1 Must be recessive (1)
ACK slot 1 Transmitter sends recessive (1) and any receiver can assert a dominant (0)
ACK delimiter 1 Must be recessive (1)
End-of-frame (EOF) 7 Must be recessive (1)
The two identifier fields (A & B) combined form a 29-bit identifier.
Remote frame
The remote frame is identical to the data frame except:
* the RTR bit is set to recessive (1)
* data length contains the number of bytes that are required from the data frame
Error frame
Error frame consists of two different fields
The first field is given by the superposition of ERROR FLAGS contributed from different stations. The following second field is the ERROR DELIMITER.
There are two types of error flags
Active Error Flag
Transmitted by a node detecting an error on the network that is in error state "error active".
Passive Error Flag
Transmitted by a node detecting an active error frame on the network that is in error state "error passive".
Overload frame
The overload frame contains the two bit fields Overload Flag and Overload Delimiter. There are two kinds of overload conditions that can lead to the transmission of an overload flag:
1. The internal conditions of a receiver, which requires a delay of the next data frame or remote frame.
2. Detection of a dominant bit during intermission.
The start of an overload frame due to case 1 is only allowed to be started at the first bit time of an expected intermission, whereas overload frames due to case 2 start one bit after detecting the dominant bit. Overload Flag consists of six dominant bits. The overall form corresponds to that of the active error flag. The overload flag’s form destroys the fixed form of the intermission field. As a consequence, all other stations also detect an overload condition and on their part start transmission of an overload flag. Overload Delimiter consists of eight recessive bits. The overload delimiter is of the same form as the error delimiter.
Interframe spacing
Data frames and remote frames are separated from preceding frames by a bit field called interframe space. Overload frames and error frames are not preceded by an interframe space and multiple overload frames are not separated by an interframe space. Interframe space contains the bit fields intermission and bus idle and, for error passive stations, which have been transmitter of the previous message, suspend transmission.
Bit stuffing
In CAN frames, a bit of opposite polarity is inserted after five consecutive bits of the same polarity. This practice is called bit stuffing, and is due to the "Non Return to Zero" (NRZ) coding adopted. The "stuffed" data frames are destuffed by the receiver. Since bit stuffing is used, six consecutive bits of the same type (111111 or 000000) are considered an error. Bit stuffing implies that sent data frames could be larger than one would expect by simply enumerating the bits shown in the tables above.
Standards
There are several CAN physical layer standards:
* ISO 11898-2: CAN high-speed
* ISO 11898-3: CAN fault-tolerant (low-speed)
* ISO 11992-1: CAN fault-tolerant for truck/trailer communication
* ISO 11783-2: 250 kbit/s, Agricultural Standard
* SAE J1939-11: 250 kbit/s, Shielded Twisted Pair (STP)
* SAE J1939-15: 250 kbit/s, UnShielded Twisted Pair (UTP) (reduced layer)
* SAE J2411: Single-wire CAN (SWC)
ISO 11898-2 uses a two-wire balanced signaling scheme. It is the most used physical layer in car powertrain applications and industrial control networks.
ISO 11898-4 standard defines the time-triggered communication on CAN (TTCAN). It is based on the CAN data link layer protocol providing a system clock for the scheduling of messages.
SAE J1939 standard uses a two-wire twisted pair, -11 has a shield around the pair while -15 does not. SAE 1939 is widely used in agricultural & construction equipment.
ISO 11783-2 uses four unshielded twisted wires; two for CAN and two for terminating bias circuit (TBC) power and ground. This bus is used on agricultural tractors. This bus is intended to provide interconnectivity with any implementation adhering to the standard.
Application layer implementations
As the CAN standard does not include tasks of application layer protocols, such as flow control, device addressing, and transportation of data blocks larger than one message, many implementations of higher layer protocols were created. Among these are DeviceNet, CANopen, SDS, CANaerospace, J1939, NMEA 2000, CAN Kingdom and SafetyBUS
This article is from http://en.wikipedia.org/wiki/Controller_Area_Network All text is available under the terms of the GNU Free Documentation License(http://en.wikipedia.org/wiki/Wikipedia:Copyrights)
Monday, June 18, 2007
Subscribe to:
Comments (Atom)