5 Controller Area Networks
5 Controller Area Networks
Embedded Systems CMP 445 Spring 2011 Computer Engineering Cairo University
Outline
Introduction
Brief History Design Objectives CAN Architecture
Basic Concepts
Brief History
1986 CAN v1.0 by Robert Bosch GmbH. 1991 CAN v2.0 by Bosch. 1993 ISO 11898 CAN 1993 Mercedes S-class first car with CAN 2003 ISO 11898-1, 11898-2 revised CAN with physical layer characteristics 2008 US OBD-II automotive diagnostic standard mandates use of CAN
Design Objectives
Reliable communication
To deal with bit errors
Fault tolerance
To deal with hardware faults
node 2
node 3
node n
RT (120
RT = 120
CAN_L
Basic Concepts
Acceptance Filtering Bus Arbitration Bit Synchronization Error Detection and Signaling Fault Confinement Bus Length vs. Bit Rate
Acceptance Filtering
Broadcast system: all nodes can hear a transmission To avoid wasting processing power listening to uninteresting transmissions
Nodes implement a filter, to pass on messages based on their identification which usually represent their content all other messages are ignored.
Bus Arbitration
Physical Characteristics
NRZ Coding Scheme Differential Signaling
NRZ Coding
Non-Return-to-Zero NRZ encoding scheme
0 and 1 are encoded as a voltage levels A transition in signal level occurs only when a 0 is followed by 1 or vice-versa.
Differential Signaling
1 encoded as recessive 0 encoded as dominant
CSMA
Carrier Sense Multi-Access Every node must sense the channel and make sure it is idle for a minimum period of time (intermission period) before starting a frame transmission. Avoids collision with on-going transmissions Problem: if two node start transmitting at the exact same time
Collision Detection
CAN bus behaves like an AND gate. If any node writes a dominant bit 0, the bus will have a dominant state 0. Otherwise, the bus will have a recessive state 1. Each transmitting node samples the bus during each bit. If written sampled, a collision is detected
Contention Resolution
Frame starts with an 11-bit id field transmitted most significant bit first A node detecting a collision (bus dominant while transmitting recessive) stops Messages with low binary value id win Losing node retries after bus is idle
Synchronization
No global clock signal, nodes use local oscillators Local bit time vary slightly from nominal bit time Periodic errors accumulate and synch is lost
Synchronization Mechanism
A receiver synchronizes to the transmitter clock by detecting transitions and compensating local clock Hard synchronization with first recessive-to-dominant edge (=dominant Start Of Frame (SOF)bit) after bus idle Continuous re-synchronization at every recessive-todominant edge transition
Bit Stuffing
NRZ has not enough edges for resynchronization After 5 consecutive bits with same polarity (dominant or recessive), a bit with complementary polarity will be inserted Receiver filters the complementary bit away
sync_seg
prop_seg
phase_seg1
phase_seg2
Sample point
sync_seg Segment
A synchronized receiver expects a falling edge transition to occur only within this segment. When the receiver is slower the falling edge will tend to occur earlier in phase_seg2 of the previous bit time. When the receiver is faster the falling edge will tend to occur later in the prop_seg or phase_seg1 of the same bit time.
prop_seg Segment
Equals twice the sum of the signals propagation time on the CAN bus line, the input comparator delay, and the output driver delay. A transmitter expects acknowledgement bit to arrive from a synchronized receiver right after prop_seg
Sample Point
At the end of phase_seg1 segment. Users can choose to take three samples instead of one.
A majority function determines the bit value when three samples are taken. Each sample is separated by half time quantum from the next sample.
The time spent on determining the bit value is the information processing time.
<
In the absence of bus errors, bit stuffing guarantees a maximum 12-bit between resynchronization edges. The accumulated phase errors are due to the tolerance in the CAN system clock. This requirement can be expressed as (2 f) 12 NBT < tSJW (4) where, f is the largest absolute relative error in oscillator frequency (usu. < 0.5%)
Example: Problem
Calculate the CAN bit segments for the following constraints:
Bit rate = 1 Mbps Bus length = 25 m Bus propagation delay = 5 10-9 sec/m Output driver plus input comparator propagation delay = 150 ns at 85oC CPU oscillator frequency = 24 MHz IPT = 2 TQ
Example: Solution
1. 2.
3. 4. 5. 6. 7. 8.
NBT = 1/1 Mbps = 1 s Physical delay of the CAN bus = 25 5 = 125 ns tPROP_SEG = 2 (125 + 150) = 550 ns A prescaler of 1 for 24 MHz gives a time quantum of 41.67 ns. Prop_seg = round_up (550 ns 41.67) = 14 > 8. Set prescaler to 2. Then one time quantum is 83.33 ns and one bit time is 12 time quanta. The new prop_seg = 7. NBT prop_seg1 sync_seg = 12 7 1 = 4. phase_seg1 = 2, phase_seg2 = 4 phase_seg1 phase_seg2 = 2 SJW = min (4, phase_seg1) SJW = 2 f < SJW (2 12 NBT) = 2 (2 12 12) = 0.69% The oscillator tolerance is 0.69%.
Example 13.2 Calculate the CAN bit segments for the following constraints: Bit rate = 500 Kbps Bus length = 50 m Bus propagation delay = 5 10-9 sec/m CAN transceiver plus receiver propagation delay = 150 ns at 85oC CPU oscillator frequency = 16 MHz Solution: Step 1 Physical delay of the bus = 50 5 10-9 sec/m = 250 ns tPROP_SEG = 2 (250 + 150) = 800 ns Step 2 Use 2 as the prescaler. The resultant TQ is 125 ns. A normal bit time is 2 ms. Quanta per bit = 2,000 /125 = 16 Step 3 Prop_seg = round_up (800 125) = 7. Step 4 Subtract 7 and 1 from 16 time quanta per bit gives 8. Since this number is even and greater than 4, divide it by 2 and assign it to phase_seg1 and phase_seg2.
Step 5 RJW = min (4, phase_seg1) = 4 Step 6 From equation 13.6, f < RJW (2 12 NBT) = 4 (24 16) = 1.04%
In summary,
Prescaler Nominal bit time Prop_seg Sync_seg Phase_seg1 Phase_seg2 RJW Oscillator tolerance =2 = 16 =7 =1 =4 =4 =4 = 1.04%
Data Frame
A data frame consists of seven fields: start-offrame, arbitration, control, data, CRC, ACK, and end-of-frame.
Interframe space or overload frame
Data Frame
CRC field
ACK field
End of frame
Start of Frame
A single dominant bit to mark the beginning of a data frame. All nodes have to synchronize to the leading edge caused by this field.
Arbitration Field
There are two formats for this field: standard format and extended format.
Interframe space Start of frame (a) standard format Arbitration field Start of frame Control field r1 DLC Arbitration field 11 bit Identifier RTR Control field IDE r0 DLC
The identifier of the standard format corresponds to the base ID in the extended format. The RTR bit is the remote transmission request and must be 0 in a data frame. The SRR bit is the substitute remote request and is recessive. The IDE field indicates whether the identifier is extended and should be recessive in the extended format. The extended format also contains the 18-bit extended identifier.
Control Field
Contents are shown in figure 13.4. The first bit is IDE bit for the standard format but is used as reserved bit r1 in extended format. r0 is reserved bit. DLC3DLC0 stands for data length and can be from 0000 (0) to 1000 (8).
Arbitration field IDE/r1 r0 Control Field Data field or CRC field DLC1 DLC0 DLC3 DLC2
reserved bits
Data Field
May contain 0 to 8 bytes of data
CRC Field
It contains the 16-bit CRC sequence and a CRC delimiter. The CRC delimiter is a single recessive bit.
Data or Control field CRC field ACK
CRC delimiter
ACK Field
Consists of two bits The first bit is the acknowledgement bit.
This bit is set to recessive by the transmitter, but will be reset to dominant if a receiver acknowledges the data frame.
Remote Frame
Used by a node to request other nodes to send certain type of messages Has six fields as shown in Figure 13.7
These fields are identical to those of a data frame with the exception that the RTR bit in the arbitration field is recessive in the remote frame.
Interframe space Start of frame Remote frame Interframe space or overload frame arbitration Control field field CRC field ACK field End of frame
Error Frame
This frame consists of two fields.
The first field is given by the superposition of error flags contributed from different nodes. The second field is the error delimiter.
Error frame
Overload Frame
Consists of two bit fields: overload flag and overload delimiter Three different overload conditions lead to the transmission of the overload frame:
Internal conditions of a receiver require a delay of the next data frame or remote frame. At least one node detects a dominant bit during intermission. A CAN node samples a dominant bit at the eighth bit (i.e., the last bit) of an error delimiter or overload delimiter.
Format of the overload frame is shown in Figure 13.9. The overload flag consists of six dominant bits. The overload delimiter consists of eight recessive bits.
End of frame or Error demiliter or Overload delimiter Overload flag Superposition of overload flags Figure 13.9 Overload frame Overload frame Overload delimiter Interframe space or Overload frame
Interframe Space (1 of 2)
Data frames and remote frames are separated from preceding frames by the interframe space. Overload frames and error frames are not preceded by an interframe space (higher priority)
Frame
Interframe space
Frame
Intermission
bus idle
Interframe Space (2 of 2)
The intermission subfield consists of three recessive bits. During intermission no node is allowed to start transmission of the data frame or remote frame. The period of bus idle may be of arbitrary length. After an error-passive node has transmitted a frame, it sends eight recessive bits following intermission (lower priority), before starting to transmit a new message or recognizing the bus as idle.
Interframe space Suspend Transmission Frame Bus Idle
Frame Intermission
Errors (1 of 3)
Error handling
CAN recognizes five types of errors.
Bit error
A node that is sending a bit on the bus also monitors the bus. When the bit value monitored is different from the bit value being sent, the node interprets the situation as an error. There are two exceptions to this rule:
A node that sends a recessive bit during the stuffed bit-stream of the arbitration field or during the ACK slot detects a dominant bit. A transmitter that sends a passive-error flag detects a dominant bit.
Errors (2 of 3)
Stuff error
Six consecutive dominant or six consecutive recessive levels occurs in a message field.
CRC error
CRC sequence in the transmitted message consists of the result of the CRC calculation by the transmitter. The receiver recalculates the CRC sequence using the same method but resulted in a different value. This is detected as a CRC error.
Errors (3 of 3)
Form error
Detected when a fixed-form bit field contains one or more illegal bits
Acknowledgement error
Detected whenever the transmitter does not monitor a dominant bit in the ACK slot
Error Signaling
A node that detects an error condition and signals the error by transmitting an error flag
An error-active node will transmit an active-error flag. An error-passive node will transmit a passive-error flag.
Fault Confinement
A node may be in one of the three states: error-active, errorpassive, and bus-off. A node keeps count of receive and transmit errors (REC, TEC) An error-active node will transmit an active-error frame (dominant) when detecting an error. An error-passive node will transmit a passive-error frame (recessive) when detecting an error. A bus-off node is not allowed to take part in bus communication.