Monday, April 5, 2010

CAN overview

Teaching digital data communication to auto repair types is beyond the scope of this blog, but I'm going to try to present some basic information below to help people without a computer background figure things out, and I'll include some links for those wanting to read further. This stuff I write below will be in the context of adding CAN to a vehicle -- debugging and repairing a newer car that already has CAN in it is probably close to impossible without the right tools and/or information that only the designers have.

What is CAN?


CAN stands for Controller Area Network, this in contrast to a Storage Area Network (SAN) used to network disk drives and servers, or a Local Area Network (LAN) used to network general-purpose computers (e.g. your PC) in a room or small building. In an automotive application, CAN is allowing us to replace wiring harnesses carrying what are effectively analog signals with pairs of wires carrying digital signals. We can combine multiple functions -- that used to require separate sets of wires -- onto a single pair of wires, reducing the amount of wiring required in the car. Engineers call this multiplexing.

The cost of potentially reduced wiring is increased control complexity. We have to introduce CAN nodes near the stuff we want to monitor (switches, sensors, etc) and control (light bulbs, electric motors, fuel injectors, etc.) The CAN nodes will have CAN controllers and transceivers (which may be chips separate from the controller, or they may be combined) in order to talk on the network as well as a microcontroller to oversee things. The software running on the microcontroller makes performing more advanced functions very easy; for example, we can program it to roll down our window all the way if we hold down the switch for 1s or something along those lines. Without a microcontroller, we'd need an awkward collection of timers and switches to pull this off. We could also have preset positions for our seats and mirrors -- something I wouldn't attempt with the 1983 technology currently in the car.

What's connected to the network?


...or, more to the point, what's connected to ours?

I good starting point would be some of the chassis electronics since they're what I'm having trouble with in my car. Long term, I'd like the network to be able to handle the stuff below.

  • Power door locks
  • Power windows and power window lock
  • Driver door lock heater
  • Power mirrors
  • Headlights (low and high beams), running lights
  • Blinkers, reverse lights and license plate lights
  • Windshield wipers
  • Windshield washer fluid pump
  • Dome lights
  • some other stuff that I forgot
  • (Note to self: leave room for power seats for those that have them)
  • Most importantly, Active Check control, which includes various bulb-out indicators and engine fluid level check lights. I'm going to start with active check control because it's completely unreliable in my car.

How is it all connected together?



CAN is a 1-bit wide network. Computer network folks like the OSI model, which divides the functions of a network into layers where the lowest level is the Physical Layer. In our case, this layer includes the wires connecting the CAN nodes and the transceivers connected to those wires. The physical layer is intentionally left out of the CAN specification -- it can include, for example, copper wires or fibre-optic cable at whatever bit rate -- but we're probably going to wind up with twisted pair. For our chassis electronics, I'm going to run it as slow a possible in order to keep things simple.

CAN doesn't talk about 1s and 0s when it talks about bits. Instead there are 'dominant' and 'recessive' bits. This accounts for situations where multiple CAN nodes are driving data onto the network simultaneously - if one node drives the dominant value and another drives the recessive value, the dominant value wins. The node driving the recessive value can see this, recognize that it has lost arbitration (it is, by definition, lower priority,) and stop transmitting data.

What data is transmitted?



Bits are grouped into frames and CAN supports 4 frame types. If you're really interested in the details here, check out one or more of the links below. The point I want to get across here is about the data in the frames: CAN nodes use the network to broadcast information about themselves. For example, a node watching the transmission might broadcast a message indicating that the car is in reverse, or a node watching the controls around the steering wheel might broadcast a message indicating that the driver turned on the windshield wipers. All other nodes on the network see this broadcast, whether it pertains to them or not, and it's each node's job to filter out the messages that they aren't interested in.

Still hungry?


Here are some links you can check out if you'd like to learn more about CAN.

Automotive CAN Diagnostics at aa1car.com: a little lighter weight than my text above and it has pictures!
Controller Area Network on Wikipedia
CAN Specification 2.0 (PDF)
Atmel Microcontrollers for Controller Area Network (PDF)