ATMega168 Tachometer help using LM2907 chip

Thread Starter

StealthRT

Joined Mar 20, 2009
303
Alright I've ordered a compatible Hitachi HD44780 LCD for the project. Now i just have to play the waiting game til it arrives...

Ill keep you updated :)

David
 

Thread Starter

StealthRT

Joined Mar 20, 2009
303
Wow... that took forever to get!

Well i finally got it and hooked it all up :)

So now i need a 4.7u to protect the pin and 3k-10k for it?

David
 

bill2009

Joined Apr 17, 2009
31
Why don't you try my suggested code(see below) for starters.

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);
}
I don't think you could hurt the arduino doing this and if your LCD is hooked up you can use that to print the rpms value. If it doesn't seem to work, just replace the guts of the loop with an analogRead of pin 0 and see what that shows.
 
Last edited:

bill2009

Joined Apr 17, 2009
31
I currently do not have a 100 pf cap. only a 100v .1uf, 50v 1.0uf and 10v 100uf.

Will any of those work?

David
I actually don't think so. The value's not critical but the electrolytic caps would be way too big. If you're in a radio shack sometime just look for a small ceramic cap. Just leave it out for now and let's try to get it working.
 

Thread Starter

StealthRT

Joined Mar 20, 2009
303
Alright.

I'm testing it out using a little over 12v.

This is what i get from the voltmeter: 4.3 and it keeps going lower and lower.

However, once hooked to the arduino analogpin 0, i get nothing on the LCD.

Here is the code:
Rich (BB code):
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 11, 7, 6, 5, 4, 3);

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

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);
 
 lcd.clear();
    lcd.print(rpms);
}
David
 
Last edited:

bill2009

Joined Apr 17, 2009
31
so 12V-->1M-->*A*-->330K-->Ground.

a voltmeter at *A* should show about 3 volts and it shouldn't change. There's no capacitor - right?
 

bill2009

Joined Apr 17, 2009
31
looking at the code, the attachinterrupt isn't needed this time and it won't work with a steady voltage. To get a result printed you'll need to repeatedly cycle the voltage from 12v to 0 (assuming you're doing this on a workbench rather than pulugging it into the tach lead).
 

bill2009

Joined Apr 17, 2009
31
ok thanks for the pic. that's great.

is the tach wire actually going to the running engine? If so we should see something.

Assuming you've verified that you can print on the LCD and see a result. Replace the body of the loop with:

int v=analogRead(0);
LCD.print(v);

caveat: I've never used the LCD stuff.
 

Thread Starter

StealthRT

Joined Mar 20, 2009
303
Yes the lcd works just fine. I replace the code and it shows "0" on it constantly... I commented out the attachinterrupt and time = millis(); already.

the tach wire is hooked up to 12v right now for testing.

I did the 12v to 0v then back again a couple times and got -1 and sometimes 6000. 14, 30000, 144, 283, 1071, 7500, 3333, 1000, 75....

David
 
Last edited:

bill2009

Joined Apr 17, 2009
31
I did the 12v to 0v then back again a couple times and got -1 and sometimes 6000. 14, 30000, 144....

David
bingo - just toggling it by hand will bounce like mad and give erratic results. You could try the tach now if it's convenient.

If you want to try something else on the bench you could hook up the .1uf cap to the "tach" input or in parallel with the 330K and do a deliberate one per second make/break and you might get something more sensible. Do NOT use the big cap when you hook it up to the real car circuit.
 
Top