CAN Technology
Initial Considerations
Dave Funk, Consultant, PHYTEC America – 06/17/1999, revised 05/12/2001
Like many things in the technology spectrum, CAN is an open technology that can be best thought of as the usual combination of (1) hardware devices, (2) interfacing methods, and (3) software control, for advanced serial communications. By placing an initial emphasis on the interface, as a mental pivot point, the other two considerations become easier to relate to, and to deal with their complexities. For those who are familiar with the standard 7-layer ISO/OSI model for Networking, the CAN Network is based on the same principle from the Applications Layer down to the Hardware Layer. It would also be well to remember that the difference between passive and intelligent systems, is that intelligent systems are "hardware controlled by software".
The two CAN protocol versions are "Standard" (11-bit ID) and "Extended" (29-bit ID).
Variations of CAN Network protocol:
- V2.0A Standard, 11-bit Message IDs (211 =2048 identifiers)
- V2.0B Extended, 29-bit Message IDs (229 .... identifiers)
Interfacing
- In RS-232C, RS-422, and even the CAN interface, there are
designated pin assignments and descriptions. Passing serial-data-elements
are of course the purpose of the interface.
- In the RS-232C interface, signal voltage levels are above or below 0V (typically +/- 9V to +/-12V) for each single-line.
- In RS-422, the signals are usually more of a "differential-mode" for noise rejection, using twisted-pair lines, unless the lines are re-configured for signal-to-ground reference.
- In CAN terminology, there are two bus-states, identified as "recessive" and "dominant". These two terms may be applied as a comparative state of signals for a twisted-pair-network, such as the normal RS-422 differential mode, or again as in comparison to the re-configured RS-422, using signal-to-ground voltage levels for a single-line network. In either electrical consideration, both use the same "recessive" or "dominant" terms. The "recessive" or "dominant" states (as terms) may be applied to the presence of signals on a fiber-network. It is more important to relate these two terms as they are used to describe data-bit signals, than to describe voltage levels.
- A couple of worthwhile comparisons is that where RS-232C uses either +V or -V voltage levels, that may fall within a wide range (+/- 3V to +/- 15V), the CAN voltage levels are always positive, either at +1.5V ("0") or at +3.5V ("1"). When fiber-optic cable is used, other considerations obviously apply.
- For a single-line CAN network, the +1.5V is accomplished by active pull-down, with open-collector devices (a common reference is assumed). In CAN descriptions, this is referred to as NRZ, since the voltage never should be at 0V, and the signal is constant for the entire bit. An additional description is used where the +3.5V level is identified as "recessive"(like resting), and the +1.5V level is called "dominant" (due to the active pull-down).
- Reception of these levels for a twisted-pair network is more similar to RS-422, because of the differential-mode input for noise-immunity, especially in noisy environments.
- The differential signal outputs/inputs are designated as CAN_H (CAN High) & CAN_L (CAN Low), and like all standards, do have specific pin assignments that depend on the type of connectors used. A description of the terms CAN_H & CAN_L are given later under "Data-Bits"
- This "differential-mode", using "twisted-pair" lines, is a time-proven method of gaining better "noise-immunity", and also enhances the speed or rate of data-transfer (up to 1Mbaud for CAN Networks).
- The CAN Network twisted-pair wires need to be properly terminated
at each end with a 120 ohm resistance. This best
represents the "characteristic-impedance",
or "surge-impedance" of the lines.
These termination resistors are necessary to reduce noise and echoing of signals on the data-bus, where it would impact the reliability of data messaging between devices on the bus.
- As in all serial communication interface technology, there are data-rate transfer-limitations, based on a number of various factors, particularly distance. CAN Networks can transfer data at 1 Mega-bits per seconds at a distance of up to 130 feet, and at lower rates for greater distances.
- The CAN Network is an open structure interface, allowing Multicasting and Broadcasting of messaging, with multi-mastering with equal nodes on the same line.
Data-Bits
- In a similar fashion to RS-232, where the first bit for asynchronous mode is a synchronizing bit, likewise the first transmitted asynchronous bit for CAN is a "Start-Bit".
- One major difference in data-bit transfer between RS-232 and CAN, is where clock timing and bit sampling are dependant on the start bit for a single frame of data, the CAN technique re-synchronizes on every "dominant" bit. In single-line-networks, dominant data transitions are, of normal consequence, a faster time-constant than transitions to recessive levels.
- In the differential-mode, when both CAN_H & CAN_L lines are driven to the same +2.5V level, resulting in a zero-difference, this represents a "recessive" bit. When the CAN_H is driven to the higher-level of +3.5V, and the CAN_L is driven to the lower-level of +1.5V, this results in a "dominant" bit. Note that the application of the dominant and recessive terms for a twisted-pair-network, are different than when used with a single-line-network. In both cases the emphasis is toward the "bus-state".
- Other important considerations are that to prevent drifting out of synchronization during multiples of the same data-bit value, a process called "bit-stuffing" is incorporated. This is accomplished by adding an alternate bit pattern to the existing data, whenever 5 consecutive similar values are passed. Bit-stuffing is by its nature, a good method of error-checking, and determining certain violations that may occur. In the detection process, the receiver would remove the stuffing bit from the data stream.
- Deliberate use of multiple consecutive bit patterns may be used as a method of instigating Error Codes.
- Due to the fact that dominant bits over-ride recessive bits, special placement of bits in the code sequence can be used for "Priority Arbitration". The first component of bits represents the highest priority. The Identification Code is an 11-bit code immediately following the Sync Bit.
- Arrangements of bit-patterns for transmission protocols are arranged in as many as 5 different "Frame" formats.
- In the same manner that USARTs are usually programmed for 16 clock samples per data-bit, the "bit-construction" of a CAN data-bit is by "Time-Quanta" or "Time-Quantum"(TQ), with a minimum of 8 to a maximum of 25 Time-Quanta per data-bit.
Software
- Nearly any serial-interface data-transfer will allow for data to be sent in "packets", providing that there is the necessary support software to allow more than "dumb-transfers".
- Since "Protocol" represents a method or procedure of doing a task, software becomes the natural element of control for various packets, frames, messaging formats, and interchange of information on a network such as the CAN Network.
- The procedure for any "data-packet" transmission or reception will depend on the "protocol", and each system will have its own version. These protocols can be very simple or quite complex, whether the system is a peer-to-peer, or multiple components on the same interface system.
- Software or firmware becomes the element of control for all of these "protocol" factors. It is this element of control of hardware by software, and the method of dealing with collision and arbitration that many people compare CAN Networking to Ether-Net.
- "Signal-Collisions" is a paramount consideration for reliable communication between multiple systems, requiring both hardware and software levels of control for stability and reliability. A method of dealing with signal collision in CAN Networking is by evaluating certain dominant states during the Identification (11-bit) period. Once past the ID, other devices will refrain from message transmission.
The higher-priority devices arbitrate at the earlier part of the ID, thereby allowing those devices to assume their proper role for messaging.
- CAN Networks have a solid reputation of reliability in a wide variety of industrial applications, ranging from vehicles, machinery processes, to instrumentation.
Principles
The complexity of the CAN Network technology is not in the voltage levels, but in the considerable optimization of the Collision-Detection, Messaging Protocols, and the "Multiple-Master" capability of the CAN Network.
- As is often the case in newer technologies, there may be comparisons of other systems of network communication.
- Generally speaking, any packet-protocol has at least 3 principle
parts:
- i.e. (1) Header, (2) Body of Data, (3) Tail.
- The Header: 11 ID bits, RTR-bit, IDE-bit, a
single reserved-bit, and a 4-bit Data-Length Code
- The Header in CAN Networking is comprised of the Identification-Bits, which also serves as an arbitration scheme.
- Following the 11-bits that comprise the ID is a single selection bit (RTR-bit). This bit acts as a selector between the "Standard Data Frame" (dominant mode) and the "Remote Frame" (recessive mode). The Remote Frame has no data field, and is used to request data. An occurrence of a dominant RTR-bit (Standard Data Frame), overrides a recessive Remote Frame request.
- Next is an Identifier Extension-bit (IDE), which when dominant, signals a normal Standard Data Frame 11-bit ID, vs. when recessive, signals an extended 18-bit ID extension. (29-bits in all).
- The next 4-bits serve as essentially a Data-Block indicator. The first bit serves as a Data-Block "On/Off" signal. The next 3-bits, indicate the number of 8-bit data blocks being transmitted, i.e.: 0-7 code = 1-8 Blocks being transmitted.
- The Body of Data:
- All data is sent in 8-bit (1 Byte) blocks, of which there may be a maximum of 8 blocks (64-bits in all) transmitted per packet.
- The Tail: (sometimes called the End of Data)
- As in nearly any packet protocol system, immediately following the data stream is a 15-bit Cyclic Redundancy Check (CRC), which the receiver uses to verify data received, followed by a recessive CRC Delimiter bit.
- If no CRC error is detected, the receiver sends a dominant Acknowledge bit (ACK), followed by a recessive ACK Delimiter bit.
- As in nearly all asynchronous serial communications, there needs to be a "idle-time, or dead-time" to allow re-synchronization of the next packet. For CAN Networking, there is a 7-bit recessive "End-of-Frame" period, followed by at least a 3-bit "Intermission".
- An important consideration of the 7-consecutive recessive bits, is that it "violates" the 5-bit rule, and will initiate a reset preparation for the next packet.
- The complexity of any protocol pertains to the required functions that must be performed. These include the normal identification of sender/receiver, receipt and acknowledgement of message, and recognition of global (or "broadcast") messages.
- One of the real merits of CAN Network and its associative protocol, is the method of handling the data-collisions that may occur. Simply stated, there are specific bit-pattern arrangements that allow recognition and avoidance of the interference caused by what might be data-collisions. The immediate result is greater reliability.
- These various bit-pattern arrangements that make up the core of CAN Networking, are however, the very thing that may make initial observations somewhat confusing and difficult to analyze.
Summary
- Dominant states overwrite recessive states.
- High priority events arbitrate the earliest in the ID sequence, causing the lessor priorities to go into a "in-bit-response" group of protocols.
- BasicCAN depends entirely on the host CPU for
all signal handling
- Simple and inexpensive, but it is subject to messaging overruns.
- CANopen has internal message management, thereby
considerably lightening the load for the CPU.
- Messaging formats are handled without the need of CPU intervention
- Node/Life Guarding provides for Nodes that may become defective or disconnected.
- Variations of CAN Network protocol.
- V2.0A Standard , 11-bit Message IDs (211 = 2048 identifiers)
- V2.0B Extended, 29-bit Message IDs
- The 7-Layer ISO/OSI Model: (addition description
in the next section)
- Application
- Presentation
- Session
- Transport
- Network
- Data Link
- Physical
- The 5 Frame Formats are: (addition description
in the next section)
- Data Frame
- Remote Frame
- Error Frame
- Overload Frame
- Interframe Space
- The 5 Error Descriptions are: (addition description
in the next section)
- Form Error
- Bit Error
- Stuff Error
- ACK Error
- CRC Error
- For all purposes, the Data-Frame format (55-bits) is simply
composed of these fields:
- Arbitration Field (12-bits)
- Control Field (6-bits)
- Data Field (groups of 8-bit blocks, i.e. 0, 8, 16, to 64 data-bits)
- CRC (Cyclic Redundancy Check)
- ACK
- Delimiter (idle, or dead-time)
- The formats of the other frames are specific to the tasks that they need to perform.
Examples
- The 7-Layer ISO/OSI Model: (only the Application
Layer is visible to the user)
- Application System Controls, Diagnostics, Data Transfers, System or Device Status
- Presentation Programming Level
- Session Type of Data-Interchange
- Transport Multi-Packet Protocol capability
- Network Repeaters, Bridges, Routers, Gateways (between Networks)
- Data Link CAN Codes, UART/USART, Protocol , Data Content
- Physical Hardware, Nodes, Cabling, Connectors, Fiber
- The 5 Frame Formats are:
- Data Frame:
- Actual data transfer from Node to Node
- Standard Frame (11-bit Id)
- Extended ID Frame (29-bit ID)
- Remote Frame:
- Request for data from another source
- Error Frame:
- 6 to 12 consecutive dominant bits (forming an Error Flag Field), followed by 8 consecutive recessive bits.
- "Data Invalid" response (see "5 Error Descriptions")
- Special Notes:
- 1. An "Error Active" node will generate the 6 consecutive dominant bits as an "Active Error Flag", followed by 8 consecutive passive delimiter bits.
- 2. The consecutive 6 dominant bits will generate a Stuffing-Bit Error, causing other nodes to recognize it and generate their own error frames.
- 3. An "Error Passive" node will generate 6 consecutive recessive bits, followed by the 8 consecutive recessive delimiter bits.
- Special Notes:
- Overload Frame:
- Delay Function (delays starting the next CAN message)
- 6 consecutive dominant bits (Overload Flag),
- followed by up to 6 other dominant flag bits, and then
- followed by 8 consecutive recessive bits (as an Error Delimiter).
- followed by up to 6 other dominant flag bits, and then
- Interframe Space:
- Simply the minimum 3 recessive "Intermission Field" bits following the last frame and the beginning of the next frame. Additional recessive bits may continue until the sync pulse of the next frame occurs
- Data Frame:
- The 5 Error Descriptions are:
- Form Error
- Detection of a spurious dominant bit in any of the following areas:
- Acknowledge (ACK) Delimiter
- CRC delimiter
- End of Frame Space
- Interframe Space
- Bit Error
- Only detected during the ID Arbitration Field, or the Acknowledge period
- Stuffing Error
- Excessive number of consecutive bits between Start of Frame and the CRC Delimiter
- ACK Error
- Failure of the Sender/Transmitter to receive a dominant Acknowledge (ACK) bit.
- CRC Error
- Discrepancy between transmitted data bits and received data bits
- Form Error