NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Project Help and Ideas » OBD II CAN Project Coding Error

April 08, 2011
by AbhishekBhat
AbhishekBhat's Avatar

Hi,

I was working on the OBD project, and had hooked it upto my car after a lot of effort! I could make out that the microcontroller was sending out the writer messages, but I doubt that the Microcontroller was going into the Read interrupt code part, and actually reading the canbus.

After looking at the code, I think I have a hint as to the reason for that, but just wanted to run it over you guys at nerdkits and Elena if she can get to it, as she was the one who implemented the code. But I would be grateful to anyone who could help clear the doubt.

  // update counters
  writer_bit_counter++;
  if(writer_bit_counter == 8) {
    writer_counter++;
    writer_bit_counter = 0;
  }

      // when done, disable our own interrupt from firing.
  if((writer_counter == writer_size) && (writer_bit_counter == 1)) {
    TIMSK0 &= ~(1<<OCIE0A);
#ifdef DEBUG
    //printf_P(PSTR("SEND SUCCESSFUL\r\n"));
#endif
    writer_started = 0;
  }

According to the code, the code will terminate the writer(i.e set writer_started = 0)) only when writer_bit_counter==1. Shouldnt this be writer_bit_counter==0, as you are setting that counter to 0 just prior to entering this if loop. Also, after the 8 bits have been completed, the bit counter will read 0, and not 1, so I think that is the only way the writer can be exited.

Do let me know the valuable inputs from your side.

April 09, 2011
by AbhishekBhat
AbhishekBhat's Avatar

Secondly, When I connect the microcontroller to my car, the security lamp goes on and al the dials stop working. So even with the engine on and running, the engine speed and oil temperature gauge show no movement. AS soon as I disconnect the microcontroller, the dials start showing the correct values.

I am not sure why does the security light go on?

April 09, 2011
by Rick_S
Rick_S's Avatar

You're braver than I. I'd be very nervous about plugging something into my car that I wasn't 100% sure could do no harm. The onboard computer of my car would cost a lot to replace if I were to make a mistake.

I will admit though, I have always wondered about the OBD-II project. There hasn't been much talk of it on the forums. It would be neat to see what could be done.

Rick

April 09, 2011
by 6ofhalfdozen
6ofhalfdozen's Avatar

Just for reference,

the computer on my 90 honda civic hatchback died about 8yrs back. At the time the car was only worth a little more than $1000. I check on getting it fixed and found out the following:

replacement computer board $2600

labor to install ~$400

initialize new board once installed (required to make it work) $2500

so about $5400 in 2003 to replace the computer on a little generic honda civic. I shudder to think what it would cost to replace the computer on something newer and fancier with all the added inputs (tire psi monitoring, antilockbreaks, etc)...

this is why, while I think the OBD project is a really really cool idea, I will definately not be brave enough to try it anytime soon.

April 09, 2011
by Ralphxyz
Ralphxyz's Avatar

Really, I need to build a clock for my 1999 Ford Ranger pickup truck (either that or figure out why my radio shorts out) and I thought well if I do that then I aught to just hook up the OBD-II to get engine info and possible speed (I also have lights burnt out on my dash so I can not see all of my speedometer at night.

So has anyone (else) done a OBD-II project?

Ralph

April 09, 2011
by Rick_S
Rick_S's Avatar

Sounds like you need a new truck Ralph wink biglaugh

Rick

April 09, 2011
by AbhishekBhat
AbhishekBhat's Avatar

Hi Guys.. I am actually a Mechanical Engineer and work on CAN bus and the data networks(all the theory and front end! :( ). So I am be pretty sure that so long as I dont send High voltage on the bus, there is no chance that the ECU will fry!The max that can happen due to sending wrong data is that the ECU stops transmitting/receiving due to the error frames, and it will go back to life by simply disconnecting the battery and reconnecting it. It is the microcontroller that is making my life miserable, but I am thoroughly enjoying the experience.. haha! I have been working on understanding the code and microcontroller basics for the last 3 months day in and day out! Its just that I cant get it to work!

To get to know someone who has actually implemented it on their car will really be wonderful.

April 09, 2011
by Ralphxyz
Ralphxyz's Avatar

AbhishekBhat,

"When I connect the microcontroller to my car, the security lamp goes on and al the dials stop working."

That right there tells me you are routing voltage to the wrong spot which could be dangerous to the ECU.

It would be good to hear from someone who has actually done this.

Have you searched the Nerdkits forums there are four pages of hits for OBD-II so it has had a bit of discussion.

Ralph

April 10, 2011
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Everyone,

@AbhishekBhat I think the big issue here is that our code and setup was meant to work on my 97 Cavalier, which uses the VPW protocol. The CAN bus is a newer technology that is substantially different. I believe the speeds and complexity of the protocol make it prohibitively hard to do with just an ATmega168. They do however make special CAN chips that the ATmega168 can interface with which might make your life a little easier.

As far as your dials stop working problem goes, we encountered similar problems a few times when working on my car. At some point we figured out that grounding a certain pin on the connector caused the speed dial to pegg to maximum (and the odometer to spin faster accordingly). Remember that the OBD-II protocol only specifies what a few of the pins on the connector need to be, the others are available to use as the manufacturer sees fit. Make sure you find the pinout of the OBD-II connector for your own car and work off of that.

Humberto

April 10, 2011
by Ralphxyz
Ralphxyz's Avatar

Should I be able to get vehicle speed from the OBD-II on my 1999 Ford Ranger?

Or would I just get symbolic references needing a lookup?

Ralph

April 10, 2011
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Ralph,

I'm pretty sure vehicle speed is just reported in km/h.

Humberto

April 10, 2011
by Rick_S
Rick_S's Avatar

Here's a site that has OBD-II and CAN to RS232 converter IC's. They are specially programmed PIC's with datasheets and schematics for interfacing them to a car. They would probably make a great front end for the Nerdkit and would do all the hard stuff.

Rick

April 11, 2011
by Ralphxyz
Ralphxyz's Avatar

Now what about a ATmel micro like the AT90CAN32 apparently it has a CAN buss built in negating the need of a ELM327 (CAN to RS232).

Is that correct?

I could handle km/h this is really getting interesting.

And yes Rick I have thought about getting a new truck especially when the 4 wheel drive stopped working.

Everything I found on the Internet said you really should not expect four wheel drive to be working on a 1999 Ford Ranger, or in fact your are lucky to have any 4x4 working that has been built in the past 20 years after 12 years.

Apparently the Ford Ranger (and other Fords of that period) used vacuum to actuate the hubs and everybody knows that after 10 years vacuum systems develop leaks and don't work. Everything I found was going to cost hundreds of dollars to repair.

And then I found a thread a guy posted saying all you had to do was this and that and your 4x4 would be working with manually actuated hubs unbelievable it took all of 15 minutes and I was trucking in 4 wheel drive.

So I am not about to give up my 4x4.

Ralph

April 11, 2011
by Noter
Noter's Avatar

I have two 4WDs and they both are and have been working fine. One is a 97 ford diesel and the other is an 85 toyota. Unless I have to haul something, I drive the toyota because it gets better mileage.

I was working on a tachometer for the toyota that gets a pulse from the distributor last year but tabled it over the winter because it's too cold to work on the truck unless it breaks and I absolutely have to. Maybe I'll be able to get the tach going in the next month or so now that it's warming up. I think my toyota is to old for any kind of CAN buss although it is fuel injected with some sort of mcu under the covers.

April 11, 2011
by AbhishekBhat
AbhishekBhat's Avatar

Hi Humberto, Sorry if I misspoke earlier, but what I meant was that my car is OBD2 compliant, and uses the VPW protocol.

I have a 2002 Pontiac Grand Am, and that uses the VPW protocol. I have also verified this by checking the pin out of the OBD, and it shows that the pin 2 is data, 16 - BAttery, 5 is - signal Ground, and 4 - Chassis ground. Other than these, I dont think there is any other connections on the OBD connector.

So I think that the interface for your as well as my car is the same. So I guess I am going on the same track as you people. Could you shed a little more light on the topic of why is the security light coming on, the dials have stopped working, and more importantly how did you get around this propble. Thanks a bunch

April 11, 2011
by Rick_S
Rick_S's Avatar

The Elm 327 doesn't really do CAN internally, they use an external chip for that but it does do VPW and PWM OBD II internal. I don't know what spec your 99 Ranger would use??

Noter, I picked up an old '93 corolla and it has a "diagnostic" connector under the hood. I know it has a tach signal there because the chilton repair manual I have for it talks about getting a tach signal from it. Other than that, I don't know what it outputs. It would be neat to tap into that if it had anything worth while in it.

Rick

April 11, 2011
by Noter
Noter's Avatar

Thanks Rick. I remember seeing a diagnostic connector under the hood, with 3 wires I think. I'll have to get to the scope on them and see what's up. That would be easier and probably safer for my nerdkit than using the distributor wire.

Post a Reply

Please log in to post a reply.

Did you know that you need to think about wires differently when you're transmitting signals more than a few inches? Learn more...