ok perfect. Can you hook the same circuit up to the tach and see what you get? Maybe take out the LCD.clear() so you can see multiple values. You should see some 0s and some 600's.i get 610 when hooking it up to the 12v
David
ok perfect. Can you hook the same circuit up to the tach and see what you get? Maybe take out the LCD.clear() so you can see multiple values. You should see some 0s and some 600's.i get 610 when hooking it up to the 12v
David
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 11, 7, 6, 5, 4, 3);
void setup()
{
while (analoglRead(0)>350) {} //spin til no tach pulse
while (analogRead(0)<=350) {} //spin til 1st tach pulse begins
unsigned long pulse1=millis(); //track time when 1st pulse begins
while (analogRead(0)>350) {} //spin til 1st tach pulse ends
while (analogRead(0)<=350) {} //spin til next tach pulse begins
unsigned long pulse2=millis();
int rpms=30000/(pulse2-pulse1);
lcd.clear();
lcd.print(rpms);
}
void loop () {
}
Off: 0
ACC: 114, 38, 114, 314, 28..
Running: 1250, 5788, 1304, 1363, 1428, 1363, 1304, 1428...
Revving: 2500, 2700....
lcd.clear();
lcd.print(rpms);
delay(300);
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 11, 7, 6, 5, 4, 3);
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
// /3 for 3 pulses per rotation (6 cylinder)
// /10 for some reason???
rpm = (((tachCount*4)*60)/3)/10;
lcd.clear();
lcd.print(rpm);
tachCount = 0;
time = millis();
}
}
void tachPulse()
{
++tachCount;
}
No that wouldn't work. You need a small capacitor like 100pf, and it needs to be in parallel with the 330K. The small cap acts like a shock absorber in the circuit so if there's a momentary spike it will soak it up and the arduino doesn't see it. The 4.7uf would be too big.Hum.. well i take it i should get a 4.7uf tomorrow at radio shack and place it between the 330k and arduino pen?
I like that code too! That's using interrupts which is a fine idea but you need the arduino seeing digitalRead() highs and lows which we couldn't do the other day. You could try that code with the signal on pin 2 instead of analog 0 now that you know the basic circuit works. If that doesn't work try substituting a 470K for the 330K but make sure you get the 100pf capacitor first.I like this code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 11, 7, 6, 5, 4, 3);
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
// /3 for 3 pulses per rotation (6 cylinder)
// /10 for some reason???
rpm = (((tachCount*4)*60)/3)/10;
delay(300);
lcd.clear();
lcd.print(rpm);
tachCount = 0;
time = millis();
}
}
void tachPulse()
{
++tachCount;
}
while (analogRead(0)>350) {} //spin til no tach pulse
while (analogRead(0)<=350) {} //spin til 1st tach pulse begins
unsigned long pulse1=millis(); //track time when 1st pulse begins
while (analogRead(0)>350) {} //spin til 1st tach pulse ends
while (analogRead(0)<=350) {} //spin til next tach pulse begins
unsigned long pulse2=millis();
int rpms=30000/(pulse2-pulse1);
while (analogRead(0)>350) {} //spin til no tach pulse
while (analogRead(0)<=350) {} //spin til 1st tach pulse begins
unsigned long pulse1=millis(); //track time when 1st pulse begins
while (analogRead(0)>350) {} //spin til 1st tach pulse ends
while (analogRead(0)<=350) {} //spin til next tach pulse begins
unsigned long pulse2=millis();
int rpms=30000/(pulse2-pulse1);
while (analogRead(0)>350) {} //spin til no tach pulse
while (analogRead(0)<=350) {} //spin til 1st tach pulse begins
unsigned long pulse1=millis(); //track time when 1st pulse begins
while (analogRead(0)>350) {} //spin til 1st tach pulse ends
while (analogRead(0)<=350) {} //spin til 2nd tach pulse begins
while (analogRead(0)>350) {} //spin til 2nd tach pulse ends
while (analogRead(0)<=350) {} //spin til 3rd tach pulse begins
unsigned long pulse2=millis();
int rpms=(30000/(pulse2-pulse1))*2;
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 11, 7, 6, 5, 4, 3);
void setup()
{
}
void loop () {
while (analogRead(0)>350) {} //spin til no tach pulse
while (analogRead(0)<=350) {} //spin til 1st tach pulse begins
unsigned long pulse1=millis(); //track time when 1st pulse begins
while (analogRead(0)>350) {} //spin til 1st tach pulse ends
while (analogRead(0)<=350) {} //spin til 2nd tach pulse begins
while (analogRead(0)>350) {} //spin til 2nd tach pulse ends
while (analogRead(0)<=350) {} //spin til 3rd tach pulse begins
unsigned long pulse2=millis();
int rpms=(30000/(pulse2-pulse1))*2;
lcd.clear();
lcd.print(rpms);
delay(300);
}
| Thread starter | Similar threads | Forum | Replies | Date |
|---|---|---|---|---|
| S | ATmega168 Beginner MCU Help | Microcontrollers | 8 | |
| W | FM Receiver Breakout with ATmega168 | Microcontrollers | 0 | |
| R | help with ATmega168 programmer board | Programming & Languages | 21 | |
| S | ATMega168 Tachometer help | Microcontrollers | 1 | |
| S | ATMega168 Tachometer help using LM2907 chip | Microcontrollers | 70 |