Advanced Embedded Systems Design
Download
Report
Transcript Advanced Embedded Systems Design
Advanced Embedded Systems Design
Lecture 10 Controller Area Networks
BAE 5030 - 003
Fall 2004
Instructor: Marvin Stone
Biosystems and Agricultural Engineering
Oklahoma State University
Goals for Class Today
•
•
•
•
•
Questions over reading / homework (Chapters 23, 24)
USB from a developers prospective – (Patrick)
SPI and I2C – (Brody)
Controller Area Networks introduction – (Stone)
Set assignment
Communications busses for embedded systems
(A very abridged list!)
•
•
LIN
On-board busses (inter-IC busses)
–
–
–
–
•
•
Automotive
–
–
–
SPI
I2C
Microwire
1-Wire
•
–
MODBUS
•
•
–
–
–
Fieldbus
Bitbus
CAN
•
•
•
–
RS485
Ethernet
DeviceNet
SDS
CiA
Proprietary
•
•
RS 485
CAN
–
•
MOST
MIL-STD-1553
ARINC 429
Marine
–
–
•
ByteFlight
FlexRay
TTP / TTCAN
Avionics
–
–
•
SAE J1939 / ISO 11783
Fault tolerant busses
•
•
•
Industrial
–
SAE J1850
SAE J1708 / 1587
CAN based
NMEA 0183
NMEA 2000 (IEC 61162-3 )
Ethernet
–
–
Ethernet
IEEE
•
•
•
803.2 – Further defined ethernet
803.11 – wireless LAN
802.15.4 – Zigbee
CAN – Controller Area Network - Introduction
• History
– Developed by Bosch in mid 1980’s to meet a need for networking
ECUs (electronic control units in automobiles)
– Initially introduced with an 11-bit message identifier (CAN 1.0 –
1.2), later a 29 bit identifier introduced (CAN 2.0)
• Now:
– 11 bit only parts: CAN 1.2 (Also CAN2.0A)
» 2048 different CAN messages
– 11 bit compatible with 29 bit messages: CAN 2.0B 29 bit passive
– xmit and receive 11 and 29 bit ID: CAN 2.0B
» 536 million CAN messages
– CAN has since been heavily adopted
• ~350 million protocol controllers sold in 2003 (Bosch / CiA)
• Broad industrial support
– Automotive
» J2284 / IDB-C 500 - kBaud automotive physical and data link
» J1939 – Heavy duty vehicle physical/data link/network/app layer
» Proprietary
– Industrial
» DeviceNet – Industrial physical/data link/network layers
» SDS - Industrial physical/data link/network layers
» Proprietary
– See: http://www.can-cia.de/can/protocol/history/history.html
CAN Overview
– CAN = Controller Area Network
• Serial data communications protocol for real-time application
using a multiple access bus
– Messages have assignable priority
» most critical can dominate during heavy load
– Messages are short (controlled length)
» opportunities to insert a new message come often
– Asynchronous serial communications
– Serial bus vs. point-to-point
» Reduction in wiring complexity
» Better information sharing
– Low probability of an undetected error
• 4.7 x 10-11 x message error rate
– For a message error rate of 25/sec:
1 undetected error per 10,000 hours operation
Capacity Comparison
Logarithmic
10,000K
Capacity (bits/sec.)
250K
56K
V.90 Modem ISO 11783
Ethernet
10base2
Capacity and Performance
• Use of bus bandwidth @250 kBaud by messages
– 100 messages per second (10 ms repetition) =5%
• Torque/Speed control on engine
• Hitch control
– 10 messages per second (100 ms repetition) =0.5%
• Throttle position
• GPS Lat/Lon data
• Implement application rate control (process data)
– 1 message per second (1s repetition) =0.05%
• Display updates
• System status
Message latency
• 134 bit message @250 kBaud (bit stuffing ignored)
– @ 4 ms per bit = 536 ms = 0.5 ms per message max
• Highest priority message
– must wait no more than ~0.5 ms
• Low priority messages
– must wait till higher priority messages clear
– latency may be long at high bus loads
Conventional Wiring (No Bus)
Sensors
ECUs
Serial
Communication
Links
Nozzles
NOZZLE
ECU
Data
Logging
GPS
A Simple CAN Application (Serial Bus)
Nozzles
Sensors
ECUs
NOZZLE
ECU
Data Bus
Data Bus
Data
Logging
GPS
CAN - Introduction
• Network structure
– Intended as a bus, but other physical implementations are
possible
– Limitations – No “Tee’s”
An overview of CAN based networking
• CAN - Elements
– CSMA/CA
• Bitwize priority access strategy
– Uses distributed synchronization of bit timing
• Non-destructive collisions
– Message components
• Identifier / Data
–
–
–
–
Bus Access - Arbitration / Prioritization
Error Detection / Error Confinement
Filtering
Other features
• In Frame Acknowledgement
• RTR
• Message structure
– Message frame contains:
•
•
•
•
•
11/29 bit Identifier
Data length
0-8 bytes data
CRC
In-frame acknowledgement
CAN Frame Format - CAN 2.0B
B. CAN Extended Frame Format
CAN Extended Data Frame
Maximum frame length with bit stuffing = 150 bits
Control
Field
6 Bits
Arbitration Field
32 Bits
Bits
S
O
F
1
Identifier
S
R
R
I
D
E
Identifier
Ext.
R
T
R
r
1
r
0
11
1
1
18
1
1
1
Bit Stuffing
Data
Field
CRC
Delimiter
DLC Data Field CRC
4
0 - 64
15
1
ACK
Field
E
O
F
2
7
No Bit
Stuffing
Typical ECU Components
Power
Conditioning
Micro-Controller
CAN
Protocol
Controller
Memory
Interface
I/O
CAN
Bus
Driver
ECU Connection to the bus
Power
Conditioning
Micro-Controller
ECU 1
CAN
Protocol
Controller
CAN
Bus
Driver
Power
Conditioning
CAN_H
ECU 2
Micro-Controller
CAN
Protocol
Controller
Memory
Interface
I/O
CAN
Bus
Driver
CAN_L
Memory
Interface
I/O
TBC_PWR
CAN_H
Terminator
CAN_L
TBC_RTN
Terminator
Physical network structure
ECU 1
ECU 2
ECU 3
Message
Message
Message
Message
Communications Bus
Message Components
Message
11 bits or 29 bits
(up to 150 bits)
0 to 8 bytes (0 to 64 bits)
Identifier
Start
Data
Serial bit stream
CAN Arbitration
VCAN_H
Vdiff
VCAN_L
recessive
dominant
ISO 11878
recessive
Identifier (29 bits)
Data (8 bytes)
ECU 1 1 0 1 1 0 0 0 1 1 1 ... 1 0 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 ...
ECU 2 1 0 1 1 1 ECU 2 ceases transmission
and prepares to resend later
Bus
Result 1 0 1 1 0 0 0 1 1 1 ... 1 0 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 ...
Arbitration Field
NO Arbitration
Lower numbered identifiers assume higher priority
Bit time control – Length of a single bit
Nominal Bit Time
Sync_Seg
Prop_Seg
Phase_Seg1
Time Quantum (tq)
Phase_Seg2
Sample
Point
• Bit must arrive a destination before phase_seg1
begins. Sampling at receiver will occur within the
phase segment.
• Prop_seg. should accommodate total out and back
propagation time plus delay in tranceivers
CAN synchronization / bit timing
•
Definitions:
– Synchronization segment (Sync_Seg) - that part of the bit time where bit
edges are expected to occur
– Propagation segment (Prop_Seg) - intended to compensate for the physical
delay times
– Phase segment (Phase_seg1, Phase_seg2) – Provide control of the sample
point position
– Synchronization Jump Width (SJW) defines how far a resynchronization
may move the Sample Point inside the limits defined by the Phase Buffer
Segments to compensate for edge phase errors.
•
Synchronization
– Hard synchronization will be done to align bits at the beginning of a
message.
– Phase_seg1 is lengthened or phase_seg2 is shortened to minimize phase
error by up to the synchronization jump width (SJW). Larger phase errors
cannot be compensated for.
•
See: http://www.can.bosch.com/docu/CiA99Paper.pdf
Physical Layer
• Many physical layer definitions
– Most ISO 11898 based
• Maximum number of ECU's
– Typical 30 (per segment)
• Typical Media
– Twisted shielded pair
• 120 W nominal impedance
• Two data lines (CAN_H, CAN_L)
• One shield
– Twisted Quad un-shielded
• 75 W nominal impedance
• Two data lines (CAN_H, CAN_L)
• Two termination supply lines
• Signal
– Compatable with ISO 11898 drivers (eg. Phillips 80C250)
ISO 11898 Bus levels – Microchip AN 228
Mapping of CAN to the OSI – Microchip AN 228
• Characteristics of CAN - CAN provides Data Link functions
Application Layer
Presentation Layer
Presentation Layer
Session Layer
Session Layer
Transport Layer
Network Layer
CAN
Data Link Layer
Physical Layer
ISO 7498
Application Layer
Transport Layer
Network Layer
CAN
Data Link Layer
Physical Layer
Network Management
Network Management
To form a complete communications system
Message Filtering - Example
Accept if:
(ID AND MASK) XOR MATCH = 0
10111100100 IDENTIFIER
11100000000
1 = Care, 0= Don’t Care
MASK
10100000000 = ID AND MASK
10100000000
00000000000 =
MATCH
Pattern must match
(ID AND MASK) XOR MATCH
Error Detection
• 5 Error Types Detected
–
–
–
–
–
Bit Error (Sent bit doesn’t match monitored bit)
Stuff Error (more than 6 successive in one state)
CRC error
Form Error
Acknowledge Error
• Probability of an undetected error
– 4.7 x 10-11 x message error rate
• for a message error rate of 25/sec,
1 undetected error per 10,000 hours operation
Assignment
• Install the Pont time triggered scheduler in hardware
and toggle the RED/GREEN LED at 1 per sec.
• Read Pont, Chapter 25, 28
• Tutorial – 30 min
– Review SAE J1708, SAE J1850, SAE J1939
– or
– Review DeviceNET and SDS