1 / 53

MegaMeet 2007

MegaMeet 2007. CAN C ontroller A rea N etwork Bowling & Grippo. Quick CAN Overview. Understanding CAN . Simple Serial Communications Protocol Variable Bit Rate: 5 Kbps up to 1 Mbps Un-limited node (limited to max. Electric load and time delay)

nessa
Download Presentation

MegaMeet 2007

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MegaMeet 2007

  2. CANController Area NetworkBowling & Grippo

  3. Quick CAN Overview

  4. Understanding CAN • Simple Serial Communications Protocol • Variable Bit Rate: 5 Kbps up to 1 Mbps • Un-limited node (limited to max. Electric load and time delay) • Multi-Master (any node may initiate transmit any frame) • Multi-cast (any node may receive all messages) • CSMA/CD standard (Carrier Sense, Multiple Access & Collision Detect) • Prioritization of messages via identifier • Fault confinement (determine permanent failures then shut off node) • Automatic re-transmission of corrupted message • High level of error detection

  5. Requirements of a CAN Controller • Simple user interface to CPU • Access control & status registers • Access to buffers • Interrupt and error types Microcontroller Message filtering + buffering CAN Transmit Receive Engine CPU Interface • Message filtering & buffering • Store incoming & outgoing messages • Only interrupt CPU w/ relevant messages • Predictable Message Transmission • Protocol handling • Error Detection • Arbitration detection • Bit monitoring/stuffing • Physical layer interface • Current & voltage control for bus • Absorb transients • Signal bus (line) faults & correct Control + status Physical interface CANH TX RX CAN bus H/W Errors CANL

  6. CAN Terminology • CAN 2.0 - Robert Bosch CAN Specification, Revision 2.0 • CAN 2.0 A - Formerly CAN 1.2, limited to 11-bit identifiers • CAN 2.0 B - Usually means complete protocol standard - Including 11-bit and 29-bit identifiers - Should read CAN 2.0 A/B • “Full-CAN” - Hardware implementation having at least 16 message buffers - Means nothing about compliance to CAN 2.0 A/B standard • MSCANxx - Freescale Scalable CAN hardware implementation (HC08, HC12, HCS12 families) • TOUCAN - “Full-CAN” Freescale CAN hardware implementation (M*CORE, PowerPC families) • FLEXCAN - Similar to, but larger version of TouCAN

  7. CAN Node/MessageStructure

  8. OSI Layers APPLICATION PRESENTATION SESSION TRANSPORT OSEK COM/NM, Vector Driver S/W NETWORK DATA LINK msCAN,TouCAN PHYSICAL CAN-B, CAN-C Transceivers CAN – Node Structure • CAN Protocol • Data Link Layer • Logical Link Control (LLC) sub-layer • Acceptance Filtering • Overload Notification • Recovery Management • Medium Access Control (MAC) sub-layer • Data Encapsulation/Decapsulation • Frame Coding (Bit Stuffing/Unstuffing) • Medium Access Management • Error Detection/Signaling • Acknowledgement • Serialization/Dserialization Physical Layer • Bit Encoding/Decoding • Bit Timing • Synchronization

  9. CAN Message Transfer • Information sent in fixed format message frames. • Any node may start to transmit when bus is free (Bus Idle). • If two or more nodes start transmitting in same frame, bus access conflict is resolved by bit-wise arbitration. • Highest priority message wins bus access. • Arbitration Field (identifier) determines the message priority. • Transmitting nodes which lose arbitration become receivers and automatically re-transmit at next available time. • No data or time wasted, someone always wins.

  10. CAN Message Transfer (Cont.) • All nodes check consistency of messages received and will flag an inconsistent message to the entire network. • All receiving nodes acknowledge a valid message. • A message is received correctly by all nodes or no nodes. • All nodes apply Message Filtering to decide whether to accept a message. • Any number of nodes can simultaneously receive and accept a message (Multicast transmission). • ID - Labels message contents (no physical node addresses).

  11. CAN – Message Types • Data Frame: • (“Hi Everyone, I am sending data to Labeled X”) • Remote Frame: • (“Hi Everyone, If you are Labeled Y; please send me data”) • Error Frame: • (“Everyone STOP!!!, Let’s try it again”) • Overload Frame: • (“I am busy Labeled Z, please wait until I am free”)

  12. CAN – Data Frame recessive IFS Control Field 6-bits CRC Field 16-bits SOF 1-bit Arbitration Field 11-bits (Std ID) 29-bits (Ext ID) Data Field 0-8 bytes ACK 2-bits EOF 7-bits IFS or Bus Idle dominant Bit Stuffing • A node is allowed to start transmitting a Data Frame after Inter-Frame Space(IFS) • The two complementary bus values are called dominant and recessive • All receivers synchronize to leading edge of Start Of Frame(SOF) • Arbitration Field is 11-bits for a Standard Format Data Frame (CAN2.0A/B) • Arbitration Field is 29-bits for a Extended Format Data Frame (CAN2.0B only) • Bit Stuffing • whenever 5 consecutive bits of equal value are transmitted, 1 extra bit of complementary value is automatically inserted into the bit stream: provides edges for clock resynchronization. Receivers automatically de-stuff

  13. CAN – Remote Frame recessive IFS Arbitration Field 11-bits (Std ID) 29-bits (Ext ID) SOF 1-bit ACK 2-bits EOF 7-bits CRC Field 16-bits Control Field 6-bits IFS or Bus Idle dominant Bit Stuffing • A node is allowed to start transmitting a Remote Transmission Request (RTR) Frame after Inter-Frame Space (IFS) • Similar to a Data Frame, but no Data Field • Interpreted as a request for data that is associated with the Identifier in the Arbitration Field • Seldom used by automotive manufacture

  14. recessive Active Error Flag 6-Bits Echo Error Flag <= 6-Bits Echo Delimiter 8-bits Intermission 3-bits Data Frame Or RTR Frame dominant CAN – Error Frame (Active) • Error Frame = Error Flag + Error Delimiter • 2 types of Error Flag: (ActiveError Flag and PassiveError Flag) • Active Error Flags : • Transmitted when error detected by an Error Active node • Consists of 6 dominant bits (overwrite other bits on bus) • Breaks rule of Bit Stuffing or destroy the ACK field or EOF field • Consequently, all other nodes detect an error, and transmit own Error Flag, (and no nodes receive the original message) • Number of dominant bits monitored on the bus can vary between 6 and 12.

  15. CAN – Error Frame (Passive) recessive Passive Error Flag 6 Bits Echo Error Flag <= 6-Bits Echo Delimiter 8-bits Intermission 3-bits Data Frame Or RTR Frame dominant • Passive Error Flags : • Transmitted when error detected by an Error Passive node • Consists of 6 dominant bits (do not overwrite other bits on bus) • Complete when the Error Passive node has received 6 consecutive bits of equal value, beginning from start of Passive Error Flag • Passive Error Frame Delimiter consists of 8 recessive bits.

  16. CAN – Overload Frame recessive Overload Flag 6-Bits Overload Delimiter 8-bits EOF or Error Delimiter or Overload Delimiter Echo Error Flag dominant • Overload Frame transmitted when any of following are detected: • Dominant bit during the 1st or 2nd bit of Intermission • Dominant bit during the 7th bit of the end-of-frame (EOF) field in receive frames. • Dominant bit during the 8th (last) bit of Error Delimiter or Overload Delimiter • Receiver permitted to initiate an Overload Frame when not ready to receive new data (not usually implemented) • Maximum of 2 Consecutive Overload Frames may be generated

  17. CAN – Standard Frame Format

  18. CAN- Extended Frame Format

  19. CAN PHY Transmission Standard • Three automotive PHY standards: • High Speed Differential Interfaces (ISO 11898-2, SAE J2284) • Up to 1 Mbps differential • Linear bus topology • Silicon solutions to common mode noise issues • Two-Wire Fault-tolerant interfaces (ISO 11898-3) • Automatically switch to single wire reception when fault detected • Limited to 125 kbps due to propagation delays • Flexible topology: bus, star, ring • Single Wire Interfaces (SAE J2411) • Based on J1850-VPW technology with enhanced wakeup capability • Limited to 33.33 kbps due to propagation delays • Flexible topology: bus, star, ring

  20. Vcc TX RX Gnd CAN Standard – High Speed • CAN-C (J2284) • Linear bus topology • 500 kbps bit rate • 30 m max bus length • Maximum of 16 nodes CANH 3.5 V 2.5 V CANL 1.5 V recessive dominant recessive ECU 2 ECU n . . . Stubs < 1 m RT 120Ω ECU 1 RT 120Ω Twisted-pair media CANH CANL

  21. Vcc CANH 3.5 V CANL 1.5 V 0 V recessive recessive dominant CAN Standard – Fault Tolerant • Flexible bus topology • <=125 kbps bit rate • Auto-switch to Single-ended • Receive on Bus fault • 40 m max bus length • Maximum of 32 nodes Vcc RL TX ECU 2 ECU n RX . . . RH ECU 1 Gnd Twisted-pair media CANH CANL

  22. VBatt Wakeup signal level 4.1V CANH 0V recessive dominant recessive CAN Standard – Single Wire • Flexible bus topology • 33.33 kbps bit rate • High Voltage Wakeup • 40 m Max bus length • Max of 32 nodes VBatt Tx Rx ECU 2 ECU n . . . RT VBatt LOG ECU 1 Gnd Twisted-pair media CANH

  23. CAN Physical Interfaces

  24. CAN Bit Timing BIT TIME SYNC_SEG PROP_SEG PHASE_SEG1 PHASE_SEG2 Transmit Point Sample Point SYNC_SEG: The bit edge is expected to lie within this segment. PROP_SEG: Allowance for physical delays. PHASE_SEG1 & PHASE_SEG2: Define the position of the Sample Point. May be adjusted to compensate for edge phase errors. SAMPLE POINT:The bus value at this point is taken as the value of the bit (if 3 samples per bit taken, this is position of 3rd sample).

  25. CAN Bit Timing BIT TIME =SYNC_SEG+PROP_SEG+PHASE_SEG1+PHASE_SEG2 SYNC_SEG = Always 1 time quantum (CAN clock period) PROP_SEG = 1- 8 time quanta (programmable) PROP_SEG >= 2 x  (bus propagation delay + input comparator delay + output driver delay) PHASE_SEG1 = 1- 8 time quanta (programmable) PHASE_SEG2 = greater of PHASE_SEG1 and INFORMATION PROCESSING TIME … where INFORMATION PROCESSING TIME <= 2 time quanta

  26. CAN Bit Timing Examples Example 1 Desired Bit Rate = 1 Mbps CAN Clock = 10 MHz Delay of driver = 30 ns Delay of receiver = 50 ns Delay of bus line (40 m) = 220 ns  Total propagation delay = 300 ns Time quantum = 100 ns Bit Time = 10 tq SYNC_SEG = 1 tq PROP_SEG = 6 tq (min) PHASE_SEG1 = 1 tq PHASE_SEG2 = 2 tq SJW = 1 tq Sample Point at 80% of bit time (Target for 1 Mbps should be around 80-85%)

  27. CAN Bit Timing Examples Example 2 Bit Rate = 125 kbps CAN Clock = 2 MHz Delay of driver = 50 ns Delay of receiver = 70 ns Delay of bus line (40 m) = 220 ns Total propagation delay = 340 ns Time quantum = 500ns Bit Time = 16 tq SYNC_SEG = 1 tq PROP_SEG = 3 tq (min) PHASE_SEG1 = 6 tq PHASE_SEG2 = 6 tq SJW = 4 tq Sample Point at 75% of bit time (Target for 125kpbs should be around 75-80%)

  28. If edge lies within: Sample Point SYNC_SEG PROP_SEG PHASE_SEG1 PHASE_SEG2 Phase Error = 0 Phase Error > 0 Phase Error < 0(for next bit) CAN Synchronization • Hard Synchronization is performed at the leading edge of SOF: SYNC_SEG begins with this edge. • All other recessive to dominant edges will be used for Resynchronization.(Exception: Transmitter will not resynchronize to edge with positive phase error) • In Resynchronization, PHASE_SEG1 may be lengthened or PHASE_SEG2 may be shortened • Resynchronization Jump Width = maximum lengthening or shortening allowed • Resynchronization Jump Width = 1 - 4 time quanta (programmable ) Maximum = time quanta in PHASE_SEG1

  29. Edge appears here... Edge should be here... Edge appears here... Edge should be here... PHASE_SEG2 shortened PHASE_SEG1 lengthened CAN Synchronization r CAN bus d Receiver bit timing S PS P1 P2 S PS P1 PS P2 S PS P1 P2 S PS P1 P2 P2 S P1 Sample points BIT 2 BIT 3 BIT 4 BIT 5 BIT 1 S = SYNC_SEG PS =PROP_SEG P1 =PHASE_SEG1 P2 = PHASE_SEG2 Bit 3 Negative Phase Error Bit 5 Positive Phase Error

  30. CAN Oscillator Tolerance • Oscillator tolerance is set by the requirement to remain synchronized between recessive to dominant edges. • | F - Fn | • dF = ———— • Fn • Fn = nominal CAN clock freq. F = actual CAN clock freq. • Requirement 1: correctly sample the first bit after sending active error flag after a stuff error. • Min (tP_SEG1, tP_SEG2) • dF < — —————————— • 2 x (13 x tBitTime - tP_SEG2) • Requirement 2: synchronize correctly in the stuffed part of the bit stream. • tSJW • dF < —————————— • 2 x (10 x tBitTime)

  31. Example 1 1 Mbps Bit Time = 10 tq SYNC_SEG = 1 tq PROP_SEG = 6 tq PHASE_SEG1 = 1 tq PHASE_SEG2 = 2 tq SJW = 1 tq Requirement 1 dF < 0.39% over 12.8-Bit Times (12.8 ms) Requirement 2 dF < 0.50% over 10.0-Bit Times (10 ms) CAN Oscillator Tolerance - Examples • Example 2 125 kbps • Bit Time = 16 tq • SYNC_SEG = 1 tq • PROP_SEG = 3 tq • PHASE_SEG1 = 6 tq • PHASE_SEG2 = 6 tq • SJW = 4 tq • Requirement 1 • dF < 1.48% over 12.6-Bit Times (101 ms) • Requirement 2 • dF < 1.25% over 10-Bit Times (80 ms)

  32. Priority Register Priority Register Priority Register MSCAN Module CPU Interface (Memory Mapped I/O) msCAN Receive / Transmit Engine TX Buffer 0 Internal Priority Scheduling TX Buffer 1 Global Identifier Filtering: 2 x 32-bit TX Buffer 2 or 4 x 16-bit or 8 x 8-bit RX Buffer RX Buffer

  33. MSCAN12 Module • Implementation of the CAN protocol - Version CAN 2.0A/B • Standard and extended data frames • 0 - 8 bytes data length • programmable bit rate up to 1 MBit/s • Double buffered receive storage system • Triple buffered transmit storage scheme with internal prioritization using “local priority” concept • Flexible maskable identifier filters • Programmable wake-up functionality with integrated low-pass filter • Programmable loop-back mode supports self-test • Separate signaling and interrupt capabilities for all CAN receiver and transmitter error states • Programmable clock source (PLL or oscillator) • Programmable link to on-chip timer module for time stamping or network synchronization • Low-power sleep mode

  34. MegaSquirt CAN Message

  35. MegaSquirt-II CAN Message • Description of the CAN message format used in MS-II • CAN Bus target data rate of 500 Kb/s. • Target Packet period – 5ms maximum. • One Master Node – MS-II. • Multiple Peripheral Nodes. • Any node can transmit/receive to any other node. • MS-II uses Extended Frame Format (29 bits)

  36. Variable Offset Message Type MsgSenderID MsgDestID VariableBlock Spare ID28 ID27 ID26 ID25 ID24 ID23 ID22 ID21 ID20 ID19 ID18 ID17 ID16 ID15 ID14 ID13 ID12 ID11 ID10 ID9 ID8 ID7 ID6 ID5 ID4 ID3 ID2 ID1 ID0 MegaSquirt-II CAN Message • MS-II CAN Message Format: The CAN Message is an Extended Frame (29 bit) format containing: • Variable Offset • Message Type • Message Sender ID • Message Destination ID • Variable Block ID

  37. MegaSquirt-II CAN Variable Blocks • Variable Block ID: • Used to identify structures or tables in a device from or to which it is desired to get/ send data • Occupies “Identifier 3” block in Extended Frame CAN Message • Block ID is 4 bits, allowing up to 16 blocks per device • Variable Offset: • Used to define offset into MS-II block (which is defined in Variable_Block_ID) • Occupies “Identifier 0,1” blocks in Extended Frame CAN Message • Offset is 11 bits, range up to 2048 bytes

  38. MegaSquirt-II CAN Message Type • Message Type: • In “Identifier 1” position in Extended Frame • Number definitions: 0 = CMD: Tells destination to place Data Length Register (DLR) data bytes in this message into the variable block ID specified in message header, starting at variable byte offset. Used to push data from remote device into MS-II. This is a “push” operation from a peripheral to the MS-II. There is no acknowledge message returned.

  39. MegaSquirt-II CAN Message Type • Message Type – Number definitions (Con’t) 1 = REQ: This message requests the destination device to send back data from the Variable Block ID in the message header, starting at the variable byte offset. The DLR register is always set to 3: the first payload data byte is the variable block to store the return message (see below) ; the second and third are the offset into this block and no. of bytes – this data is reflected in the header of the returned data. Sending this message from a peripheral to MS-II will trigger a response message (type 2 = RSP).

  40. MegaSquirt-II CAN Message Type • Message Type – Number definitions (Con’t) 2 = RSP: This is the response record to a REQ record request. 3 = XSUB: This is for future use, it will allow the trigger a subroutine/function on a destination device. 4 = BURN: This triggers the receiving device to issue a flash program operation.

  41. MegaSquirt-II CAN Sender/Dest ID • Sender and Destination ID: • All devices on the MS CAN network must have a unique CAN ID number. This number defines the Sender and Destination ID. • By default, the engine controller board (MS-II) is defined as ID zero. • Each ID is defined ahead of time before joining the CAN network.

  42. Other MS-II CAN Parameters • Other CAN-specific bits that are included in message header: • SRR = 1 • IDE = 1 • RTR = set to 1 if no data is being sent (same as DLR empty) • DLR is Data Length Register, defines how many bytes are transmitted in CAN frame (up to 8)

  43. Other MS-II CAN Parameters • CAN Data rate is 500 KBPS • 16 Time Quanta (including Sync Seg) • Tseg1 = 13 • Tseg2 = 2 • Sync Jump Width (SJW) = 4 • Note – often these numbers are entered in registers as one less (I.e. 0 to n-1).

  44. CAN Message Header Format bit 7 bit 6 bit 5 bit4 bit 3 bit 2 bit 1 bit 0 ID28 ID27 ID26 ID25 ID24 ID23 ID22 ID21 IDR0 High 8 bits of Variable Offset ID20 ID19 ID18 RTR / SRR IDE ID17 ID16 ID15 IDR1 Low 3 Variable Offset 1 Message Type 1 ID14 ID13 ID12 ID11 ID10 ID9 ID8 ID7 IDR2 DeviceID (Sender) DeviceID (Receiver) ID6 ID5 ID4 ID3 ID2 ID1 ID0 RTR IDR3 Variable Block ID Spare 1

  45. MS-II Acceptance Filtering • A CAN network with multiple nodes will most likely carry a lot of messages. • For any given message, each CAN node has to determine if this message is intended for them: • They (node) can decode every CAN message and see if the message was addresses to them – if so then proceed further, else discard. –Or- • Use front-end acceptance filters which only allow messages matching a user-defined bit pattern to pass to the MSCAN module.

  46. MS-II Acceptance Filtering • The acceptance filters compare each bit in each field, and can either allow any bit value (0 or 1) to match, or can be set to force a specific bit value match. • There are two registers for each bit match: • Acceptance filter register (AR name suffix) holds the bit pattern to check against the message. • Acceptance mask register (MR name suffix) indicates whether the corresponding bit position is actually checked (set to 0) or ignored (set to 1). • The combination of the AR and MR registers indicate the actual acceptance filter.

  47. MS-II Acceptance Filtering • Acceptance Register 0 0 0 1 1 1 1 0 (0x1E) • Mask Register 1 1 0 0 0 1 0 1 (0x3A) • Resulting Filter X X 0 1 1 X 1 X • Identifier 1 0 1 0 1 1 1 1 1 (accepted) • Identifier 2 1 0 0 1 1 0 1 0 (accepted) • Identifier 3 1 0 0 0 1 0 1 0 (rejected)

  48. MS-II Acceptance Filtering • Any peripheral on the MS-II CAN bus should set the acceptance filter mask to filter on the destination ID matching the peripheral mask.

  49. MS-II Acceptance Filtering Acceptance Filter and Mask for Destination ID =3 bit 7 bit 6 bit 5 bit4 bit 3 bit 2 bit 1 bit 0 ID28 ID27 ID26 ID25 ID24 ID23 ID22 ID21 IDAR0 IDMR0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 ID20 ID19 ID18 RTR / SRR IDE ID17 ID16 ID15 IDAR1 IDMR1 0 0 0 1 1 0 0 0 1 1 1 1 1 1 1 1 ID14 ID13 ID12 ID11 ID10 ID9 ID8 ID7 IDAR2 IDMR2 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 ID6 ID5 ID4 ID3 ID2 ID1 ID0 RTR IDAR3 IDMR3 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1

  50. MS-II CAN Example • Here is an example of a MS-II CAN peripheral: • Peripheral wants to obtain RPM from MS-II. • Peripheral ID is 1. • Peripheral wants to send a single packet (REQ = 1 Message Type) and receive RPM in return packet (type = 2, RSP).

More Related