From 21d2078a4e9dfef3f1540e4b525048be0ff04bc0 Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Tue, 1 Mar 2016 14:39:50 +1100 Subject: [PATCH] Significant improvements to analog sensor readings (Filtering and read strategy) --- globals.h | 4 ++-- reference/speeduino.ini | 2 +- speeduino.ino | 14 ++++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/globals.h b/globals.h index a4fba7f1..bc3e6548 100644 --- a/globals.h +++ b/globals.h @@ -46,8 +46,8 @@ const int map_page_size = 288; // The following are alpha values for the ADC filters. // Their values are from 0 to 255 with 0 being no filtering and 255 being maximum #define ADCFILTER_TPS 128 -#define ADCFILTER_CLT 210 -#define ADCFILTER_IAT 128 +#define ADCFILTER_CLT 180 +#define ADCFILTER_IAT 180 #define ADCFILTER_O2 128 #define ADCFILTER_BAT 128 diff --git a/reference/speeduino.ini b/reference/speeduino.ini index 1d4dcd3f..ca713dbd 100644 --- a/reference/speeduino.ini +++ b/reference/speeduino.ini @@ -62,7 +62,7 @@ endianness = little nPages = 8 burnCommand = "B" - blockReadTimeout = 500 + blockReadTimeout = 1000 pageSize = 288, 64, 288, 64, 288, 64, 64, 160 pageActivationDelay = 10 ; pageActivate = "" diff --git a/speeduino.ino b/speeduino.ino index 1c1199b4..b1aa296c 100644 --- a/speeduino.ino +++ b/speeduino.ino @@ -732,12 +732,14 @@ void loop() { currentStatus.TPSlast = currentStatus.TPS; currentStatus.TPSlast_time = currentStatus.TPS_time; + analogRead(pinTPS); byte tempTPS = fastMap1023toX(analogRead(pinTPS), 0, 1023, 0, 255); //Get the current raw TPS ADC value and map it into a byte currentStatus.tpsADC = ADC_FILTER(tempTPS, ADCFILTER_TPS, currentStatus.tpsADC); //Check that the ADC values fall within the min and max ranges (Should always be the case, but noise can cause these to fluctuate outside the defined range). - if (currentStatus.tpsADC < configPage1.tpsMin) { currentStatus.tpsADC = configPage1.tpsMin; } - else if(currentStatus.tpsADC > configPage1.tpsMax) { currentStatus.tpsADC = configPage1.tpsMax; } - currentStatus.TPS = map(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 + byte tempADC = currentStatus.tpsADC; //The tempADC value is used in order to allow TunerStudio to recover and redo the TPS calibration if this somehow gets corrupted + if (currentStatus.tpsADC < configPage1.tpsMin) { tempADC = configPage1.tpsMin; } + else if(currentStatus.tpsADC > configPage1.tpsMax) { tempADC = configPage1.tpsMax; } + currentStatus.TPS = map(tempADC, configPage1.tpsMin, configPage1.tpsMax, 0, 100); //Take the raw TPS ADC value and convert it into a TPS% based on the calibrated values currentStatus.TPS_time = currentLoopTime; //Check for launch in (clutch) can be done around here too @@ -750,15 +752,18 @@ void loop() if ((mainLoopCount & 255) == 1) { int tempReading; - + + tempReading = analogRead(pinCLT); tempReading = fastMap1023toX(analogRead(pinCLT), 0, 1023, 0, 511); //Get the current raw CLT value currentStatus.cltADC = ADC_FILTER(tempReading, ADCFILTER_CLT, currentStatus.cltADC); currentStatus.coolant = cltCalibrationTable[currentStatus.cltADC] - CALIBRATION_TEMPERATURE_OFFSET; //Temperature calibration values are stored as positive bytes. We subtract 40 from them to allow for negative temperatures + tempReading = analogRead(pinIAT); tempReading = map(analogRead(pinIAT), 0, 1023, 0, 511); //Get the current raw IAT value currentStatus.iatADC = ADC_FILTER(tempReading, ADCFILTER_IAT, currentStatus.iatADC); currentStatus.IAT = iatCalibrationTable[currentStatus.iatADC] - CALIBRATION_TEMPERATURE_OFFSET; + tempReading = analogRead(pinO2); tempReading = map(analogRead(pinO2), 0, 1023, 0, 511); //Get the current O2 value. currentStatus.O2ADC = ADC_FILTER(tempReading, ADCFILTER_O2, currentStatus.O2ADC); currentStatus.O2 = o2CalibrationTable[currentStatus.O2ADC]; @@ -769,6 +774,7 @@ void loop() currentStatus.O2_2 = o2CalibrationTable[currentStatus.O2_2ADC]; */ + tempReading = analogRead(pinBat); tempReading = fastMap1023toX(analogRead(pinBat), 0, 1023, 0, 245); //Get the current raw Battery value. Permissible values are from 0v to 24.5v (245) currentStatus.battery10 = ADC_FILTER(tempReading, ADCFILTER_BAT, currentStatus.battery10);