I'm building a circuit to interpret the tach signal from a Honda Civic and drive a servo. The servo will turn the needle of a 3' diameter tachometer, which will be on the roof our our 24 Hours of LeMONs car. Original post here: http://arduino.cc/forum/index.php/topic,55381.0.html
I have everything laid out and it is generally working, in that the servo position generally climbs with the vehicle RPM, but behaves jumps around a lot. Looking at the serial monitor, I'm getting Pulsein values of around 32000 at idle, and 1200 at high RPM. Those values are inconsistent however. At idle, I'll get 32000, 30000, 34000, 25000, 2200, 32000, 2330, etc...
Unfortunately the freq counter and servo libraries cannot coexist, from what I've read.
Do I need a function to smooth the data? Anyone see anything glaring in the code?
What I got this far:
Voltage divider circuit (as described in original post) to convert 12V pulse to a 5V pulse.
5V DC-DC regulating power supply - grounded/powered by vehicle.
Arduino- GND pin grounded to powersupply/vehicle, but powered on the bench by USB for the serial monitor (is this a grounding problem?)
This simple code:
#include <Servo.h>
Servo tach; // create servo object to control tach needle
int pin = 7; // tach signal pin
unsigned long duration; // variable to store tach signal
void setup()
{
Serial.begin(9600);
tach.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(pin, INPUT);
}
void loop()
{
duration = pulseIn(pin, HIGH); // pulsein, pin 7 input, waits for it to go high, times out in 1000ms
map(duration,500,30000,180,0); // map pulsein duration
tach.write(duration); // move needle to position
Serial.println(duration); // debug pulsein
delay(100); // arbitrary delay = need to tune this to servo resolution
}
Thanks in advance for advice.