can bus theory solution

23
2/8/2016 1 MSCS-667: Industrial Automation Systems Abu Sayed Md. Mostafizur Rahaman Associate Professor Department of Computer Science and Engineering Jahangirnagar University Lecture Today CAN Bus Sample Exercise

Upload: md-mashiur-rahman

Post on 19-Feb-2017

342 views

Category:

Education


0 download

TRANSCRIPT

Page 1: can bus theory solution

2/8/2016

1

MSCS-667: Industrial Automation Systems

Abu Sayed Md. Mostafizur RahamanAssociate Professor

Department of Computer Science and Engineering

Jahangirnagar University

Lecture Today

• CAN Bus

• Sample Exercise

Page 2: can bus theory solution

2/8/2016

2

CAN (Controller Area Network)

• Definition

– CAN (Controller Area Network) is a serial bus system used to communicate betweenseveral embedded 8-bit and 16-bit microcontrollers.

– It was originally designed for use in the automotive industry but is used today in manyother systems (e.g. home appliances and industrial machines).

– Highest Baud Rate is 1Mbit.

– CAN uses a message oriented transmission protocol.

CAN (Cont…)

• Developed by– Robert Bosch GmbH in the 1980s.

• Application Area– Automotive sectors.

• Reason for developing:– Increasing share of controller and automating technology– lively data exchange

• i.e. a high number of communication process but only small data packets

• Advantages– Minimization of wiring effort– High error safety– Small latency time– Distributed systems, several receiver– Good extensibility– Priorization of messages– Lower-cost

Page 3: can bus theory solution

2/8/2016

3

Arbitration Process

• Bus level

– Dominant and the Recessive level

– Dominant level means logic 0 and theRecessive level means logic 1

Overview ISO / OSI Layer Model

• Physical layer– Serial data transmission in a bus topology.

• MAC Layer:– Protocol (CSMA/CA)

• Each participant that wants to send listens

• if the bus is occupied ( carrier sense) and starts the sending process whenthe bus was idle for a certain time.

• There is the possibility that several participants start to send at the sametime ( multiple access).

• The resolving of an eventually appearing collision is carried out as part ofthe arbitration process.

• Hereby all the affected participants start by putting their frames (startingwith the identifier) bit by bit on the bus.

• After each bit the sender checks if the actual level on the bus correspondswith the level that it applied on the bus. If not it stops sendingimmediately.

• This results that message with the highest priority gains the bus accesswithout the destruction of the message (collision avoidance).

Out of the 7 layers, only the blue colored ones ( 1, 2, and 7 )are considered for field busses

Page 4: can bus theory solution

2/8/2016

4

LLC- Logical Link Control

• The communication on the bus is based on four different frame formats:

– Data Frame

– Remote Frame

– Error Frame

– Overload Frame

LLC- Logical Link Control (Frame format)

Data Frame

• Start of Frame: 1 dominant bit to identify start

• Arbitration field: 11 bit identifier + 1 bit RTR (remote transmission

request bit)

• Control field: 2 bits reserved for extended CAN, 4 bits for data

length

• Data field: 0-8 byte of data possible, starting with MSB

• CRC-field: 15 bit + 1 recessive CRC delimiter bit

• ACK-field: 1 bit ACK-slot + 1 bit ACK delimiter (recessive):

transmitter sends recessive bit in the slot; recipients that received

error free,send a dominant bit in the slot.

• End of Frame: 7 bit

Data frame format

In total the minimum frame length results in 44 bits. Additionally are the 0-64 data bits and potentially stuff bits.

Page 5: can bus theory solution

2/8/2016

5

LLC- Logical Link Control (Frame format)

• Remote Frame– A participant of the bus uses the remote frame to trigger the sending of a special data frame

with the same identifier by a data source.– Data frame and remote frame only differ in a varying RTR bit ( RTR bit of remote frame =1,

RTR bit for data frame=0 )

• Error Frame– If a participant of the bus recognizes an erroneous frame ( e.g. wrong checksum in CRC field),

it reports this by sending an error frame.– Therefore a sequence ( 6 bits with the same polarity) that isn’t permissible during normal

operation is switched on the bus.– This implicates that all the other ( fully functional node) switch themselves an error frame on

the bus as the bit stuffing rule was violated. An error frame is terminated with 8 recessive bits.

• Overload Frame– An overload frame is used to enlarge the spacing between two frames.– It can only be send at the beginning of the spacing.

Safety Mechanisms

• In order to reduce the fault liability of the CAN bus the following safetymechanisms are realized:

• Bit Monitoring

– Each transmitting network node monitors whether or not the bus level it hastransmitted is actually present on the bus. Otherwise a fault has appeared that has to bedissolved or the sending process has to be terminated (arbitration phase).

• Frame Format Check

– As the frame format is fixed, every participant of the bus can check whether thisformat is maintained ( e.g. recessive delimiter bits). Otherwise a fault is existent.

Page 6: can bus theory solution

2/8/2016

6

Safety Mechanisms

• Bit-Stuffing

– The CAN protocol uses the NRZ bit coding ( non-return to zero).

– This means that there are longer phases without bit edges for synchronization.

– To avoid this an inverted stuff bit is set after 5 bits of the same polarity. This bitpermits the synchronization of every node and is deleted when received.

• Cyclic Redundancy Check (CRC)

– The transmitted message is secured again by CRC. Thereby the message is divided bya special polynomial generator and the result is deposit in the CRC field. The messageis divided again by this polynomial generator by the receiver and the result iscompared with the transmitted CRC field. If there are not identical a transmissionerror has appeared. (polynomial generator x15+x14+x10+x8+x7+x4+x3+1

CRC (Cont…)

• It should be clear by now that a major goal in designing error detectionalgorithms is to maximize the probability of detecting errors using only asmall number of redundant bits. Cyclic redundancy checks use some fairlypowerful mathematics to achieve this goal.

• For example, an 8-bit message consisting of the bits 10011010 correspondsto the polynomial,

• M(x) = 1×x7 +0×x6 + 0×x5 +1×x4 + 1×x3 + 0×x2 +1×x1 + 0×x0

= x7 +x4 + x3 +x1

Page 7: can bus theory solution

2/8/2016

7

CRC (Cont…)

• We wanted to create a polynomial T(x) for transmission that is derived fromthe original message M(x), is k bits longer than M(x), and is exactly divisibleby G(x).

• We can do this in the following way:1. Multiply M(x) by xk, that is, add k zeros at the end of the message. Call this zero-extended message xk

M(x).

2. Divide xk M(x) by G(x) and find the remainder R(x).

3. Subtract the remainder from xk M(x) to get T(x).

It should be obvious that what is left at this point is a message that is exactly divisible byG(x).

Example-1

Page 8: can bus theory solution

2/8/2016

8

Sample Exercise

The CAN-specification does not restrict the number of bus nodes, the length of the bussystem and the maximum baud rate. Nevertheless, the bus length or the maximum baud rate,respectively, is limited in a real bus system.

a) Give the correlation between the baud rate and the maximum bus length. Assume asimplified bit-timing-model. What is the maximum bus length of a CAN bus system if abaud rate of 500kbit/s shall be achieved? The signal propagation velocity is vSig =0.2m/ns (signal propagation velocity on a two-wire line) and the delay time caused bythe signal processing is 100ns.

Solution

Page 9: can bus theory solution

2/8/2016

9

• Three nodes start at the same time to write messages on the bus with theidentifiers 204 (hex), 208(hex) and 287(hex).

a) Write down the identifiers in binary notation. Take possible safety mechanisms intoaccount.

Answer:204(hex) = 516(dec) = 010000010100 (bin) (Stuff-Bit)

208(hex) = 520(dec) = 010000011000 (bin) (Stuff-Bit)

287(hex) = 647(dec) = 01010000111 (bin)

b) Which message will prevail in the arbitration process? Why (give reasons)?

Answer:

The message with the identifier 204 will assert it elf since it has the lowest identifier and with that the

highest priority (zero-level is dominant).

c) Carry out the arbitration process step by step. At which time, do the nodes with thelower priority stop their transmission? Which signal level results on the bus?

Answer:

Page 10: can bus theory solution

2/8/2016

10

Exercise

The control of the power train of a new car requires four controllers to exchange safetycritical data. Motor controller and gearbox controller exchange data cyclically with a periodof 20 ms.

ABS-controller and motor controller exchange cyclically safety critical data with a period of

10 ms. Additionally, motor controller, gearbox controller, and ABS-controller shall send

acyclic data of variable length to the central diagnosis device.

Which one of the bus systems CAN, FlexRay, Profibus, or EtherCat is suited for the

interconnection of all four controllers? Explain for each bus system why it is suited or

unsuited!

Exercise: Solution

• FlexRay: best suited. It’s time triggered and allows deterministictransmission of safety critical cyclic data and asynchronous data as well.

• Profibus: Master-Slave-communication Single-Point of failure

– No deterministic cycle time

– Not suited

• EtherCat: Special hardware required rather expensive

• CAN: suited, but CSMA-CA not deterministic

Page 11: can bus theory solution

2/8/2016

11

Sample Questions:

1. Define CAN bus. Give the reason of developing of CAN bus.

2. List some application of CAN bus.

3. Describe the protocol used in CAN bus to MAC layer.

4. Give the bus level used in CAN bus with an example.

5. Describe briefly the data frame format used in CAN bus.

6. Define remote frame, error Frame and overload frame used in CAN bus.

7. Describe briefly the safety mechanism techniques used in CAN bus.

8. Describe CRC technique with an example.

Exercise

• CAN-Bus (approx. 35 min)

In an automation-project of an office building you have the task to engineer thefield bus. A CAN-bus is to be used. The office building consists of 7 floors(including ground floor) with 14 offices each. The building automation systemis responsible for the climate control, fire monitoring, and lighting control.Figure 1 shows the layout of a floor of the office building.

Page 12: can bus theory solution

2/8/2016

12

The following requirements have to be considered:

• In each office a CAN node exist. The CAN node is connected with a smoke detector, atemperature sensor, a light sensor, and a climate control unit to set the room temperature.The coordination and control is realized through a central automation computer.

• The central automation computer should be able to query explicitly every sensor andactuator in every room.

• In order to provide maximum safety, messages that come from the smoke detectors shallhave a higher priority than all other messages.

The sensor and actuator layout of an office is shown in Figure 2.

Page 13: can bus theory solution

2/8/2016

13

1. Bus Configuration

In the first step, the basic parameters of the bus system are to be determined.

Question 2.1: Transmission Rate

The length of the bus cable is 1480 m.

What is the maximum possible transmission rate?

You may assume a simplified bit timing model. The signal propagation velocity is Vsig =0.2 m/ns and the delay time caused by the signal processing is 100 ns.

Question 2.2: Message Transfer Time

The maximum message transfer time shall not exceed 1.25 ms. You may assume a maximum

message length of 80 Bit. Can this be realized with the maximum transmission rate? Justifyyour answer with a calculation.

Page 14: can bus theory solution

2/8/2016

14

Solution 2.1 & 2.2

2. Message Format

In the second step, the actual CAN messages are to be specified. The message identifier andthe respective data parts have to be defined.

Hint: Use binary representation!

Question 2.3: Message Coding

Each message to be transmitted shall contain the message type, the floor number, and theoffice number.

a) Which messages must be distinguished in the system?

b) How do you define the encoding of message identifiers, taking message priorities intoaccount? Give a schematic definition of the message identifiers and justify your decision.

c) Give for each message occurring in the system an example with appropriate coding of themessage identifier.

Page 15: can bus theory solution

2/8/2016

15

Solution 2.3

b) As any sensor/actuator is to be addressed individually, the coding has to bedone within the identifier Considering the higher priority of fire alarmmessages, the definition of the Identifiers is as follows:

Page 16: can bus theory solution

2/8/2016

16

Question 2.4: Data Coding

The MEASURED-temperature values of a temperature sensor are measured in an interval of

0° C to 100° C with an accuracy of 0.1° C and sent to the central automation computer on demand. The SET-temperature values of the climate control unit are provided in an interval of 5° C to 30° C with a resolution of0.1° C. The smoke detector reports only the status (1 - smoke / 0 - no smoke). The MEASURED-light valuesof a light sensor are measured in an interval of 0 lx to 10000 lx with an accuracy of 1 lx and sent to the centralautomation computer on demand.

a) What is the minimum size of the required data part of the respective CAN messages in

bytes?

b) Write down the respective data parts of the minimum and maximum values. You do not

need to apply any safety mechanisms.

Question 2.5: Safety Mechanisms

Write down the message identifier and the data part for the message that represents a MEASURED-light valueof 2727 in office No. 13 in the 4th floor. Apply CAN-specific safety mechanisms where necessary. Explainbriefly your result.

Solution 2.4

• MEASURED Temperature:

Interval from 0°C-100°C with accuracy 0.1°C => 1000 values

Coding of 1000 values => 10bit => 2 Data byte necessary

Coding: binary 0 = 00000000 00000000 = 0°C (without Stuffing-Bit)

binary 1000 = 00000011 11101000 = 100°C (without Stuffing-Bit)

• SET-Temperature:

– Interval from 5°C - 30°C with accuracy 0.1°C => 250 values

– Coding of 250 values => 8 bit => 1 Data byte necessary

– Coding: binary 0 = 00000000 = 5°C

– binary 250 = 11111010 = 30°C

Page 17: can bus theory solution

2/8/2016

17

• Fire alarm:

– 1 Status bit => 1 bit => 1 Data byte!

– Coding:

– 0_0_0_0_0_0_0_Status bit

• MEASURED-light:

– Interval from 0 – 10000 with accuracy 1 => 10000 values

– Coding of 10,000 values => 14 bit => 2 Data byte necessary

– Coding: binary 0 = 00000000 00000000 = 0°lx (without Stuffing-Bit)

– binary 10000 = 00100111 00010000 = 10000°lx (without Stuffing-Bit)

Page 18: can bus theory solution

2/8/2016

18

Exercise: Home Automation

In this question we deal with ambient intelligence, which is a new trend in controlling theliving environment with respect to the human users. The plan shown in figure 3.1 shows thetop view of a house. The house is equipped with a CAN-Bus which can be used to connectvarious devices together. One of the Bus members is an industrial PC (IPC), which has theresponsibility of coordination. It can also be used for manual inputs to the system by theusers. Your task as an automation engineer is conception of a CAN-Bus network to fulfillthe following requirements:

• Blind control: The blind is connected to the CAN-Bus via the PLC of question 2. Hereonly the state of the two sensors (wind, light) are being sent to the IPC in one message.

• Radiator: There are 5 radiators placed in each room (except for the corridor andbalcony). The radiator sends the current temperature of the room to the IPC and receivesthe desired temperature via the IPC.

• Fire Detector/sprinkler: In order to fight back against fire, “Fire Detectors” (Sensor)and “sprinklers” (actuator) for detecting the fire and extinguishing it are used in pairs.Each room contains one pair of fire detector/sprinkler, summing up to a total amount of 6pairs. As soon as a fire is detected (fire detector activated), an alarm message is sent tothe IPC. The IPC, then, sends an activation message to the corresponding sprinkler.

• Air-Conditioning system: Altogether, there are 3 AC systems in the house. One in thebedroom, one in the working office, and one in the living room. It sends the current roomtemperature to the IPC and receives the desired temperature via the IPC. Furthermore, itcan explicitly be turned on/off from the IPC.

• Security system: The security system is being considered here as a black box. Its onlyrelevant action for us is to send an alarm message to the IPC in case of security issues.

Page 19: can bus theory solution

2/8/2016

19

• Industrial-PC: The IPC implements a user interface for communicationbetween the CAN-Network and the user; it presents information about theconnected devices to the CAN-Bus and allows interaction with them.Furthermore, if a message from one of the Bus members affects another Busmember, this has to be sent first to the IPC and via the IPC to thecorresponding component.

Page 20: can bus theory solution

2/8/2016

20

Question 3.1: CAN-Node architecture

Design a suitable bus topology (arrangement of the nodes) that realizes the requirements ofthe house. Mention all your CAN nodes.

Question 3.2: CAN-Messages

Identify the messages that are necessary to communicate between different node. Writedown for each node which message(s) are being sent or received by it. Combine messages ofequal type to one message.

Question 3.3: Message-Identifiers

For the purpose of addressing various nodes on the CAN-Bus System, you have been givenan address range from 300(hex) to 400(hex). Determine the message identifiers for themessages you have detected in 3.2. Take into account the realistic requirements on thesystem.

Question 3.4: Baud rate

The length of the CAN-Bus System is 40m. Calculate the maximum baud rate of the Bus.Consider the signal propagation velocity is 0.2m/ns and electrical switching time 200ns.

Question 3.5: Extension to the security system

In case of an alarm from the security system, a picture taken from a camera installed in thehouse will be sent to the IPC through the CAN-Bus system. The size of the picture is 340kByte. Since the size of a standard CAN message is not sufficient for sending such a picture,it must be separated into several parts. Create a concept to efficiently encode the data parts.Consider the order of the part messages. Write down your concept and mention the requirednumber of CAN messages for transmitting one picture.

Page 21: can bus theory solution

2/8/2016

21

Exercise: Ship Accident

After the fatal Costa Concordia cruise ship accident, the junior engineers of the JahangirnagarUniversity have received the task to construct a new cruising ship, Costa Concordia v2.

Employing automation engineering techniques and highly modern technologies, the new cruisingship should provide her passengers more comfort and safety. Due to cost matters it must, first a smallprototype of the cruising ship should be constructed. If this fulfills the requirements, an order forconstructing the real cruising ship will be allotted. From now on the small prototype is meant,whenever Costa Concordia v2 is mentioned.

The Costa Concordia v2 consists of 7 floors with 14 cabins and a restaurant on each (see figure 1.1).The following decisions/requirements are to be considered in Costa Concordia v2:

• Each cabin and restaurant has a smoke detector, which in case of fire sends a signal to the centralcontrol unit. This signal causes a chain of alarms to go off. For more simplicity the chain ofalarms is considered as one alarm. Furthermore, simultaneous occurrence of two or more alarmsfrom different cabins or restaurants is ignored.

• In each cabin and restaurant there is a temperature sensor and a temperature selector installed. Thetemperature sensor sends the current temperature to the central control unit. Via the temperature selector aperson can set the desired temperature, manually. Once a person has set a desired temperature, it is sent tothe central control unit. Furthermore, the temperature can be set automatically by the central control unit,regardless of the selector.

• On the outside body of the cruising ship (under the water) a modern sonar unit (Sound Navigation andRanging Unit) is installed. The sonar unit can detect the underwater reefs, which might be hazardous for thecruising ship. In case such a reef is detected, a signal is sent to the central control unit.

• The central control unit should be able to access all the sensors/actors in each cabin or restaurant.

• In order to make the future passengers of Costa Concordia v2 always positively remember the juniorengineers of the University of Stuttgart a further comfort function should be included. Each cabin will havea cool box, which will be filled with German beer. An integrated sensor in the cool box detects how manybeer bottles are left. If the amount of beer bottles is not equal to the maximal capacity of the cool box, asignal is sent to the central control unit. This signal will from thereon be forwarded to the catering staff totake care of. The catering staff is not considered here.

Page 22: can bus theory solution

2/8/2016

22

The distribution of the sensor and actor elements of the cabins and restaurants, shown in figure 1.1, is the samefor each floor.

Question 1.1: CAN Baud Rate

The length of the bus system is 1590 m. What is the maximal possible baud rate? Assume that the signalpropagation velocity is v line) and the delay time caused by the signal processing is 100 ns.

Question 1.2: CAN Message Length

The maximal message transmission time should be 1.5 ms. How big is the maximal message size allowed tobe?

Question 1.3: CAN Identifier

Each transmitted message should include the type of the message, the floor number and the cabin number.Design an identification coding, which fulfills the above mentioned requirements. How would you choose yourcoding? Provide an example for each type of message.

Page 23: can bus theory solution

2/8/2016

23

The measured temperature values of the temperature sensors are measured in an interval of 0°C to 100°C withan accuracy of 0.1° and can be sent to the central control unit on demand. The desired temperature values,given via the temperature selectors, are provided in an interval of 5°C to 30°C with a resolution of 0.5°C. Thesmoke detectors, sonar unit and cool boxes send only the status (1 -smoke / 0 - no smoke), (1 - reef detected /0- no reef detected) and (1 cool box full- / 0 – cool box not full).

a) What is the minimum size of the required data part of each CAN message type in bits and bytes? Justifyyour answer.

b) Write down, in binary form, for each type of message the data field corresponding to the start value of themessage and the end value of that message. E.g. for the type of message “desired temperature” the binaryforms of the CAN messages 5°C and 30°C are requested.

Hint:

· Write down only those bytes, which are required for each data field.

· Ignore any CAN specific safety mechanisms.

Question 1.5: CAN Message Examples

Write down the message identifier and the data part for the message that represents themeasured temperature value of 25.6° C of the cabin number 14 on the 7th floor and themeasured temperature value of 12.8° C of the cabin number 1 on the 1th floor. Write youranswer in binary as it will appear on the bus. Apply CAN-specific safety mechanisms where

necessary.

Question 1.6: CAN Arbitration

The two temperature messages of the question 1.5 are put simultaneously on the bus. Which

message receives the bus access? Justify your answer. Sketch the arbitration process and thesending behavior of each CAN node. What appears on the bus?