ATMega168 Tachometer help using LM2907 chip

SgtWookie

Joined Jul 17, 2007
22,230
Looks like around 200k to 210k is the ticket for your circuit.

If you don't have a 200k resistor, here are some series or parallel combinations that will get close:
110k + 91k = 201k (0 %)
120k + 82k = 202k (-1.463 %)
130k + 75k = 205k (0 %)
130k + 82k = 212k (0.952 %)
150k + 51k = 201k (0 %)
150k + 56k = 206k (0.488 %)
150k + 62k = 212k (0.952 %)
160k + 43k = 203k (-0.976 %)
180k + 24k = 204k (-0.488 %)
200k + 0 = 200k (-0.498 %)
200k + 5100 = 205100 (0.049 %)
220k || 2.4M = 201526.718 (0.262 %)
220k || 3M = 204968.944 (-0.015 %)
240k || 1.5M = 206896.552 (0.925 %)
240k || 1.6M = 208695.652 (-0.621 %)
270k || 820k = 203119.266 (-0.917 %)
270k || 910k = 208220.339 (-0.847 %)
300k || 620k = 202173.913 (-1.379 %)
300k || 680k = 208163.265 (-0.875 %)
330k || 510k = 200357.143 (-0.32 %)
330k || 560k = 207640.449 (-1.124 %)
360k || 470k = 203855.422 (-0.558 %)
360k || 510k = 211034.483 (0.493 %)
390k || 430k = 204512.195 (-0.238 %)
390k || 470k = 213139.535 (1.495 %)
 

Thread Starter

StealthRT

Joined Mar 20, 2009
303
But an important question comes to mind... I will be using this for all type of different cars. I need to find the "safe haven" that would work for all cars (prior to 2007+ I'm sure since they are different.. maybe?).

David
 

SgtWookie

Joined Jul 17, 2007
22,230
Do you have 4, 6 and 8 cylinder vehicles that you can experiment with?

Right now, this certainly isn't ready for production. It's experimental.

Even if you manage to somehow get something like this into production, the resistor will wind up being SOT (Select On Test), as out of necessity (cost factor), you will have to use components with greater tolerances than what you've been using.
 

Thread Starter

StealthRT

Joined Mar 20, 2009
303
Well the truck i am using for this is a 6-cyl. I have a V8 Durango that i could use if i need something higher than a 6 but i thought i would just use a switch for 4/6 or 8-cyl.

I just want to be able to detect the low RPM once the car has started no matter if its a v6 civic or a v6 mustang.

David
 

SgtWookie

Joined Jul 17, 2007
22,230
It's based on the number of tach pulses it receives in a given period of time.

A 4-cyl will put out two tach pulses per revolution; 6-cyl three; 8-cyl four.

I wouldn't use a switch; that would be too costly. A 0.1" jumper would work fine.

But if you were really considering making it cost-effective for production, I'd get rid of the entire circuit altogether, and just use the uC to count triggers on an internal comparator vs time.

What's the point in having a bunch of analog circuitry that could be done away with altogether?
 

Thread Starter

StealthRT

Joined Mar 20, 2009
303
I was just thinking about using this:

http://mouser.com/Search/ProductDetail.aspx?qs=sGAEpiMZZMukXCIZ6E1E4Cpuuzf3fTP4uLkUompNZOA=

for a switch. Just connect a pair of pins together to create the correct connection to the resistor that would be needed for either a 4,6 or 8-cyl. So, 3 pairs of pins. (6 total pins) and just connect them with a bridge connector. (top and bottom pins)

But if you were really considering making it cost-effective for production, I'd get rid of the entire circuit altogether, and just use the uC to count triggers on an internal comparator vs time.

What's the point in having a bunch of analog circuitry that could be done away with altogether?
I do not know how to code for the arduino to take in the PWM. Besides, i would like to use an analog input instead of using a digital since i will be using those for various other things for the car. I figured having a chip that converts pulses to volts or volts to pulses would be more ideal than having the arduino do its crazy code stuff.

David
 

SgtWookie

Joined Jul 17, 2007
22,230
I was just thinking about using this:

http://mouser.com/Search/ProductDetail.aspx?qs=sGAEpiMZZMukXCIZ6E1E4Cpuuzf3fTP4uLkUompNZOA=

for a switch. Just connect a pair of pins together to create the correct connection to the resistor that would be needed for either a 4,6 or 8-cyl. So, 3 pairs of pins. (6 total pins) and just connect them with a bridge connector. (top and bottom pins)
Do you absolutely have to have a bend?

Any additional operation that's required to make a component costs money. A straight 6-pin dual row header would be much less expensive.

I do not know how to code for the arduino to take in the PWM.
It wouldn't be PWM, it would be a digital input. You just count the transitions vs a known frequency; the clock.

Besides, i would like to use an analog input instead of using a digital since i will be using those for various other things for the car. I figured having a chip that converts pulses to volts or volts to pulses would be more ideal than having the arduino do its crazy code stuff.
It's not "crazy code stuff".

Right now, what you're getting as an output from this thing SHOULD be a logic "1" or logic "0" as to whether the engine is not running, or running, respectively. The circuit right now is problematic, experimental, and is not ideal. We're still trying to "tweak in" values for your breadboarded circuit that was started a couple of weeks ago. Basically, you're looking for a 1 or 0.
That's not analog.

Were you not so intimidated by Arduino code, this would've been taken care of a week or two ago. Selection of 4-6-8 cylinders could be made by simply jumpering one or two input pins to Vdd or GND. The entire input circuit could have been replaced by three resistors and a capacitor.

Hey, you needed the Arduino anyway, right?

Why not eliminate all of the analog stuff, and just have the Arduino count the pulses directly? It would make things so much more simple.
 

Thread Starter

StealthRT

Joined Mar 20, 2009
303
But what i do not get is that the arduino can only see 5v or less-not pulses...

Well im always open to suggestions. If you know how to do that using the arduino then by all means teach me how :) The only code i could find was this:
Rich (BB code):
/*
Tachometer circuit:

Low tension from distributor >---24k-o-> input 2
                                     |
                                    11K
                                     |
                                     0v
  
*/

volatile int tachCount = 0;
long time;
long rpm = 0;

void setup()
{
  attachInterrupt(0, tachPulse, RISING);
  time = millis();
}

void loop()
{
  //Runs every 1/4 second
  if (millis() - time >= 250)
  {
    // rpm = number of interrupts counted in 250ms
    //  *4 to make per second
    //  *60 to make per minute
    //  /2 for 2 pulses per rotation (4 cylinder)
    //  /10 for some reason???
    rpm = (((tachCount*4)*60)/2)/10;
    
    //Do things with the RPM value here (update display etc)...
    //

    tachCount = 0;
    time = millis();
  }
}

void tachPulse()
{
  ++tachCount;
}
David
 

SgtWookie

Joined Jul 17, 2007
22,230
I don't know a darned thing about Arduinos.

However, I'll bet you'll find that others on the forums do.

Why not make an inquiry in the correct forum? We can follow up later.
 

bill2009

Joined Apr 17, 2009
31
Hi, I came across this by accident but I am working on a tach using an arduino. At least on my motorcycle the arduino reads the tach signal very easily with either analog or digital inputs. The only external circuitry I have in the breadboard is a divider network to bring the signal into below 5 volts. Literally a 1M resistor from the tach lead to an arduino pin and a 330K resistor from that pin to ground. This works like a champ with (on my 2 cyl bike), 1 pulse per revolution.

I am told though that vehicle ignition systems are very noisy environments and that I need way more isolation. I was interested in the LM2907 as a way of providing that isolation. Probably way too many parts in the final version though.
 

bill2009

Joined Apr 17, 2009
31
Hi, I think the tach circuit can be very very simple. The main issue is protecting the AVR from the ignition system. Have you measured the tach signal with a scope to see what it looks like?

You basically just need to get a 5v logic level that pulses with the engine speed or any multiple of it. You can use that either with brute force digitalReads or by driving an interrupt if the AVR has other stuff to do.

If you measure the voltage and explain what else your program has to do I'll be happy to spit out some draft code for you.

You can take a look at http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1236701872 for an example although the code there is much more complicated than you will need.
 

Thread Starter

StealthRT

Joined Mar 20, 2009
303
Hey Bill thanks for the quick response.

As for your scope question, no i do not own one. So i can not check that.

As for what I'm *planning* to do with it...

I am hooking up a bluetooth modal that i use my cell phone to turn on/off each digital output. I will have each digital output control door locks/windows/lights/etc etc..

So id rather use a Analog input and not take up any of my digitals if at all possible so that i can use all the digitals for outputs.

I still don't really understand how the ATMEGA168 chip can *read* the tach wire when it has frequency-and the chip can only read volts.... An explanation of that would be wonderful. Feed me knowledge about that. :)

David
 

bill2009

Joined Apr 17, 2009
31
As for your scope question, no i do not own one. So i can not check that.
ok, I'm going to make an assumption below that it give a rough 14V square wave at 2X engine speed.

I am hooking up a bluetooth modal that i use my cell phone to turn on/off each digital output. I will have each digital output control door locks/windows/lights/etc etc..

So id rather use a Analog input and not take up any of my digitals if at all possible so that i can use all the digitals for outputs.
The analog pins can all be used to read digital inputs. Analog pin 0 is digital pin 14.

I still don't really understand how the ATMEGA168 chip can *read* the tach wire when it has frequency-and the chip can only read volts.... An explanation of that would be wonderful. Feed me knowledge about that.
The avr can read the tach input and determine whether the signal is high or low. If it measures how long between pulses when the signal goes high it can determine the frequency. The easiest way to do this is with an interrupt routine and they're not that tricky but I'll try to do it with brute force below. This assumes you hook up pin 14 (Analog 0) of your arduino to the tach wire through a 1M resistor and run a 330K resistor from that pin to ground along with a 100 pf cap**


Rich (BB code):
void loop () {
  while (digitalRead(14)==HIGH) {} //spin til no tach pulse 
  while (digitalRead(14)==LOW) {} //spin til 1st tach pulse begins 
  unsigned long pulse1=millis(); //track time when 1st pulse begins
  while (digitalRead(14)==HIGH) {} //spin til 1st tach pulse ends
  while (digitalRead(14)==LOW) {} //spin til next tach pulse begins 
  unsigned long pulse2=millis();
  int rpms=30000/(pulse2-pulse1);
  Serial.print(rpms);
}
** Critical assumption that the AVR will survive this with only the two resistors and small cap. If you are going to depend on this you should really scope the signal and think about power conditioning. Also, I did not actually try the code! Interrupts make this all much simpler by the way.
 
Last edited:

Thread Starter

StealthRT

Joined Mar 20, 2009
303
Sorry i forgot to say that i am only looking to see when the car has started since i will be starting the car with the bluetooth and need to know when the engine has started so i can tell the chip to stop cracking it.

int rpms=30000/(pulse2-pulse1);
Did you mean to put 30,000 or 3,000?

So i take it
Serial.print(rpms)
Should output the actual rpm numbers? And again, i only need to know when the car has started (whatever idle is. be it if i set it to > 300rpms or whatever)

David
 

bill2009

Joined Apr 17, 2009
31
No, I meant 30,000 - it's actually 60,000 milliseconds(one minute), divided by the time between pulses(in milliseconds), divided by 2 because you get 2 pulses per revolution.

How would your starter-stoppper work? Crank for 3 seconds then check if it's running? I can actually see the attraction of the separate chip if you don't care about anything except on/off but getting rid of the extra components is probably worth the hassle.

I can imagine a function that would return a "true" if it sees a few pulses in a second and "false" if it doesn't like:

if (enginerunning()) {
whatever
}
else {
whatever else
}

Or use it in a loop that includes the starter actuation and whatever you do if the starting sequence doesn't work.
 

Thread Starter

StealthRT

Joined Mar 20, 2009
303
How would your starter-stoppper work?
I would just send the "START" command via bluetooth to the chip and once the chip detects rpms at or above 300 then the engine must be started... and therefore stop trying to start it.

I had invisioned something like so in a loop:
Rich (BB code):
    if (code = "START")
    {
       startEngine();
    }

    Function startEngine(){
    x = 0;

    do until x = 10
       if (rpm >= 300 && x < 9)
       {
         STOP STARTING, ITS RUNNING
         x = 0;
       }else{
         Keep trying until x = 10
         x = x + 1;
       }
    loop
}
I do have a 1Meg resistor and 330k. However, you (as does stgwookie) keeps saying that the electronics in cars are very noisy. What can i put in between the chip and the tach in order for that not to be a problem? You said that the LM2907 chip would do that but it's no longer being used to my dismay so another soluction is needed in its place.

David
 

SgtWookie

Joined Jul 17, 2007
22,230
You could use a 4.7v Zener diode from the Arduino's input pin to ground to protect against overvoltage, and use a 3k to 10k resistor from the tach to the Arduino. Pretty simple and cheap.
 

Thread Starter

StealthRT

Joined Mar 20, 2009
303
Well there's one problem stopping me from testing this out.... i have no laptop to hook up so i can see what values i am getting from the arduino... Any suggestions?

David
 
Top