`Control Area Network
`(CAN)
`
`18-540 Distributed Embedded Systems
`Philip Koopman
`October 4, 2000
`
`Required Reading:
`
`Schill, Overview of the CAN Protocol
`
`Most of the pictures in the lecture are from:
`CAN specification (Bosch)
`Overview to Can; Infineon
`DeviceNet materials -- http://www.odva.org/
`
`Page 1 of 32
`
`Mercedes Exhibit 1019
`
`
`
`Assignments
`u By next class read about Protocol building Blocks:
`• Review protocol survey paper from this week
`(I haven’t found papers that directly address this topic)
`
`u Dates to remember:
`• Project Part #3: due in one week on Wednesday 10/11
`• HW #5 due at 4 PM on Friday 10/13
`
`Page 2 of 32
`
`
`
`Where Are We Now?
`u Where we’ve been:
`• Protocol Overview
`
`u Where we’re going today:
`• CAN -- an important embedded
`protocol
`• Primarily automotive, but used in
`many places
`
`u Where we’re going next:
`• A building-block approach to
`protocols:
`– Custom protocols
`– Protocol performance analysis
`
`Page 3 of 32
`
`
`
`Preview
`u CAN – important automotive protocol
`• Physical layer
`• Protocol layer
`• Message filtering layer (with add-on protocols)
`
`u Keep an eye out for:
`• Message prioritization
`• How “small” nodes can be kept from overloading with received messages
`• Tradeoffs
`
`Page 4 of 32
`
`
`
`Before CAN
`
`Page 5 of 32
`
`
`
`With CAN
`
`Low Speed
`
`Page 6 of 32
`
`
`
`Generic CAN Propaganda Slide
`
`Page 7 of 32
`
`
`
`CAN & the Protocol Layers
`u CAN only standardizes the lower layers
`u Other high-level protocols are used for application layer
`• User defined
`• Other standards
`
`Page 8 of 32
`
`
`
`Physical Layer Possibilities
`u MUST support bit dominance (discussed later)
`u Specifically rules out transformer coupling for high-noise applications
`• But, cars are high-noise, right????
`• Differential drive and optical fibers help in most cases, but not all
`
`Page 9 of 32
`
`
`
`Bit Dominance
`u Wired “Or” design
`• (Called “open collector logic” before TTL/tristate was invented…)
`• Bus floats high unless a transmitter pulls it low
`
`Page 10 of 32
`
`
`
`Generic CAN Network Implementation
`
`Page 11 of 32
`
`
`
`Basic Bit Encoding - NRZ
`u NRZ = Non-Return-To_Zero
`• Fewer transitions (on average) = less EMI, but requires less oscillator drift
`
`• Bit stuffing relaxes oscillator drift requirements
`
`Page 12 of 32
`
`
`
`Another Look at Bit Stuffing
`u Five identical bits in a row triggers an inverted Stuff Bit
`• Bit de-stuffer must take it back out on the receiving end…
`• [This picture is slightly wrong -- it is 5 bits in source stream, not counting
`stuff bits…]
`
`Page 13 of 32
`
`
`
`Generic Message Format
`
`u Header
`• Routing information (source, destination)
`• Global priority information (which message gets on bus first?)
`
`u Data
`• Application- or high-level-standard defined data fields
`• Often only 1-8 bytes
`
`u Error detection
`• Detects corrupted data (e.g., using a CRC)
`• Embedded networks can have very high bit error rates
`
`Page 14 of 32
`
`
`
`CAN Message Format
`u What’s inside the message?
`
`• “Arbitration Field” = “Message ID”
`
`Page 15 of 32
`
`
`
`Binary Countdown (Bit Dominance)
`
`1 0 1
`
`1 0 0
`
`Node 5
`
`Node 4
`
`u Operation
`• Each node is assigned a unique identification number
`• All nodes wishing to transmit compete for the channel by transmitting a binary
`signal based on their identification value
`• A node drops out the competition if it detects a dominant state while
`transmitting a passive state
`• Thus, the node with the highest identification value wins
`
`u Examples
`• CAN, SAE J1850
`
`Page 16 of 32
`
`
`
`More Detailed Arbitration Example
`
`Page 17 of 32
`
`
`
`Two Sizes of CAN Arbitration Fields
`
`Page 18 of 32
`
`
`
`Arbitration Limits Network Size
`u Need 2*tpd per bit maximum speed
`
`Page 19 of 32
`
`
`
`SAE Message Classes
`u Fast tends to correlate with critical control
`• But, this is not always true; just often true
`
`Page 20 of 32
`
`
`
`Basic CAN Controller (Don’t Use This One)
`u “Cheap” node
`• Could get over-run with messages even if it didn’t need them
`
`Page 21 of 32
`
`
`
`Full CAN Controller
`u Hardware message filters sort & filter messages without interrupting
`CPU
`
`Page 22 of 32
`
`
`
`Mask Registers
`u Used to set up message filters
`• Mask register selects bits to examine
`• Object Arbitration register selects bits that must match to be accepted
`
`Page 23 of 32
`
`
`
`Various Special Messages
`u Various error messages
`
`u Remote Frames –atomic request for data / provide data
`• (Not used in most in cars)
`
`Page 24 of 32
`
`
`
`DeviceNet
`u One of several higher-level protocols
`• Based on top of CAN
`• Used for industrial control (valves, motor starters, display panels, …)
`– Caterpillar is a member of ODVA as well (Open DeviceNet Vendors Assn.), but for
`factory automation.
`
`u Basic ideas:
`• CAN is used in high volumes = cheaper network chips than competitors
`• Use structured approach to message formats to standardize operation
`
`u Does NOT standardize specific message contents
`• But it does specify a hierarchy of message ID formats
`
`Page 25 of 32
`
`
`
`DeviceNet Message ID Scheme
`
`Message Identifier Bits
`4
`3
`9
`8
`7
`6
`2
`1
`5
`Message ID
`Source Node #
`Msg ID
`Source Node #
`Source Node #
`Msg ID (0..6)
`1
`1
`1
`Message ID (0..2f)
`1
`1
`1
`1
`X
`X
`X
`
`10
`
`1
`1
`
`0
`
`X
`
`Hex Range Identity Usage
`000 - 3ff
`Group 1
`400 - 5ff
`Group 2
`600 - 7bf
`Group 3
`7c0 - 7ef
`Group 4
`7f0 - 7ff
`Invalid
`
`1
`
`10
`
`0 1 1 1
`
`10
`
`Page 26 of 32
`
`
`
`DeviceNet Group Strategy
`u Group 1
`• Prioritized by Message ID / Node number
`• High priority messages with fairness to nodes
`
`u Group 2
`• Prioritized by Node number / Message ID
`• Gives nodes priority
`
`u Group 3
`• Essentially same as Group 1, but allows Group 2 to have higher priority
`
`u Group 4
`• Global housekeeping messages / must be unique in system (no node number)
`
`Page 27 of 32
`
`
`
`Other Approaches Are Possible
`u And, you can invent your own too…
`
`u Variations include:
`• Automatic assignment of node numbers (include hot-swap)
`• Automatic assignment of message numbers (include hot-swap)
`• Mixes of node-based vs. message-ID based headers
`
`Page 28 of 32
`
`
`
`CAN Workloads – Spreadsheets
`u “SAE Standard Workload” (53 messages) V/C = Vehicle Controller
`
`Page 29 of 32
`
`
`
`Why Use An Embedded Network
`u Potential Advantages (for CAN?)
`• Reduces wires and increases reliability
`• Lowers weight, size, and installation costs
`• Logical choice for physically distributed systems
`• Allows sharing of system resources
`• Increases system capability and flexibility
`• Self-configuration, self-installation, and advanced diagnostics
`• Foundation for system integration and automation
`• Integrated, modular product line leads to interoperability
`
`u Potential Network Drawbacks (for CAN?)
`• May initially increase product cost
`• Requires knowledge and new skills in networking
`• Requires special tools for fault detection
`
`Page 30 of 32
`
`
`
`CAN Tradeoffs
`u Advantages
`• High throughput under light loads
`• Local and global prioritization possible
`• Arbitration is part of the message - low overhead
`
`u Disadvantages
`• Propagation delay limits bus length (2 tpd bit length)
`• Unfair access - node with a high priority can "hog" the network
`– Can be reduced in severity with Message + Node # prioritization
`• Poor latency for low priority nodes
`– Starvation is possible
`
`u Optimized for:
`• Moderately large number of message types
`• Arbitration overhead is constant
`• Global prioritization (but limited mechanisms for fairness)
`
`Page 31 of 32
`
`
`
`Review
`u Controller Area Network
`• Binary-countdown arbitration
`• Standard used in automotive & industrial control
`
`u CAN Tradeoffs
`• Good at global priority (but difficult to be “fair”)
`• Efficient use of bandwidth
`• Requires bit-dominance in physical layer
`• Message filters are required to keep small nodes from being overloaded
`– (But, these are easy to implement)
`
`u Next lecture: Protocol building blocks (custom protocols)
`
`Page 32 of 32