35
CH13_CAN_d12.shw ELEC-H410/ 13 : CAN 30-01-14 17 :57:18 © beams 1 Chapter 13 CAN Control Area Network ELEC-H410 REAL-TIME SYSTEMS 2

Chapter 13 CAN Control Area Network

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

1

Chapter 13

CANControl Area Network

ELEC-H410REAL-TIME SYSTEMS

2

Page 2: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

3

CAN

<CAN vs OSI<<<

CONTENTS

4

Page 3: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

5

CAN vs OSIOSI for WAN

application

présentation

session

transport

network

data link

physical

application

presentation

session

transport

network

data link

physical

7

6

5

4

3

2

1

7

6

5

4

3

2

1

protocol #7

protocol #6

protocol #5

protocol #4

network

data link

physical

network

data link

physical

node A node B

relay system

IMP IMP

APDU

PPDU

SPDU

TPDU

packet

frame

bit

Data

6

This figure recalls the complete 7-layers OSI model. Remember in particular:

- that there is a horizontal virtual communication between peer layers, communication which obeys a protocolspecific to this layer

- that the physical communication is vertical; each layer brings services to the upper one; each layerincreases the level of abstraction

- that the three lower layers relay the information what implies, in the wide-area networks, the passage byrelay machines (IMP), managed by the telecom operators in the case of Wide-Area Networks.

Page 4: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

7

CAN vs OSImodel for broadcast LAN without relays

application

presentation

session

transport

network

data link

physical

application

presentation

session

transport

network

data link

physical

7

6

5

4

3

2

1

7

6

5

4

3

2

1

protocol #7

protocol #6

protocol #5

protocol #4

node A node BAPDU

PPDU

SPDU

TPDU

packet

frame

bit

Data

protocol #3

protocol #2

protocol #1

8

In simple broadcast networks, IMP can be suppressed.

Page 5: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

9

CAN vs OSI3-layer simplified model for real-time network

application

data link

physical

application

data link

physical

7

2

1

7

2

1

protocol #7node A node B

APDU

frame

bit

Données

protocol #2

protocol#1

CAN

10

In the case of industrial networks (also called field busses) like CAN, the priority is given tothe efficiency; several operations (conversion, encoding, routing, invoicing) are useless because we are on ahomogeneous subnetwork.

The network is then reduced to its 3 principal layers. The standard CAN specifies only the two lowest layers#1 and #2.

Several layers #7 exist to provide an interface to the applications. They can be extremely reduced or veryelaborate, proprietary or standardized.

Page 6: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

11

CAN vs OSIZoom on layers #1 & #2: sublayers

application7

2

1

node A

medium

LLC : Logical Link Control

MAC : Medium Access Control

PLS : Physical SignallingPMA : Physical Medium AttachmentMDI : Medium Dependant Interface

protocol #1

protocol #2

CAN

12

Actually, the structure of the layers is more complex, each layer being itself divided into several sublayers,which we shall detail in the following slides.

Page 7: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

13

< LLC (Logical Link control)‚ acceptance filters‚ notification of overload‚ recovery after errors

< MAC (Medium Access Control)‚ framing‚ coding (stuffing/destuffing)‚ error detection/correction‚ error signalling‚ acknowledgement‚ // - series - // conversion

CAN vs OSIDetails of layers : #2 (Data Link)

14

Let us start from the top and examine layer #2; it breaks up into 2 classical sublayers:

- LLC (Logical Link control)• acceptance filtering: rejection of some received messages, which will not be propagated towards the

application, because they do not concern it• notification of overload: the receiver warns the transmitter that it is not ready to accept the current

flow• recovery after errors: procedure intended to manage the situations of error, and to warn the

application which will, P if possible continue to ensure its missionP go to a degraded mode of operationP in all the cases ensure the safety

- MAC (Medium Access Control)• framing: the data received from LLC are encapsulated in a frame(see further)• coding (stuffing/destuffing): the sequence of the bits is modified to improve bit detection• error detection/correction: the frame contains additional information to evaluate the quality of the

transmission and, if necessary, to detect and correct the errors• error signalling: if an error could not be corrected by a receiver, it should be notified to the transmitter,

so that a new transmission can be tried• acknowledgement: if data have been correctly received, the transmitter is also informed• // serial // conversion: the conversation between the network peripheral and the CPU is done in

parallel via the data bus, whereas the network carries serial data

Page 8: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

15

CAN

<< layer #1‚ medium‚ MDI (Medium Dependant Interface)‚ PMA (Physical Medium Attachment)‚ PLS (Physical Signalling)

<<

CONTENTS

16

Page 9: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

17

< PLS (Physical Signalling)‚ coding/decoding at bit level‚ bit timing‚ synchronization

< PMA (Physical Medium Attachment)‚ Driver/Receiver

< MDI (Medium Dependant Interface)‚ connectors‚ cables

CAN vs OSIDetails of layer #1 (Physical)

18

Lets go down to layer #1, separated into 3 sublayers:

PLS (Physical Signalling)coding/decoding at bit level: transformation of the logical bit into a signal electrically adapted to thetransmission linebit timing: management of a regular rate of emission of the bits ( bitrate)synchronization: sampling at the good moment in reception

PMA (Physical Medium Attachment)transceiver : amplifiers (here differential) for transmission/reception adapted to the transmission cable

MDI (Medium Dependant Interface)connectors and cables

Page 10: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

19

< medium‚ classical: coppers twisted pair

! STP Shielded Twisted Pair! UTP Unshielded Twisted Pair! optional optical insulation

‚ wireless (via encapsulation e.g. Bluetooth)< connectors

CAN: layer #1MDI (Medium Dependant Interface)

stub

PHOENIXDB-9

Mini-DIN

RJ-11

20

Let us restart this analysis of CAN layers from the bottom, i.e. with the medium.

CAN works normally on a twisted pair of copper wire (shielded or unshielded). The top right figure shows atraditional example of twisted pair shielded by a braid.

We shall see in a later slide that the nodes can be galvanically insulated from the network by usingoptocouplers.

Rare examples of wireless CAN are presented. Actually, CAN is encapsulated in another standard likeBluetooth or WiFi. The CAN frame is the "payload" in the frame of the wireless standard.

The figure also shows several types of connectors used for CAN:

- at left bottom the traditional DB9, presented here in a sealed version; the upstream and downstream cablesare joined within the connector. It is a wiring well-adapted to avoid reflexions due to the disturbances of thecharacteristic impedance by the derivations (stubs) (see hereunder)

- at medium bottom we find the system distribution box with derivation. This cabling is prone to reflections onthe stubs; to avoid them the edges of the signal have to be softened, hence the transmission speed has tobe reduced

- at right bottom, we find mini-DIN connectors like those used for keyboards and telephone connectors like RJ-11

Page 11: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

21

CAN : layer #1PMA (Physical Medium Attachment) = transceiver

CANCTL

:P

GNDCAN_H

CAN_L

+5V_CAN

CANCTL

:P

CANCTL

:P

MDI

PMA#1

limits common modeoptional : bus-powered

differentialtransmission

PLS

22

CAN uses a pair of wires called respectively CAN_H and CAN_L.

This pair is connected to each node by a pair of differential amplifiers (one for transmission, the other one forreception) grouped in the same case and called transceiver (= transmitter + receiver) and which constitutesthe PMA sublayer (Physical Medium Attachment) . The transceiver is connected to the node by two logicsignals labelled Tx (Transmit) and Rx (Receive).

The "transmission" direction is naturally defined from the node towards the network.

Wiring also comprises a network ground, which reduces the potential difference between nodes, if they arevery distant (about 1km max) and are fed by individual power-supply. This strongly reduces the commonmode and thus contributes to protect the inputs of the differential amplifiers.

Lastly, it is possible to ensure the power supply of the nodes (or simply of the transceivers in the case of anoptically isolated network) by an additional power wire (+5V_CAN).

Page 12: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

23

< hi-speed‚ 125 kbit/s to 1Mbit/s‚ 25 to 50 mA

< Etat HI‚ fixed par R1,R1‚ "recessive"

< Etat LO‚ fixed par MOSFET‚ "dominant"

< cables ‚ Zc = 120S‚ terminators

CAN: layer #1PMA (Physical Medium Attachment)

R1

GND

+5V

R1

R1

GND

+5V

R1

R1

GND

+5V

R1

R1

GND

+5V

R1

R1

GND

+5V

R1

R1

GND

+5V

R1

24

There are at least 5 types of electrical standards for the signals on CAN. We will present two of them.

The most frequent one corresponds to the standard ISO 11898-2 and is called CAN HiSpeed.

It allows flows up to 1 Mbps on a twisted pair whose characteristic impedance should be 120S; both ends ofthe cable of must be terminated by 120S resistors to avoid reflexion.

CAN functions with to a particular principle of recessive and dominant bits:

A simplified version of the transceiver output stage is shown on the figure. It includes symmetrical polarizationresistors R1 and transistors.

- when all the transistors are switched-off, CAN_H and CAN_L are at the same potential of 2.5V, fixed by R1.This state is called recessive and, by convention, represents the logic level "1"

- when the transistors are switched-on, CAN_H is pulled-up at least to 3.5V and wire CAN_L pulled-down toa potential at most equal to 1.5V. The difference of potential (CAN_H -CAN_L) is positive and higher than orequal to 2V. This state is called dominant and codes the logic level "0".

The denomination of the states (recessive and dominant) become obvious when we imagine that 2 nodeswant to impose a different state on the bus. Level "0" will dominate, since it is fixed by low-impedancetransistors whereas emitting a "1" means just let the wires float at the potential fixed by resistors R1.

Page 13: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

25

< low-speed‚ 125 kbit/s‚ 1mA

< HI‚ fixed par R1,R2‚ "recessive"

< LO‚ fixed by MOSFET‚ "dominant"

< more tolerant wiring

CAN: layer #1PMA (Physical Medium Attachment)

R1

GND

+5V

R2

R2

GND

+5V

R1

R1

GND

+5V

R2

R2

GND

+5V

R1

R1

GND

+5V

R2

R2

GND

+5V

R1

26

To be able to cable in a less rigorous way, we can use transceivers in conformity with the ISO11898-3standard or CAN Low-Speed.

The essential difference is the use of unsymmetrical polarization resistors R1&R2; their higher value reducesthe consumption.

The recessive state becomes

CAN_H - CAN_L = -1.5V

whereas with the dominant state

CAN_H - CAN_L = + 3V

The transmission speed is lower (< 125kBits/s) and the transitions times of the signals are longer, whichdecreases the problem of reflexions.

Page 14: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

27

CAN : couche #1PMA (Physical Medium Attachment)

opto-isolated version

28

On this schematic, we see a CAN peripheral 82527 (IC13) and the transceiver 82C250 (IC14), connectedthrough optocouplers allowing to isolate GND_CAN (the reference potential of the network) from DGND (thereference potential of the node).

The reception signal RxD coming from the transceiver feeds the input diode of a fast optocoupler, whoseinsulated output is connected to the Rx0 input of the 82527.

In the other direction, the Tx0 output of the 82527 feeds the input diode of a second optocouplor whoseinsulated output is connected to the TxD input of the transceiver.

A strap (HEADER2) allows to bring into service the 120S adaptation resistance, if the board is at the end ofthe line.

Page 15: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

29

CAN: layer #1PLS (Physical signalling): NRZ coding

CANCTL

:P

GNDCAN_H

CAN_L

+5V_CAN

MDI

PMA#1

PLS

CK

0 1 1 10 0

Tx Tbit

30

The last function of the #1 is the PLS (Physical Signalling) including the encoding of the bits and theirclocking.

These functions are provided by the CAN controller;- if the CAN controller is a separate peripheral it has got its own quartz oscillator- if it is an internal controller, it benefits from the CPU clock

Bit encoding is the most intuitive one: NRZ (Non Return to Zero), where the bits change state at the rising sideof the clock and keep their state during the whole bit time T bit.

To summarize, layer #1 comprises:- cables and connectors- transceivers- part of the CAN controller

Page 16: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

31

< problem: when to sample in reception‚ bitrate is known => correct frequency‚ adjust the phase to sample in the middle of the bits

! based on the transitions in the signal! more difficult synchro for long succession of same level

< solution‚ ethernet, FIP, .... : manchester coding‚ CAN : bit stuffing : if 5 identical bits, add a 6th

complementary bit (1st error detection in receiver)

CAN : layer #1PLS (Physical Signalling) : bit stuffing improves sync

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

1 2 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 1912 SS S

32

The PLS still performs a function of coding/decoding: the bit stuffing/destuffing.

This function is a consequence of the NRZ coding.

All the networks function on the principle of an asynchronous transmission, i.e. the clock is not transmitted.

Even if the baudrate is known a priori and can be created locally which high precision (relative error is 10 -4

with an ordinary quartz), it is still required to suitably fix the phase of this clock to sample as close as possibleto the middle of the bits.

Best codes are the RZ type (Return to Zero), among which the most famous is Manchester used for Ethernet.With such a code, there is always an edge (rising or falling) in the middle of the bit, which facilitates the phaselocking of the reception clock.

Unfortunately with the NRZ coding chosen by the designers of CAN, synchronization is more difficult,because the presence of edges is not guaranteed, since long series of consecutive 1 or 0 in the data are ofcourse possible.

A minimal occurrence of edges is obtained thanks to the bit stuffing: a suite of 5 consecutive bits of the samelogical level is completed by a bit at the complementary level.

At the receiver side, the destuffing logic is very simple: as soon as five identical bits are met, the following onemust be the complement- if the stuffing bit is present it is simply eliminated- if it's not the case, an error is reported by the receiver. This is one of the numerous error detection

mechanisms implemented in CAN, which is famous is this domain.

Page 17: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

33

< bit stuffing is less powerful than Manchester but‚ compensated by a very powerful oversampling

mechanism, with majority voting‚ proven reliability

< many parameters have to be fixed at boot time< more details: see CAN controller data sheet + CAN

specifications

CAN : layer #1PLS (Physical Signalling) : synchronisation

34

Page 18: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

35

CAN

<<< layer #2

‚ MAC! medium allocation CSMA/CA! speed/length compromise! error detection

‚!

!

!

<

CONTENTS

36

Page 19: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

37

CAN : layer #2MAC : CAN frame

SOF Start Of Frame

(11+1)bits 6bits 8..64bits 16bits 2b 7bits

arbitration

datacontrol

ACKCRC

EOF End Of Frame

idle or overload

38

We arrive at layer # 2, whose lower sublayer is of course the MAC (Medium Allocation Control).The whole layer #2 is carried out in hardware by the CAN controller.

The first task of MAC in transmission is to encapsulate the data coming from LLC in a frame, by adding apreamble (header) and a postamble (trailer) .

This figure shows the composition of a CAN frame:

- before the transmission, the bus is idle in a recessive state

- SOF (Start Of Frame) is marked by a dominant bit, like the Start Bit in RS-232

- the preamble includes# an arbitration field allowing to solve the conflicts between concurrent transmitters, by fixing the priority

of the frame (see further)# a control field

- the postamble includes# a CRC (for the detection and correction of errors)# an acknowledge ACK field so that any receiver can indicate the validity of the frame# EOF (Enf Of Frame)

The bus must remain idle (recessive state) for a minimum time (Inter Frame Gap) before the next frame canbe transmitted.

Page 20: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

39

< CSMA : ‚ Carrier Sense

! a node cannot start if current transmission running ‚ Multiple Access :

! multi-masters network! each node can take the initiative to transmit! collision cannot be avoided

< NDA : Non Destructive Arbitration‚ the collision always designates a winner‚ no waste of time‚ no loss of bandwidth

CAN : layer #2MAC CSMA/NDA

40

CAN belongs to the category of broadcast networks with multiple accesses, i.e. several nodes coulddecide to emit simultaneously.

The rules are then:

- a node cannot scramble a transmission in progress; a mechanism of detection of activity on the network(Carrier Sense) is always used

- all nodes willing to transmit use the same timer to measure the Inter Frame Gap, hence they will start theirtransmission simultaneously and a collision will occur. The solution is

- either to use a protocol to reduce the probability of collisions for future attempts to transmit, like inEthernet

- or to regulate the conflicts in the event of collision

A particularly elegant solution is used for CAN: the collision always produces a winner , whose emissioncan continue without losing time or bandwidth.

This mechanism relies on the recessive/dominant bits during the emission of the arbitration field in thepreamble to the frame.

Page 21: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

41

< transceiver : nodes listen to what they emits‚ bit-to-bit comparison‚ if a recessive bit is emitted and a dominant bit is read,

transmission is stopped‚ the winner is the node which emits the lowest arbitration field

(maximum of "0")

CAN : layer #2MAC CSMA/CA/NDA : arbitration elects a winner

Node 1

Node 2

Node 3

BUS

CTL10 9 8 7 6 5 4 3 2 1 0

RECEPTION

RECEPTION

recessivedominant

TRANSMISSrecessivedominantrecessivedominant

recessivedominant

42

This figure shows the transmission of 3 simultaneous frames by 3 nodes eager to speak.

After the Start Of Frame, each note transmits an arbitration field (11 bits in the version CAN2.0A, 29 bits inversion CAN2.0B)The arbitration field is in fact a unique identifying number (CAN_ID) for the CAN object to be transmitted inthe frame.

The the transceiver is able to listen to the cable during the transmission and to compare, for each bit of thearbitration, the value read and the value transmitted.The 0 being dominant, the node which reads 0 while it emits 1 loses the arbitration and immediately stops itstransmission. The node keeps listening, however, because the frame is perhaps in the list of objects it isprogrammed to receive.

On the figure, we see that node 1 loses the arbitration at bit 4. Nodes 2 and 3 remain in competition becausethey emit the same arbitration field. A last additional bit RTR (explained further) makes node 2 win.

The node which wins the cable is thus the one which emits the object which identifier is the lowest (because itcontains the most 0), or, in the event of equality, the node that transmits RTR=0.

De facto, the identification number CAN_ID thus represents a level of priority, the highest priority beingattributed to the object 0.

Page 22: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

43

< 11 bits ID10..ID0 = identification of an object‚ no concept of address‚ model publisher/subscriber (producer/consumer)

! each frame conveys only one object which # has got a single ID# has got only one publisher => ID indicates the publisher univocally

! all the subscribers can catch the data of the object at the same time< 2048 objects (theoretical), 2032 (authorized)

‚ no bit stuffing in arbitration‚ 7 recessive bits are forbidden in most significant bits (pattern reserved for

EOF)

CAN : layer #2MAC : arbitration field = unique CAN_ID

arbitration

44

CAN is an object-oriented network working in a publisher/subscriber (also call producer/consumer) mode.

An object generally represents a state variable of the system (e.g. the temperature of a fluid) which ismeasured by the publisher/producer node and broadcasted regularly on the network. All the nodes interestedby this object are subscribers/consumers which will simultaneously receive it.

An object is unique (two objects may not have the same CAN_ID) and has got only one producer (thenumber of consumers is not limited).The CAN_ID indicates thus univocally at the same time a variable and its producer.

In this model, it is not necessary to transmit any transmitter or receiver address. The address of thetransmitter is implicit (via the CAN_ID) and the transmission is always a broadcast.

The 11 bits of the CAN_ID allow in theory 2048 different objects. Actually, only 2032 are allowed, since somenumbers are prohibited. Indeed the 7 most significant bits cannot be recessive, because there is nobit stuffing during the arbitration and this sequence is reserved for the EOF.

Page 23: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

45

< 1 bit RTR (Remote Transmission Request)‚ RTR recessive => frame is a question

! from a subscriber to a producer! empty data field

‚ RTR dominant => normal data frame‚ arbitration: if, by chance, the answer comes

spontaneously from the producer at the same time asthe question, the answer has the priority

‚ allows to implement a bus arbiter (cf FIP,Foundation)

CAN : layer #2MAC : arbitration - bit RTR

arbitration

46

In addition to the 11 bits of the CAN_ID, the arbitration field is terminated by the RTR (Remote TransmissionRequest) bit.

In recessive state 1, RTR must be interpreted like a question mark. A "question" frame can thus be sent by aconsumer who wants to know the value of the object indicated by the CAN_ID. The data field is of courseempty.When receiving this "question", the publisher will respond automatically (in hardware). The RTR bit of the"answer" frame is 0 and the data field will provide the desired value to the consumer.

REM1 : bit RTR is included in the mechanism of arbitration; an "answer" frame thus takes precedence over a"question" carrying the same CAN_ID; it is logical, the consumer passes immediately in receiving mode andgets the answer immediately, which saves bandwidth.

REM2 : the RTR bit can be used to change the working mode of CAN by creating a bus arbiter (see FIP orFoundation Field Bus), whose role is to regularly produce the "question" frames, with a multi-cyclicscheduling.

Page 24: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

47

< arbitration based on a comparison of bits‚ all the nodes must be "in the same bit"‚ worst case: N1 et N2 at the two ends

! N1 start to transmit at t = 0! N2 start to transmit at t = Tprop-, (Carrier Sense is OK!)! N1 emits a recessive arbitration bit IDi! N2 emits a dominant arbitration bit IDi! N1 is only aware of it at t = 2Tprop - ,

‚ => 2.Tprop must be < Tbit‚ => longer cable => Tprop ü => Tbit has to ü

< example ‚ L << c.Tbit/2 => L<< 100m for Tbit=1:s (Lmax=40m)

CAN : layer #2arbitration and cable length => speed limit

48

This clever mechanism of arbitration however introduces a limit: all the nodes must be synchronized at bitlevel (the arbitration must compare at the same instant bits having the same weight). Unfortunately, the traveltime on the network introduces a delay which complicates this synchronization.

Like in Ethernet, the worst situation happens for two nodes N1 and N2 located at the two ends of the network.

- N1 starts to transmit at t=0 beginning by a SOF (Star_Of_Frame)- the Carrier Sense is intended to prevent N2 from transmitting if it sees activity on the cable. However if T prop

is the travel time on the network (approximately 200m/:s), N2 can start to emit at the latest at t=T prop-,because the Start_Of_Frame bit of N1 did not reach N2 yet.

- if N2 emits a dominant bit k whereas N1 emits a recessive bit k, N1 will only realize it T prop later.

In the worst case the time-shift between N1 and N2 is 2.T prop. To still be "in the same bit", it is thus necessarythat the duration of the bit is appreciably higher than 2.T prop.

The length of a CAN network is thus inversely proportional to the transmission speed. Here are thestandardized limits.

Bit rate length---------------------------------------

1 Mbit/s 40 m500 kbit/s 130 m250 kbit/s 270 m125 kbit/s 530 m100 kbit/s 620 m 50 kbit/s 1,3 km 20 kbit/s 3,3 km 10 kbit/s 6,7 km 5 kbit/s 10,0 km

Page 25: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

49

< R0,R1 : reserved (used for 29-bits ID)< DLC3..DLC0 data length [byte]

‚ provided by LLC with the data< data (="payload" = only useful parts)

‚ 0 to 8 bytes coming from LLC! 0 byte for RTR frame! 0 byte for a status (heartbeat) but 1 is better

‚ CAN is obviously designed for short messages

CAN : layer #2MAC : control field + data

arbitration control data 0..8b

50

The preamble is terminated by a control field. The first two bits are not used in the protocol CAN2.0A and areuseful only to indicate a 29-bit CAN_ID(CAN2.0B).

The next 4 bits code the number of bytes of the coming data (between 0 and 8 bytes). LLC provides an 8-bytes buffer where the application can write the data to be transmitted. Written bytes are not counted, itwould have no meaning since each byte is accessible individually and the application could wish to changeonly one of them.The length of the data must be configured by in a special register at boot time, or eachtime the length must be modified.

The frame can thus contain an empty data field which saves bandwidth. This happens only in two cases - "question" frames with RTR=1- status frames like "heartbeat" transmitted periodically to indicate that a node is "alive". It is however quite

rare, because adding 1 status byte in the data consumes few bandwidth and allows a much richer statuswith 256 states.

Taking into account the short length of the data field (8 bytes maximum), CAN is a network peculiarly suitedfor the exchanges of very short messages, compared to Ethernet (minimum 46 bytes).

Page 26: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

51

< CRC 15 bits‚ f(x) = polynomial made of (arbitration + control + data)‚ g(x)= generator polynomial‚ CRC = remainder of f(x) DIV g(x); computed in real-time

by hardware (shift registers)‚ Hamming distance = 6‚ P residual error CRC < 3.10-5

< recessive delimitor (1 bit)

CAN : layer #2MAC : CRC field controlling the integrity

arbitr. CRC : 15+1 bitdata ACK EOF

52

The role of the MAC layer is to reduce the transmission errors, CAN implements a classical CRC (CyclicRedundancy Check) to detect/correct errors in the frame.

The calculation of the remainder of the division of the received bits (preamble+data), considered as apolynomial f(x), by a generator polynomial g(x) is made in hardware progressively during reception. When theremainder is obtained, it is immediately compared with the remainder emitted in the CRC field.

The CRC is here in 15 bits and is terminated by a recessive delimiter.

The Hamming distance provided by this CRC is 6. The MAC layer will be able to detect errors up to 5 bits andcorrect errors up to 4 bits.

The residual probability of positive false (undetected errors) is 3.10 -5, which is regarded as good, butinsufficient for the safety applications. Other mechanisms of detection will be used simultaneously to furtherreduce this probability . (see next §)

Page 27: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

53

< ACK : 2 bits‚ bit 1

! the producer puts a recessive bit! if any receiving node finds a correct frame, it crushes ACK

by a dominant bit so that the producer is aware of the ACK‚ bit 2

! delimiter: always recessive< EOF

‚ 7 recessive bits‚ special because violates the bit stuffing

CAN : layer #2MAC : field ACK + EOF

arbitrage CRC : 15+1 bitdata

54

The postamble ends in an acknowledgement field (ACK) and an EOF (End of Frame) marker.

The ACK starts with a recessive emitted bit, which will be crushed to a dominant bit 0 by any receiver havingrecognized a correct frame. By this mechanism, the emitter, which sees thedominant bit knows that thetransmission is correct.The 2 nd bit is a simple delimiter, always recessive.

Finally, the EOF is a particular sequence, because it is made of 7 successive recessive bits without bitstuffing.

Page 28: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

55

< bit error‚ recessive bit transmitted/ dominant bit read => error (except in arbitration and ACK)

< bit stuffing error‚ 6 successive bits of the same value=> error (except in EOF)

< CRC error< error of delimitor in CRC or ACK

‚ must be recessive< ACK error

‚ dominant bit not detected in ACK< P residual error: 4.7e-11 reliable

CAN : layer #2MAC : powerful multimode error detection

56

Page 29: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

57

< CRC error => NACK< other errors during the frame: error frame

‚ can be detected by any node‚ this node emits an error flag: 6 dominant bits‚ every node sees an error (violation of bit stuffing)‚ every node sends an error flag => superposition‚ error delimiter: 8 recessive bits‚ normal operation after InterFrameGap‚ /!\ faulty node could block CAN => counters

CAN : layer #2MAC : error signalling by active error frame

data error flag6 bits

superposmax 6 bits

error delimiter8 bits

IFG3 bits

errorSOF

active error frame dominant

recessive

58

When a node detects an error, it must still announce it to the other nodes. Two mechanisms are implemented:

- if no error was detected during reception, but the CRC is incorrect, the incorrect frame is signalled by aNACK (i.e. by leaving the first recessive bit in the ACK field unchanged). The emitter is then warned that ithas to retry the transmission

- if an error is detected by any node during the emission (e.g. bit stuffing error), this node will stop thetransmitter immediately by - emitting an error flag composed of 6 dominant bits which will

• crush the current data, since they are dominant• violate the bit stuffing and hence provoke a bit stuffing error in every node (which propagates the error

to the whole network). All nodes will transmit and error flag and the superposition of those flags will addat most 6 dominant bits

- the error flag is completed by 8 recessive bits to form an error frame- a silence of 3 bits (the Inter Frame Gap) is respected before the normal operation of the bus

- the producer of the aborted frame will try to transmit it again, with the normal arbitration process

This mechanism has a danger: a node could have a failure and declare that all frames are incorrect; in thatcase the CAN bus would be completely blocked. A mechanism of error counting has been implemented toprevent this problem.

Page 30: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

59

< error counters‚ separated for emission and reception‚ complex rules for incrementation/decrementation‚ distinction between fugitive errors and repetitive errors (error rate

< 1frame/8frames do not increase the counters)‚ if errors are too frequent

! error passive state: passive error frames! BUS OFF: transceiver goes to HiZ

CAN : layer #2MAC : counters for error confinement

erroractive

errorpassive bus-off

soft reset + wait128x11 recessivebits

TEC>255

TEC<127REC<127

TEC>127REC>127

RESET

TEC=Transmit Error CounterREC=Receive Error Counter

60

The management of errors is completed by error counters. Each node counts errors in transmission in theTEC (Transmit Error Counter) and reception in the REC (Receive Error Counter).

The values of the counters determine the transitions in a state machine with 3 states. The rules to incrementand decrement the counters are rather complex and have been designed to separate repetitive and fugitiveerrors. Here is a basic version (omitting the various exceptions)

- when a receiver detects an error, its REC is incremented by 1- when a transmitter sends an Error Flag, its TEC is increased by 8 (1)

- after a successful transmission, TEC is decreased by 1 (2)

- after a successful reception, REC is decreased by 1

Rules (1) and (2) indicate that if the bus is subject to fugitive parasitic influence the counter will not to tend togrow if the error rate is inferior to 1frame/8.

- after reset, the normal state is "error active" meaning that the node is allowed to send active errorframes, and hence to interrupt any current transmission when it detects an error

- if any counter of a node reaches 128, the node passes to the "error passive" state; error frames becomepassive (see next slide) so that the node cannot block the bus any longer; in this state, the REC is no moreincremented and can only be decremented

- if errors persist and TEC overflows (>255) the state becomes "bus off" and the node disconnects itselffrom the bus (the output amplifier is put in high impedance); an interrupt request is send to the processor,since bus-off is a major accident.

- depending on the controller, the node will eventually come back from bus-off to the normal state if- the application performs a software reset of the controller and reloads the configuration registers; in this

case, the next condition also applies- the receiver sees at least 128 times a sequence of 11 recessive bits, meaning that at least 128 object

have been sent on the bus. This ensures that a faulty node cycling continuously in the state diagramleaves a minimum bandwidth to other nodes.

Page 31: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

61

< passive error state‚ error flag = 6 recessive bits‚ if the node is the producer

! transmission is stopped! every other nodes are warned because the bit

stuffing is violated‚ if the node is a receiver

! recessive flag has no influence! if no other node detect an error => OK

CAN : layer #2MAC : passive error frame

data error flag6 bits

superposmax 6 bits

error delimiter8 bits

IFG3 bits

errorSOF

passive error frame dominant

recessive

62

A node in "passive error" state emits a recessive error flag .

This flag being recessive, it won't have any influence on the system, except if the node is the currenttransmitter. In this case, the 7 recessive bits violate the bit stuffing and all active error nodes will emit anactive error flag.

Page 32: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

63

< a faulty frame is transmitted over and over againautomatically‚ until it is transmitted without error‚ or until the transmit error counter =128

< overload frame‚ when

! a dominant bit occurs in the Inter Frame Gap! a node is not ready to listen to the bus

‚ identical to active error frame (except that error countersare not incremented)

‚ max 2 consecutive frames/node

CAN : layer #2LLC : error recovery / overload

64

After the occurrence of an error, the transmitting node will automatically try to transmit again (with respect ofthe arbitration rules of course) until the frame is accepted without error.This cannot happen indefinitely. If the node passes in the "error passive" state, the trials are stopped. Amaximum of 128 trials is thus possible.

LLC also manages overload. This mechanism is normally reserved for nodes that, for internal reasons aretemporarily no more able to receive (buffer overflow, interruption,...). This node is authorized to emit amaximum of 2 overload frames when the Interframe Gap is finished. Those frames are identical to the activeerror frames (but error counters are not incremented). This delay is not spectacular (max 2x23 bits, i.e. 46:s@ 1Mbit/s).

Page 33: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

65

< without filtering‚ the CAN controller sends an IRQ each time a frame is

received‚ useful for a monitor (control room)

< with filtering! you can specify of which ID(or groups of ID) you wants to

be a consumer< how : mask on the ID

‚ mask_bitk = 0 => IDk is "don't care"‚ mask_bitk = 1 => IDk must correspond to that of the

register defining the ID which you want to consume

CAN : layer #2LLC : message filtering reduces CPU load

66

All the CAN controllers implement a filtering mechanism allowing a node to ignore an object which is notrelevant for it. This avoids interrupt requests to the CPU for which the ISR would anyway reject the object.

It is the LLC sublayer which is in charge of this selection by a set of registers corresponding to one or moremasks defining which bits must be regarded as significant for the choice of a CAN_ID or a family of CAN_ID.

Page 34: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

67

CAN

<<<‚

!

!

!

‚!

!

!

<Conclusions

CONTENTS

68

Page 35: Chapter 13 CAN Control Area Network

CH13_CAN_d12.shwELEC-H410/ 13 : CAN 30-01-14 17 :57:18

©

beams

69

< advantages‚ cheap‚ popular (400x106 nodes / year)‚ reliable‚ bandwidth never lost => good behaviour if loaded

< disadvantages‚ speed/length compromise‚ used only for short data‚ real-time: worst case latency depends on

! CAN_ID! frequency of higher priority message (<CAN_ID)! max lenght of a message

CANConclusions

70

The first specifications of CAN were written by BOSCH in 1986. Taking into account that about 400 millionsmicro-controllers with a CAN controller are sold each year, CAN is a real success story due to its numerousadvantages.

Of course, it is not a high-speed, high throughput network, and its length is limited.

CAN is much used in real-time applications, and hence subject to "schedulability analysis". It is deterministicin the sense that it is possible to compute a worst-case latency .The priority mechanism of CAN is based upon CAN_ID, so that the latency is different for each object andmust take into account - the length and frequency of transmission of all objects having a lower CAN_ID- the fact that no preemption of a frame is possible, i.e. the current frame will always be terminated, even if it

has a lower priority