{"id":1428,"date":"2018-02-15T20:27:12","date_gmt":"2018-02-16T01:27:12","guid":{"rendered":"http:\/\/www.circuitcrush.com\/?p=1428"},"modified":"2021-06-30T17:42:39","modified_gmt":"2021-06-30T21:42:39","slug":"how-obd-ii-works-part-2","status":"publish","type":"post","link":"https:\/\/www.circuitcrush.com\/how-obd-ii-works-part-2\/","title":{"rendered":"How OBD-II Vehicle Diagnostics Work, Part 2: A Closer Look"},"content":{"rendered":"<p>In part 1 of <a href=\"http:\/\/www.circuitcrush.com\/how-obd-ii-works\/\" target=\"_blank\" rel=\"noopener\">How OBD-II Vehicle Diagnostics Work<\/a> we quickly went over some history of electronics in cars and why you should care about OBD-II, even if you\u2019re not an automotive buff.<\/p>\n<p>Then, we went over some OBD-II basics and touched on the 4 \u201csub-standards\u201d of the OBD-II main standard.<\/p>\n<p>You learned about passive and active states and we went over OBD-II data packet structure before dissecting a typical OBD-II data packet.<\/p>\n<p>The post finished with a quick overview of diagnostic trouble code (DTC) structure and my promise to take a closer look at each of the four OBD-II standards in part 2 of the series.<\/p>\n<p><!--more--><\/p>\n<p>I\u2019m a man of my word, so here it is. Let\u2019s get a closer look at each standard. That way if you do decide to embark on an automotive related project, you\u2019ll be well prepared.<\/p>\n<h1><strong>OBD-II Standards<br \/>\n<\/strong><\/h1>\n<p>As a quick recap, here is a list of the four standards:<\/p>\n<ul>\n<li>ISO 9141-2<\/li>\n<li>SAE J1850 variable pulse width (VPW)<\/li>\n<li>SAE J1850 pulse width modulation (PWM)<\/li>\n<li>The newer CAN standard (ISO 15765)<\/li>\n<\/ul>\n<p>I\u2019ve also included the diagram of an OBD-II port and pinout (figure 1) from part 1 of the series as a reference.<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone wp-image-1350 size-full\" src=\"http:\/\/www.circuitcrush.com\/wp-content\/uploads\/OBD-II-Pinout.jpg\" alt=\"OBD-II pinout\" width=\"432\" height=\"550\" srcset=\"https:\/\/www.circuitcrush.com\/wp-content\/uploads\/OBD-II-Pinout.jpg 432w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/OBD-II-Pinout-118x150.jpg 118w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/OBD-II-Pinout-236x300.jpg 236w\" sizes=\"(max-width: 432px) 100vw, 432px\" \/><\/p>\n<p><strong><em>Figure 1: OBD-II connector and pinout.<\/em><\/strong><\/p>\n<p>Let\u2019s dive right on in.<\/p>\n<p> <\/p>\n<h2><strong>OBD-II ISO 9141-2<br \/>\n<\/strong><\/h2>\n<p>This one is popular with Chrysler, European, and many Asian vehicles. It uses pins 7 and 15 on the connector.<\/p>\n<p>This standard uses an asynchronous serial format running at 10,400 bps, like a UART.<\/p>\n<p>The voltage level ranges from 0 V to 12 V with 12 V being the passive state and 0 V the active state.<\/p>\n<p>Each byte begins with an active start bit. Next come 8 data bits. There is no parity and a stop bit comes last.<\/p>\n<p>Communication mainly takes place on pin 7 (a.k.a. the \u201cK\u201d line). Pin 15 (a.k.a. the \u201cL\u201d line) is optional. Pin 15, if used, serves a unidirectional wake up signal to the engine control unit (ECU). Message data can be up to 12 bytes per command.<\/p>\n<p>Note that the term ECU can refer to a single module or a collection of modules. They are the brains of the vehicle which monitor and control many functions of the car. Common types of ECUs include the ECM (engine control module), the TCM (transmission control module) and there are others.<\/p>\n<p>An alternate, yet similar protocol to ISO 9141-2 is ISO 14230-4 KWP2000. Basically, the format is the same, only the messages can contain up to 255 bytes. This one is common in US vehicles made after 2003, but before 2008.<\/p>\n<p>The ECU will go to sleep if it receives no communications in a 5 second period. Therefore, communications usually will begin with a wake up.<\/p>\n<h3 style=\"text-align: center;\">Become the Maker you were born to be. Try <a href=\"https:\/\/learnarduinonow.com\">Arduino Academy<\/a> for FREE!<\/h3>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-4238\" src=\"https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2.png\" alt=\"\" width=\"365\" height=\"139\" srcset=\"https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2.png 828w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2-300x114.png 300w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2-150x57.png 150w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2-768x292.png 768w\" sizes=\"(max-width: 365px) 100vw, 365px\" \/><\/p>\n<p>ISO 9141-2 uses a slow initialization, while ISO 14230-4 uses a fast initialization (another small difference).<\/p>\n<p>For a slow initialization, you need to send a 0x33 (as your data byte) at 5 bps to the ECU. The ECU then does a sort of \u201chandshake\u201d and things begin.<\/p>\n<p>The fast initialization process for ISO 14230-4 only takes about 500 ms.<\/p>\n<h2><strong>OBD-II SAE J1850 VPW<br \/>\n<\/strong><\/h2>\n<p>You\u2019ll often find this standard in pre-2008 General Motors vehicles.<\/p>\n<p>This single-wire protocol uses pin 2 and runs at about 10 Kb\/s. The bus may have a length up to 35 meters with 32 nodes.<\/p>\n<p>Variable pulse width (VPW) modulation uses 2-bit symbols, a 64 \u00b5s wide pulse and a 128 \u00b5s wide pulse. The signal level varies between 0 V (passive) and 7 or 8 V (active). Each packet it sends begins with a 200 \u00b5s start-of-frame (SOF) pulse, then comes the header. Following the header are the data bits.<\/p>\n<p>A symbol is a concept that can be used to encode multiple bits or just one bit. It is a waveform, a state or some significant condition of the communication channel that lasts for a fixed amount of time.<\/p>\n<p>The maximum number of data bytes the protocol allows in a normal message is 12, which transmits the most significant bit (MSB) first. Once all the data transmits, a cyclic redundancy check (CRC) byte is calculated and appended to the message.<\/p>\n<p>When the message is received by the receiving node, it shifts the header, data, and CRC bytes through some CRC circuitry. The circuitry performs a calculation that should produce 0xC4. If it doesn\u2019t, the receiving node flags the sender letting it know there is an error.<\/p>\n<p>Only two pulse widths are used when encoding data, either a short (64\u03bcs) or a long (128\u03bcs).<\/p>\n<p>There is a change in polarity for each bit symbol. The first bit is always passive since the SOF is always active. A 64 \u00b5s passive pulse is a 0 and a 128 \u00b5s passive pulse is a 1. Once the first symbol\u2019s pulse ends, the bit symbols reverse with a 64 \u00b5s active pulse being a 1 and a 128 \u00b5s active pulse being a 0.<\/p>\n<p>Since there is always a transition between states as each bit of a message is transmits, a series of high, low, high, low, etc. pulses compose the message. Logic 0s and 1s are uniquely encoded into both the active and passive states by varying the width of the pulse.<\/p>\n<p>Yep, it\u2019s sort of confusing. Figure 2 may help shed some light on it.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-1429 size-full\" src=\"http:\/\/www.circuitcrush.com\/wp-content\/uploads\/J1850-VPW.jpg\" alt=\"J1850 VPW Waveforms\" width=\"649\" height=\"287\" srcset=\"https:\/\/www.circuitcrush.com\/wp-content\/uploads\/J1850-VPW.jpg 649w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/J1850-VPW-600x265.jpg 600w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/J1850-VPW-150x66.jpg 150w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/J1850-VPW-300x133.jpg 300w\" sizes=\"(max-width: 649px) 100vw, 649px\" \/><\/p>\n<p><strong><em>Figure 2: SAE J1850 VPW logic 0 and logic 1.<\/em><\/strong><\/p>\n<p>Like ISO 9141-2, J1850 VPW runs at 10,400 bps. Note that you can add or remove nodes easily without affecting other nodes.<\/p>\n<p>While the timing for SAE J1850 VPW isn\u2019t very strict, the standard assumes that all the nodes on the bus are using the exact same ground. If the nodes are at different ground levels errors can result. Keep this in mind when working with this standard.<\/p>\n<p>For arbitration, an active state always dominates over a passive, or a zero always dominates over a one. Because of this, whichever message has a lower value in the header information wins arbitration. If two or more nodes are arbitrating with the same header information, then arbitration continues through every byte of the message until one node wins.<\/p>\n<p>Finally, the SAE J1850 VPW protocol doesn\u2019t require any sort of wake-up signal like the previous one did.<\/p>\n<h2><strong>OBD-II SAE J1850 PWM<br \/>\n<\/strong><\/h2>\n<p>This version of SAE J1850 is popular in pre-2008 Ford vehicles.<\/p>\n<p>The data rate is fixed and 10,400 bps like ISO 9141-2. The average throughput is about the same as the VPW version. The PWM version also has a 4x mode where the data rate bumps up to 41,600 bps. Like the previous version, PWM doesn\u2019t require any special wake-up or stay-up signal.<\/p>\n<p>This protocol also uses a SOF with an active pulse whose duration is twice that of the data bit time followed by a short passive pause.<\/p>\n<p>Data bit times are 96 \u00b5s (or 24 \u00b5s for the 4x mode) and each one begins in an active state. It uses a fixed frequency PWM pulse for each bit of data with a one-third (either 32 \u00b5s or 8 \u00b5s for 4x mode) active PWM being a 1 and a two-thirds (either 64 \u00b5s or 16 \u00b5s for 4x mode) active PWM as a 0.<\/p>\n<p>PWM uses an acknowledge (ACK) for each packet that transmits between the source and destination.<\/p>\n<p>Message length is restricted to 12 bytes, including the CRC. The header is 3 bytes.<\/p>\n<p>The data packet structure and arbitration scheme are the same as those for SAE J1850 VPW.<\/p>\n<p>To be more immune to noise, the output signal of SAE J1850 PWM transmits differentially on pin 2 (B+) and pin 10 (B-) of the OBD-II connector. Note that \u201cB\u201d stands for bus, not battery.<\/p>\n<p>Differential signals use two complementary voltages in order to transmit one signal. The receiver extracts information by detecting the potential difference between the inverted and non-inverted signals. Figure 3 depicts this.<\/p>\n<p>The B+ line has an active state of 5 V while the B- line has an active state of 0 V. It is the opposite for the passive state (B+ at 0 V and B- at 5 V).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1430 size-full\" src=\"http:\/\/www.circuitcrush.com\/wp-content\/uploads\/Differential-Signals.jpg\" alt=\"An example of differential signals\" width=\"599\" height=\"366\" srcset=\"https:\/\/www.circuitcrush.com\/wp-content\/uploads\/Differential-Signals.jpg 599w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/Differential-Signals-150x92.jpg 150w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/Differential-Signals-300x183.jpg 300w\" sizes=\"(max-width: 599px) 100vw, 599px\" \/><\/p>\n<p><strong><em>Figure 3: the bottom trace shows a differential signal, the top shows a normal “single-ended” signal.<\/em><\/strong><\/p>\n<h2><strong>ISO 15765 Controller Area Network (CAN)<br \/>\n<\/strong><\/h2>\n<p>All vehicles sold in the U.S. since January 1<sup>st<\/sup>, 2008 are required to use this protocol. If you have a European vehicle from 2003 or later, the vehicle may have CAN. Some pre-2003 vehicles may even use it, as it\u2019s been around since the 1980s.<\/p>\n<p>There are many articles and resources that relate to CAN and one can write a lot about it, so obviously part of a single blog post can\u2019t cover everything.<\/p>\n<p>The post <a href=\"http:\/\/www.circuitcrush.com\/can-networking-tutorial\/\" target=\"_blank\" rel=\"noopener\">You CAN Do It: A CAN Networking Tutorial for Beginners<\/a> is a nice introduction to the protocol. I suggest reading it before going any further.<\/p>\n<p>While CAN can operate at up to 1 Mbps, the version specified for OBD-II runs at 250 or 500 kbps. CAN addressing supports two modes: an 11-bit mode and a 29-bit extended mode. Given the two speeds and two addressing schemes, there are four different flavors of CAN that apply to the automotive sector.<\/p>\n<p>To help keep things in sync, CAN uses bit stuffing. Bit stuffing is the procedure of adding an opposite state bit whenever the data state remains the same for five consecutive bit times. On the receiving end, the next bit automatically gets tossed once the receiver gets five consecutive bits of the same state.<\/p>\n<p>Like SAE J1850 PWM, CAN uses differential signals to transmit data on 2 wires CAN high (CANH) and CAN low (CANL). Pin 6 of the OBD-II connector is the CANH line and pin 14 is CANL. The CANH line uses an active state of 3.5 V \u2013 5 V and the CANL line uses an active state of 0 V \u2013 2 V. The passive state of both the lines is 2.5 V.<\/p>\n<p>CAN communications use non-return-to-zero (NRZ) for coding and decoding bits.<\/p>\n<p>The idle state of the CAN bus is a logic 1, so a logic 0 bit of 4 \u00b5s (for 250 kbps) or 2 \u00b5s (for 500 kbps) indicates an SOF. The data bits follow using the same timing.<\/p>\n<p>Figure 4 depicts a typical CAN data frame. The frame is similar to the other protocols. The exception is that the header can use either an 11-bit format which is standard, or a 29-bit extended format.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-178 size-full\" src=\"http:\/\/www.circuitcrush.com\/wp-content\/uploads\/CAN-Frame.jpg\" alt=\"A typical CAN frame (with an 11 bit identifier)\" width=\"703\" height=\"110\" srcset=\"https:\/\/www.circuitcrush.com\/wp-content\/uploads\/CAN-Frame.jpg 703w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/CAN-Frame-600x94.jpg 600w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/CAN-Frame-150x23.jpg 150w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/CAN-Frame-300x47.jpg 300w\" sizes=\"(max-width: 703px) 100vw, 703px\" \/><\/p>\n<p><strong><em>Figure 4: a typical CAN data frame.<\/em><\/strong><\/p>\n<p>The RTR, IDE, r0, and DLC parts make up a byte and together are sometimes called the PCI byte. This byte is simply formatting information for the data bytes that follow. This is another small difference. The You CAN Do It article explains these bits in a bit more detail (pardon the pun). The article also goes over CAN bus arbitration.<\/p>\n<h1><strong>Working With OBD-II<br \/>\n<\/strong><\/h1>\n<p>For those who have the interest, I\u2019d like to give you some information on how to actually work with the OBD-II system in a vehicle before we wrap things up.<\/p>\n<p><a href=\"https:\/\/www.elmelectronics.com\" target=\"_blank\" rel=\"noopener\">ELM Electronics<\/a> makes several preprogrammed chips that will enable you to easily interface with your vehicle\u2019s OBD-II system. In fact, ELM has become the standard in this area, and you\u2019ll find their chips inside many of the scan tools that mechanics use.<\/p>\n<p>Some of you may find it inconvenient to sit in your car with a laptop and soldering iron, so if you\u2019d like to experiment with OBD-II there are a few options.<\/p>\n<p>You could buy an old ECU from a junk yard and take it to your bench. <a href=\"http:\/\/scantool.net\" target=\"_blank\" rel=\"noopener\">ScanTool.net<\/a> makes the ECUsim 2000 (and other items relating to OBD-II) which is a small simulator. The catch is that you must pick one protocol and the price currently starts at $200, which may be out of reach for some people. Additional protocols are available at an additional cost.<\/p>\n<p>The ECUsim 2000 simulates a vehicle with three ECUs, an ECM, a TCM, and an antilock braking module (ABS). This enables you to experiment with OBD-II at your bench without tethering you to the vehicle.<\/p>\n<p>Whatever you choose to do with OBD-II, just be careful and make sure everything is right before implementing it in your own vehicle. And don\u2019t forget to have some fun and learn something!<\/p>\n<p>Until next time, which OBD-II protocol does your vehicle use?\u00a0 Comment and let us know.<\/p>\n<h2 style=\"text-align: center;\">Become the Maker you were born to be. Try <a href=\"https:\/\/learnarduinonow.com\">Arduino Academy<\/a> for FREE!<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4238\" src=\"https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2.png\" alt=\"\" width=\"828\" height=\"315\" srcset=\"https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2.png 828w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2-300x114.png 300w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2-150x57.png 150w, https:\/\/www.circuitcrush.com\/wp-content\/uploads\/FB_Cover2-768x292.png 768w\" sizes=\"(max-width: 828px) 100vw, 828px\" \/><\/p>\n<a target=\"_blank\" href=\"https:\/\/www.drpeterscode.com\/index.php\"><img src=\"https:\/\/www.circuitcrush.com\/wp-content\/plugins\/dpabottomofpostpage\/apixel1x1.jpg\" ><\/a><table><\/table>","protected":false},"excerpt":{"rendered":"<p>In part 1 of How OBD-II Vehicle Diagnostics Work we quickly went over some history of electronics in cars and why you should care about OBD-II, even if you\u2019re not an automotive buff. Then, we went over some OBD-II basics and touched on the 4 \u201csub-standards\u201d of the OBD-II main standard. You learned about passive […]<\/p>\n","protected":false},"author":1,"featured_media":1435,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[104],"tags":[105],"class_list":{"0":"post-1428","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-obd-ii","8":"tag-obd-ii","9":"entry"},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/www.circuitcrush.com\/wp-content\/uploads\/OBD-II-Part-2.jpg","_links":{"self":[{"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/posts\/1428","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/comments?post=1428"}],"version-history":[{"count":1,"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/posts\/1428\/revisions"}],"predecessor-version":[{"id":4308,"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/posts\/1428\/revisions\/4308"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/media\/1435"}],"wp:attachment":[{"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/media?parent=1428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/categories?post=1428"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.circuitcrush.com\/wp-json\/wp\/v2\/tags?post=1428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}