From a90d13b038b92a827b782929e2b784bdf461fd0a Mon Sep 17 00:00:00 2001 From: Josh Stewart Date: Mon, 27 Jun 2016 10:31:52 +1000 Subject: [PATCH] Improved flex error checking --- comms.ino | 3 ++- reference/speeduino.ini | 2 +- timers.ino | 20 ++++++++++++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/comms.ino b/comms.ino index 23a7d2e5..d3d0e368 100644 --- a/comms.ino +++ b/comms.ino @@ -262,7 +262,8 @@ void sendValues(int length) response[31] = lowByte(currentStatus.rpmDOT); response[32] = highByte(currentStatus.rpmDOT); - response[33] = currentStatus.flex; + response[33] = currentStatus.flex; //Flex sensor value (or 0 if not used) + cli(); Serial.write(response, (size_t)packetSize); sei(); diff --git a/reference/speeduino.ini b/reference/speeduino.ini index fde69ba0..cd5cecd9 100644 --- a/reference/speeduino.ini +++ b/reference/speeduino.ini @@ -465,7 +465,7 @@ page = 8 requiresPowerCycle = launchPin requiresPowerCycle = launchEnable requiresPowerCycle = launchHiLo -; requiresPowerCycle = flexEnabled + requiresPowerCycle = flexEnabled defaultValue = pinLayout, 1 defaultValue = TrigPattern, 0 diff --git a/timers.ino b/timers.ino index 00fa8dd2..424fa609 100644 --- a/timers.ino +++ b/timers.ino @@ -99,9 +99,25 @@ void timer2Overflowinterrupt() //Most ARM chips can simply call a function //Set the flex reading (if enabled). The flexCounter is updated with every pulse from the sensor. If cleared once per second, we get a frequency reading if(configPage1.flexEnabled) { - if(flexCounter > 150 || flexCounter < 50) + if(flexCounter < 50) { - //This indicated an error condition. Spec of the sensor is that errors are above 170Hz) + currentStatus.flex = 0; //Standard GM Continental sensor reads from 50Hz (0 ethanol) to 150Hz (Pure ethanol). Subtracting 50 from the frequency therefore gives the ethanol percentage. + flexCounter = 0; + } + else if (flexCounter > 151) //1 pulse buffer + { + + if(flexCounter < 169) + { + currentStatus.flex = 100; //Standard GM Continental sensor reads from 50Hz (0 ethanol) to 150Hz (Pure ethanol). Subtracting 50 from the frequency therefore gives the ethanol percentage. + flexCounter = 0; + } + else + { + //This indicates an error condition. Spec of the sensor is that errors are above 170Hz) + currentStatus.flex = 0; + flexCounter = 0; + } } else {