From 8f2094e20a90f7476980fda4e08a8000924bbef4 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Mon, 12 May 2014 13:43:33 +1000 Subject: [PATCH] First work on coolant and IAT reads and corrections --- globals.h | 2 +- speeduino.ino | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/globals.h b/globals.h index 2ebd584..823cabb 100644 --- a/globals.h +++ b/globals.h @@ -42,7 +42,7 @@ struct statuses { byte VE; byte O2; byte coolant; - byte coolantADC; + byte cltADC; byte IAT; byte iatADC; byte advance; diff --git a/speeduino.ino b/speeduino.ino index 02a9dd6..ffd0638 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -56,6 +56,9 @@ struct table3D fuelTable; //8x8 fuel map struct table3D ignitionTable; //8x8 ignition map struct table2D taeTable; //4 bin TPS Acceleration Enrichment map (2D) struct table2D WUETable; //10 bin Warm Up Enrichment map (2D) +struct table2D cltCalibrationTable; +struct table2D iatCalibrationTable; +struct table2D o2CalibrationTable; unsigned long counter; unsigned long currentLoopTime; //The time the current loop started (uS) @@ -220,20 +223,27 @@ void loop() } //Uncomment the following for testing - /* + currentStatus.hasSync = true; currentStatus.RPM = 5500; - */ + //***SET STATUSES*** //----------------------------------------------------------------------------------------------------- currentStatus.TPSlast = currentStatus.TPS; currentStatus.MAP = fastMap(analogRead(pinMAP), 0, 1023, 0, 100); //Get the current MAP value - currentStatus.coolant = fastMap(analogRead(pinCLT), 0, 1023, 0, 255); //Get the current raw CLT value - currentStatus.iatADC = fastMap(analogRead(pinIAT), 0, 1023, 0, 255); //Get the current raw IAT value currentStatus.tpsADC = fastMap(analogRead(pinTPS), 0, 1023, 0, 255); //Get the current raw TPS ADC value and map it into a byte currentStatus.TPS = fastMap(currentStatus.tpsADC, configPage1.tpsMin, configPage1.tpsMax, 0, 100); //Take the raw TPS ADC value and convert it into a TPS% based on the calibrated values currentStatus.O2 = fastMap(analogRead(pinO2), 0, 1023, 117, 358); //Get the current O2 value. Calibration is from AFR values 7.35 to 22.4, then multiplied by 16 (<< 4). This is the correct calibration for an Innovate Wideband 0v - 5V unit + //The IAT and CLT readings can be done less frequently. This still runs about 10 times per second + if ((mainLoopCount & 127) == 1) + { + currentStatus.cltADC = fastMap(analogRead(pinCLT), 0, 1023, 0, 255); //Get the current raw CLT value + currentStatus.iatADC = fastMap(analogRead(pinIAT), 0, 1023, 0, 255); //Get the current raw IAT value + + currentStatus.coolant = table2D_getValue(cltCalibrationTable, currentStatus.cltADC); + currentStatus.IAT = table2D_getValue(iatCalibrationTable, currentStatus.iatADC); + } //Always check for sync //Main loop runs within this clause