Bil Herd Asks OBD “How Fast am I Going?”


Whenever I end up with a new vehicle I ultimately end up sticking in a new GPS/Receiver combination for better sound quality and a better GPS.

I am quite at home tearing into a dashboard as I was licensed to install CB radios in my teens as well as being the local go-to guy for 8-track stereo upgrades in the 70’s. I have spent a portion of my life laying upside down in a puddle on the car floor peering up into the mess of wires and brackets trying to keep things from dropping on my face. If you remember my post on my Datsun 280ZXT, I laid in that same position while welding in a clutch pedal bracket while getting very little welding slag on my face. I did make a note that the next time I convert a car from an automatic to a manual to do so while things are still disassembled.image15

Swapping out a factory radio usually involves choosing whether to hack into the existing factory wiring wire-by-wire, or my preference, getting a cable harness that mates with the factory plug and making an adapter out of it by splicing it to the connector that comes with the new radio.

Usually I still have to hunt down a few signals such as reverse indicator, parking brake indicator, vehicle speed sensor and the like. In my last vehicle the Vehicle Speed Sensor (VSS) wire was supposed to be in the factory harness, but driving experience showed it must not be as the GPS would show me driving 30 feet to the right of the highway. That and the calibration screen on the GPS verified that it was not receiving speed pulses.

Finding the VSS Wire

Diving deep into the dash verified that a single wire was in fact missing in spite of being shown in the standard Haynes manual. Many times the VSS signal is on the harness for use by a GPS or for the automatic volume adjustment on the radio — as the vehicle goes faster the factory radio gets louder.

speed-pulse

I checked all of my online installer resources and no one had identified the signal as present anywhere in the driver compartment. Finally I leased the Ford schematics directly from Ford and was able to identify a safe speed signal to use. I should note that I stay away from the wheel speed sensors for the anti-lock brake system, I am already freaked out by the thought that a microcontroller is running the brakes on my behalf. As it turns out there was a solitary signal that lets the windshield wiper controller speed up when the vehicle speeds up, like an automatic volume control only for wipers.

All of this effort got me thinking about how else I could have done this without running wires through the firewall and tapping one of 300 wires attached to the on-board Electronic Control Unit (ECU). In other words, how would a normal person do it?

Microchip Technology Incorporated 18060 IVN
Microchip Technology Incorporated 18060 IVN

One thought I had was to put together a dedicated circuit that could query what the vehicle speed was from the built-in On Board Diagnostic bus (OBD or OBDII) and synthesizing a speed pulse from the resulting data. Looking on the Internet briefly I found that there was one company that did this for retrofitting taxicabs for the metering hardware but not much more than that. Besides all of that, I needed a topic for a Hackaday video.

Here we see the years that the various OBD protocols were used and a quick summary.

Name

Speed

Used by

ISO 9141

10 Kbits/second

most Asian and European manufacturers

J1850 PWM

(Pulse Width Modulation)

100 Kbits/second

Ford, Mazda

J1850 VPW

(Variable Pulse Width)

100 Kbits/second

Primarily GM

CAN

(Controller Area Network)

200-500

Kbits/second

Newer Vehicles

Looking into the OBDII connector and protocol the first thing that jumps out is that it’s not a single protocol; it is a collection of legacy protocols. Vehicles made since 2008 typically use the Controller Area Network (CAN) protocol.

obd-years
Microchip Technology Incorporated 18060 IVN

One thing I knew was that I didn’t want to learn the intricacies of these lower level protocols and how to program at a bit or frame level, I just wanted to ask and get an answer to a simple question: “What is the vehicle speed?” In the video I do go into the different electrical interfaces for J1850, ISO9141 and CAN.

Reading CAN Data

I came upon an OBD interpreter chip made by OBD Solutions. It’s called the STN1110 and converts the physical and low level protocols into a simple ASCII based UART interface.

stn1110

Sending a query for the Parameter Identification (PID) for Vehicle speed “010d” results in a three byte response with the third byte being the vehicle speed in kilometers and hour as a single byte hex value. (0-255 km/hr). From this data it’s just a matter of creating a pulse that gets faster based on the size of the VSS value, the larger the value, the higher the output frequency. I actually don’t know what the GPS expects as a normal frequency but being software, I can always scale it if I run into problems.

schematicLooking at the datasheet for the STN1110 they give examples of the interface circuitry for the various protocols: CAN, J1850, ISO9141. If I were doing this project for production I would scrutinize the interfaces in great detail, but for a video and a one-off circuit I am more than willing to take the vendor’s suggested circuits as they most likely know the “normal” for what works.

What the designer still has to do is make sure that surge protection and that the current draw and the ability to “sleep” are designed in. With regard to surge suppression, the automobile is one dirty environment; huge inductors (starter, alternator) and lots of places where spikes and surges can be injected. With regard to current draw, the assembly would be plugged in “permanently” which means that it’s current draw must be minuscule while sitting for weeks on battery power. I once installed an alarm system in one of my cars which killed the battery in a week, it sucked.

Cramming Too Much On One Board Footprint

pcb1

Looking at the board you will see I did an insane thing, I mixed surface mount and through-hole and not just any through-hole, I mounted the resistors radially, meaning that they stand up like the old Japanese radios of the 70s-80s. Part of the idea was what if I wanted to make a kit and the other is that I really hate placing 50 SMT resistors as they get in my arm hair and it’s easy to misplace them. The size of the PCB was selected to fit a plastic enclosure I picked off of Digikey.

Turns out once I got into everything I realize that if I pare the design down to just the CAN protocol (2008+) it will do everything I need and so rev 2 will be all through-hole so I can throw the spares up on Tinde as a kit.

Things work well enough with the final board with the exception of the fact that I missed that one of the LED indicator pins is also used to initiate a Non-Volatile RAM initialization… I mean who doubles an LED pin as an input pin? Even with the LED in place a resistor would be needed to tie it tosimulator a known state since an LED that is turned off doesn’t conduct current or act like a resistor.

Finally at the end of the video I break out my cheapo OBD simulator which basically parks my truck on the work bench, electronically speaking. There are really good versions of these, mine is a $70 one I got off eBay. The instructions are in Mandarin but they really aren’t needed. Using a dev board with built-in USB connector simulates my custom board without the FTDI interaction I was getting between the Hackaday Pro Trinket and serial monitor. I set the baud for 9600 and issue the PID query for VSS: 010D (or $010D as I would say being an old timer)

It replies with B5 meaning that the simulator is traveling at 181 km/hr. (Decimal of Hex B5 is 181)

In the next post I address the software. Being a simple form of instrumentation my inclination is to implement this as a (simple) Real Time Operating System (RTOS) meaning that hardware counters and timers tied to crystal create the final signal that does not vary based on the execution time of the code. I am also inclined to use assembler (did you submit to the Hackaday 1k Challenge??) and because I am a hardware engineer I love true In circuit Emulators(ICE). You know, where you actually see the execution of the processor itself and can set true breakpoints (An IDE is not an ICE). See you next time!



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *