View Single Post
Old 03-03-2011, 12:06 AM   #36 (permalink)
toc
EcoModding Apprentice
 
Join Date: Jan 2011
Location: Australia
Posts: 179

Sonata97 - '97 Hyundai Sonata GL
90 day: 25.96 mpg (US)

Pulsar - '03 Nissan Pulsar ST
Team Nissan
90 day: 36.09 mpg (US)

Lancer - '04 Mitsubishi Lancer
90 day: 31.11 mpg (US)

Lancer 2.0 - '09 Mitsubishi Lancer
90 day: 27.1 mpg (US)
Thanks: 9
Thanked 16 Times in 13 Posts
I've tried again to use "Pin 11" of the ALDL connector to form some sort of speed input on it.

On the arduino I have been using this:

#include <LiquidCrystal.h>

int pinTachoInHz = 2; // D2 for Tacho Input - Measuring the Hz
long TachoInHz = 0; // declare this as a byte if the count is always less than 255
// so you don't have to disable interrupts when using in loop
long intTachoInHz_Millis = 0;
long prevTacho;
long readingMillis = 0;
long prevMillis;
float vssPulsesPerKM = 4750.0;

LiquidCrystal lcd(12, 11, 7, 6, 5, 4);

void setup() {
// Configure serial output
//Serial.begin(9600);

//Configure pin modes

lcd.begin(20, 4);

pinMode(pinTachoInHz, INPUT);
digitalWrite(pinTachoInHz, HIGH); // Turn on pullup resistor
attachInterrupt(0, count, RISING); // call count when pin 2 goes high

}

void loop(){
analogWrite(3, 55);
analogWrite(8, 200);
float curSpeed = 0;
long tachDiff = 0;
float dataMillis = 0;
lcd.setCursor(0, 0);
lcd.print("Sensor: ");
long tachoCount = TachoInHz; // get a snapshot of the count
readingMillis = millis();
dataMillis = readingMillis-prevMillis;
tachDiff = tachoCount-prevTacho;
float dataTacho = (tachDiff / dataMillis) * 1000;
lcd.print(tachoCount);
lcd.setCursor(0, 1);
lcd.print("Speed: ");
curSpeed = (dataTacho * 60) / vssPulsesPerKM;
lcd.print(curSpeed);
lcd.print("KM/hr");
prevTacho = tachoCount;
prevMillis = readingMillis;
lcd.setCursor(0, 2);
lcd.print("ODO: ");
float odo = tachoCount / vssPulsesPerKM;
lcd.print(odo);
lcd.print("KM");
lcd.setCursor(0, 3);
lcd.print(dataTacho);
lcd.print(" ");
lcd.print(dataTacho / vssPulsesPerKM);
delay(300);
lcd.clear();
// count the ms between each update, divide by the total ms (i.e. ms2 - ms1)
// Then, times 1000 to get pulses per second.
// divide by 4750
//times by 3600 and viola that should be very close.

// Else, look into Timer2 as another option.
}

// this needs to be fixed up!

void count(){
TachoInHz++;
}

Unfortunately, I'm still seeing inaccurate results.

I had another thought of using PulseIn to time the lengths of the pulses, this might give me something proportional to speed to work with.

Pin 11 of the ALDL connector is apparently, an output of vehicle speed (so the speedo cable goes to the ECU, the ECU puts out a 5V signal proportionate to the speed - and this should get faster as the vehicle is faster is my understanding).

Is there a better way to read that signal with minimal errors?

As you can see, 4750 is what I believe the number of pulses in a km are - but even that could be wrong if there are pulses missing for example - I know something is wrong, as the odo count is out - I drove 2KM according to the car ODO, this did not replicate to the odo count.
  Reply With Quote