Movement of all sensor reads into their own file
This commit is contained in:
parent
c6bbfc72ec
commit
69ed610d76
55
sensors.ino
55
sensors.ino
|
@ -3,11 +3,11 @@ Speeduino - Simple engine management for the Arduino Mega 2560 platform
|
||||||
Copyright (C) Josh Stewart
|
Copyright (C) Josh Stewart
|
||||||
A full copy of the license may be found in the projects root directory
|
A full copy of the license may be found in the projects root directory
|
||||||
*/
|
*/
|
||||||
|
int tempReading;
|
||||||
|
|
||||||
void instanteneousMAPReading()
|
void instanteneousMAPReading()
|
||||||
{
|
{
|
||||||
//Instantaneous MAP readings
|
//Instantaneous MAP readings
|
||||||
int tempReading;
|
|
||||||
tempReading = analogRead(pinMAP);
|
tempReading = analogRead(pinMAP);
|
||||||
tempReading = analogRead(pinMAP);
|
tempReading = analogRead(pinMAP);
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ void instanteneousMAPReading()
|
||||||
void readMAP()
|
void readMAP()
|
||||||
{
|
{
|
||||||
//MAP Sampling system
|
//MAP Sampling system
|
||||||
int tempReading;
|
|
||||||
switch(configPage1.mapSample)
|
switch(configPage1.mapSample)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
|
@ -87,3 +86,55 @@ void readMAP()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void readTPS()
|
||||||
|
{
|
||||||
|
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).
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void readCLT()
|
||||||
|
{
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
void readIAT()
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void readO2()
|
||||||
|
{
|
||||||
|
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];
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Second O2 currently disabled as its not being used
|
||||||
|
currentStatus.O2_2ADC = map(analogRead(pinO2_2), 0, 1023, 0, 511); //Get the current O2 value.
|
||||||
|
currentStatus.O2_2ADC = ADC_FILTER(tempReading, ADCFILTER_O2, currentStatus.O2_2ADC);
|
||||||
|
currentStatus.O2_2 = o2CalibrationTable[currentStatus.O2_2ADC];
|
||||||
|
*/
|
||||||
|
|
||||||
|
void readBat()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,6 +137,8 @@ volatile bool fpPrimed = false; //Tracks whether or not the fuel pump priming ha
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
Serial.begin(115200);
|
||||||
|
|
||||||
//Setup the dummy fuel and ignition tables
|
//Setup the dummy fuel and ignition tables
|
||||||
//dummyFuelTable(&fuelTable);
|
//dummyFuelTable(&fuelTable);
|
||||||
//dummyIgnitionTable(&ignitionTable);
|
//dummyIgnitionTable(&ignitionTable);
|
||||||
|
@ -415,7 +417,7 @@ void setup()
|
||||||
previousLoopTime = 0;
|
previousLoopTime = 0;
|
||||||
currentLoopTime = micros();
|
currentLoopTime = micros();
|
||||||
|
|
||||||
Serial.begin(115200);
|
|
||||||
|
|
||||||
//This sets the ADC (Analog to Digitial Converter) to run at 1Mhz, greatly reducing analog read times (MAP/TPS)
|
//This sets the ADC (Analog to Digitial Converter) to run at 1Mhz, greatly reducing analog read times (MAP/TPS)
|
||||||
//1Mhz is the fastest speed permitted by the CPU without affecting accuracy
|
//1Mhz is the fastest speed permitted by the CPU without affecting accuracy
|
||||||
|
@ -485,7 +487,7 @@ void setup()
|
||||||
channel1InjDegrees = 0;
|
channel1InjDegrees = 0;
|
||||||
channel2InjDegrees = 180;
|
channel2InjDegrees = 180;
|
||||||
}
|
}
|
||||||
else if (configPage1.injTiming == INJ_SEQUENTIAL)
|
else if (useSequentialFuel)
|
||||||
{
|
{
|
||||||
channel1InjDegrees = 0;
|
channel1InjDegrees = 0;
|
||||||
channel2InjDegrees = 180;
|
channel2InjDegrees = 180;
|
||||||
|
@ -668,19 +670,9 @@ void loop()
|
||||||
//TPS setting to be performed every 32 loops (any faster and it can upset the TPSdot sampling time)
|
//TPS setting to be performed every 32 loops (any faster and it can upset the TPSdot sampling time)
|
||||||
if ((mainLoopCount & 31) == 1)
|
if ((mainLoopCount & 31) == 1)
|
||||||
{
|
{
|
||||||
currentStatus.TPSlast = currentStatus.TPS;
|
readTPS();
|
||||||
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).
|
|
||||||
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
|
//Check for launching (clutch) can be done around here too
|
||||||
currentStatus.launching = !digitalRead(pinLaunch);
|
currentStatus.launching = !digitalRead(pinLaunch);
|
||||||
//And check whether the tooth log buffer is ready
|
//And check whether the tooth log buffer is ready
|
||||||
if(toothHistoryIndex > TOOTH_LOG_SIZE) { BIT_SET(currentStatus.squirt, BIT_SQUIRT_TOOTHLOG1READY); }
|
if(toothHistoryIndex > TOOTH_LOG_SIZE) { BIT_SET(currentStatus.squirt, BIT_SQUIRT_TOOTHLOG1READY); }
|
||||||
|
@ -689,33 +681,11 @@ void loop()
|
||||||
//The IAT and CLT readings can be done less frequently. This still runs about 4 times per second
|
//The IAT and CLT readings can be done less frequently. This still runs about 4 times per second
|
||||||
if ((mainLoopCount & 255) == 1)
|
if ((mainLoopCount & 255) == 1)
|
||||||
{
|
{
|
||||||
int tempReading;
|
|
||||||
|
|
||||||
tempReading = analogRead(pinCLT);
|
readCLT();
|
||||||
tempReading = fastMap1023toX(analogRead(pinCLT), 0, 1023, 0, 511); //Get the current raw CLT value
|
readIAT();
|
||||||
currentStatus.cltADC = ADC_FILTER(tempReading, ADCFILTER_CLT, currentStatus.cltADC);
|
readO2();
|
||||||
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
|
readBat();
|
||||||
|
|
||||||
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];
|
|
||||||
|
|
||||||
/* Second O2 currently disabled as its not being used
|
|
||||||
currentStatus.O2_2ADC = map(analogRead(pinO2_2), 0, 1023, 0, 511); //Get the current O2 value.
|
|
||||||
currentStatus.O2_2ADC = ADC_FILTER(tempReading, ADCFILTER_O2, currentStatus.O2_2ADC);
|
|
||||||
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);
|
|
||||||
|
|
||||||
|
|
||||||
vvtControl();
|
vvtControl();
|
||||||
boostControl(); //Most boost tends to run at about 30Hz, so placing it here ensures a new target time is fetched frequently enough
|
boostControl(); //Most boost tends to run at about 30Hz, so placing it here ensures a new target time is fetched frequently enough
|
||||||
|
|
Loading…
Reference in New Issue