mirror of https://github.com/rusefi/speeduino.git
Some default pin mappings for VVT and Boost
This commit is contained in:
parent
770da8b43e
commit
dfab13631a
94
utils.ino
94
utils.ino
|
@ -1,12 +1,12 @@
|
||||||
/*
|
/*
|
||||||
Speeduino - Simple engine management for the Arduino Mega 2560 platform
|
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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Returns how much free dynamic memory exists (between heap and stack)
|
Returns how much free dynamic memory exists (between heap and stack)
|
||||||
*/
|
*/
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
@ -118,7 +118,9 @@ void setPinMapping(byte boardID)
|
||||||
pinDisplayReset = 48; // OLED reset pin
|
pinDisplayReset = 48; // OLED reset pin
|
||||||
pinTachOut = 49; //Tacho output pin
|
pinTachOut = 49; //Tacho output pin
|
||||||
pinIdle1 = 5; //Single wire idle control
|
pinIdle1 = 5; //Single wire idle control
|
||||||
pinIdle2 = 7; //2 wire idle control
|
pinIdle2 = 6; //2 wire idle control
|
||||||
|
pinBoost = 7; //Boost control
|
||||||
|
pinVVT = 4; //Default VVT output
|
||||||
pinFuelPump = 4; //Fuel pump output
|
pinFuelPump = 4; //Fuel pump output
|
||||||
pinStepperDir = 16; //Direction pin for DRV8825 driver
|
pinStepperDir = 16; //Direction pin for DRV8825 driver
|
||||||
pinStepperStep = 17; //Step pin for DRV8825 driver
|
pinStepperStep = 17; //Step pin for DRV8825 driver
|
||||||
|
@ -150,7 +152,9 @@ void setPinMapping(byte boardID)
|
||||||
pinDisplayReset = 48; // OLED reset pin
|
pinDisplayReset = 48; // OLED reset pin
|
||||||
pinTachOut = 49; //Tacho output pin (Goes to ULN2803)
|
pinTachOut = 49; //Tacho output pin (Goes to ULN2803)
|
||||||
pinIdle1 = 5; //Single wire idle control
|
pinIdle1 = 5; //Single wire idle control
|
||||||
pinIdle2 = 7; //2 wire idle control (Note this is shared with boost!!!)
|
pinIdle2 = 6; //2 wire idle control
|
||||||
|
pinBoost = 7; //Boost control
|
||||||
|
pinVVT = 4; //Default VVT output
|
||||||
pinFuelPump = 45; //Fuel pump output (Goes to ULN2803)
|
pinFuelPump = 45; //Fuel pump output (Goes to ULN2803)
|
||||||
pinStepperDir = 16; //Direction pin for DRV8825 driver
|
pinStepperDir = 16; //Direction pin for DRV8825 driver
|
||||||
pinStepperStep = 17; //Step pin for DRV8825 driver
|
pinStepperStep = 17; //Step pin for DRV8825 driver
|
||||||
|
@ -326,13 +330,27 @@ void setPinMapping(byte boardID)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Setup any devices that are using selectable pins
|
//Setup any devices that are using selectable pins
|
||||||
if(configPage3.launchPin != 0) { pinLaunch = configPage3.launchPin; }
|
if (configPage3.launchPin != 0) {
|
||||||
if(configPage2.ignBypassPin != 0) { pinIgnBypass = configPage2.ignBypassPin; }
|
pinLaunch = configPage3.launchPin;
|
||||||
if(configPage1.tachoPin != 0) { pinTachOut = configPage1.tachoPin; }
|
}
|
||||||
if(configPage2.fuelPumpPin != 0) { pinFuelPump = configPage2.fuelPumpPin; }
|
if (configPage2.ignBypassPin != 0) {
|
||||||
if(configPage4.fanPin != 0) { pinFan = configPage4.fanPin; }
|
pinIgnBypass = configPage2.ignBypassPin;
|
||||||
if(configPage3.boostPin != 0) { pinBoost = configPage3.boostPin; }
|
}
|
||||||
if(configPage3.vvtPin != 0) { pinVVT_1 = configPage3.vvtPin; }
|
if (configPage1.tachoPin != 0) {
|
||||||
|
pinTachOut = configPage1.tachoPin;
|
||||||
|
}
|
||||||
|
if (configPage2.fuelPumpPin != 0) {
|
||||||
|
pinFuelPump = configPage2.fuelPumpPin;
|
||||||
|
}
|
||||||
|
if (configPage4.fanPin != 0) {
|
||||||
|
pinFan = configPage4.fanPin;
|
||||||
|
}
|
||||||
|
if (configPage3.boostPin != 0) {
|
||||||
|
pinBoost = configPage3.boostPin;
|
||||||
|
}
|
||||||
|
if (configPage3.vvtPin != 0) {
|
||||||
|
pinVVT_1 = configPage3.vvtPin;
|
||||||
|
}
|
||||||
|
|
||||||
//Finally, set the relevant pin modes for outputs
|
//Finally, set the relevant pin modes for outputs
|
||||||
pinMode(pinCoil1, OUTPUT);
|
pinMode(pinCoil1, OUTPUT);
|
||||||
|
@ -391,9 +409,13 @@ void setPinMapping(byte boardID)
|
||||||
pinMode(pinTrigger2, INPUT);
|
pinMode(pinTrigger2, INPUT);
|
||||||
pinMode(pinTrigger3, INPUT);
|
pinMode(pinTrigger3, INPUT);
|
||||||
pinMode(pinFlex, INPUT_PULLUP); //Standard GM / Continental flex sensor requires pullup
|
pinMode(pinFlex, INPUT_PULLUP); //Standard GM / Continental flex sensor requires pullup
|
||||||
// pinMode(pinLaunch, INPUT_PULLUP); //This should work for both NO and NC grounding switches
|
// pinMode(pinLaunch, INPUT_PULLUP); //This should work for both NO and NC grounding switches
|
||||||
if (configPage3.lnchPullRes) { pinMode(pinLaunch, INPUT_PULLUP); }
|
if (configPage3.lnchPullRes) {
|
||||||
else { pinMode(pinLaunch, INPUT); } //If Launch Pull Resistor is not set make input float.
|
pinMode(pinLaunch, INPUT_PULLUP);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pinMode(pinLaunch, INPUT); //If Launch Pull Resistor is not set make input float.
|
||||||
|
}
|
||||||
|
|
||||||
//Set default values
|
//Set default values
|
||||||
digitalWrite(pinMAP, HIGH);
|
digitalWrite(pinMAP, HIGH);
|
||||||
|
@ -402,15 +424,15 @@ void setPinMapping(byte boardID)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
This function retuns a pulsewidth time (in us) using a either Alpha-N or Speed Density algorithms, given the following:
|
This function retuns a pulsewidth time (in us) using a either Alpha-N or Speed Density algorithms, given the following:
|
||||||
REQ_FUEL
|
REQ_FUEL
|
||||||
VE: Lookup from the main MAP vs RPM fuel table
|
VE: Lookup from the main MAP vs RPM fuel table
|
||||||
MAP: In KPa, read from the sensor
|
MAP: In KPa, read from the sensor
|
||||||
GammaE: Sum of Enrichment factors (Cold start, acceleration). This is a multiplication factor (Eg to add 10%, this should be 110)
|
GammaE: Sum of Enrichment factors (Cold start, acceleration). This is a multiplication factor (Eg to add 10%, this should be 110)
|
||||||
injDT: Injector dead time. The time the injector take to open minus the time it takes to close (Both in uS)
|
injDT: Injector dead time. The time the injector take to open minus the time it takes to close (Both in uS)
|
||||||
TPS: Throttle position (0% to 100%)
|
TPS: Throttle position (0% to 100%)
|
||||||
|
|
||||||
This function is called by PW_SD and PW_AN for speed0density and pure Alpha-N calculations respectively.
|
This function is called by PW_SD and PW_AN for speed0density and pure Alpha-N calculations respectively.
|
||||||
*/
|
*/
|
||||||
unsigned int PW(int REQ_FUEL, byte VE, byte MAP, int corrections, int injOpen)
|
unsigned int PW(int REQ_FUEL, byte VE, byte MAP, int corrections, int injOpen)
|
||||||
{
|
{
|
||||||
|
@ -421,16 +443,26 @@ unsigned int PW(int REQ_FUEL, byte VE, byte MAP, int corrections, int injOpen)
|
||||||
|
|
||||||
//100% float free version, does sacrifice a little bit of accuracy, but not much.
|
//100% float free version, does sacrifice a little bit of accuracy, but not much.
|
||||||
iVE = ((unsigned int)VE << 7) / 100;
|
iVE = ((unsigned int)VE << 7) / 100;
|
||||||
if( configPage1.multiplyMAP ) { iMAP = ((unsigned int)MAP << 7) / currentStatus.baro; } //Include multiply MAP (vs baro) if enabled
|
if ( configPage1.multiplyMAP ) {
|
||||||
if( configPage1.includeAFR && (configPage3.egoType == 2)) { iAFR = ((unsigned int)currentStatus.O2 << 7) / currentStatus.afrTarget; } //Include AFR (vs target) if enabled
|
iMAP = ((unsigned int)MAP << 7) / currentStatus.baro; //Include multiply MAP (vs baro) if enabled
|
||||||
|
}
|
||||||
|
if ( configPage1.includeAFR && (configPage3.egoType == 2)) {
|
||||||
|
iAFR = ((unsigned int)currentStatus.O2 << 7) / currentStatus.afrTarget; //Include AFR (vs target) if enabled
|
||||||
|
}
|
||||||
iCorrections = (corrections << 7) / 100;
|
iCorrections = (corrections << 7) / 100;
|
||||||
|
|
||||||
|
|
||||||
unsigned long intermediate = ((long)REQ_FUEL * (long)iVE) >> 7; //Need to use an intermediate value to avoid overflowing the long
|
unsigned long intermediate = ((long)REQ_FUEL * (long)iVE) >> 7; //Need to use an intermediate value to avoid overflowing the long
|
||||||
if( configPage1.multiplyMAP ) { intermediate = (intermediate * iMAP) >> 7; }
|
if ( configPage1.multiplyMAP ) {
|
||||||
if( configPage1.includeAFR && (configPage3.egoType == 2)) { intermediate = (intermediate * iAFR) >> 7; } //EGO type must be set to wideband for this to be used
|
intermediate = (intermediate * iMAP) >> 7;
|
||||||
|
}
|
||||||
|
if ( configPage1.includeAFR && (configPage3.egoType == 2)) {
|
||||||
|
intermediate = (intermediate * iAFR) >> 7; //EGO type must be set to wideband for this to be used
|
||||||
|
}
|
||||||
intermediate = (intermediate * iCorrections) >> 7;
|
intermediate = (intermediate * iCorrections) >> 7;
|
||||||
if(intermediate == 0) { return 0; } //If the pulsewidth is 0, we return here before the opening time gets added
|
if (intermediate == 0) {
|
||||||
|
return 0; //If the pulsewidth is 0, we return here before the opening time gets added
|
||||||
|
}
|
||||||
|
|
||||||
intermediate += injOpen; //Add the injector opening time
|
intermediate += injOpen; //Add the injector opening time
|
||||||
if ( intermediate > 65535) {
|
if ( intermediate > 65535) {
|
||||||
|
@ -450,6 +482,8 @@ unsigned int PW_SD(int REQ_FUEL, byte VE, byte MAP, int corrections, int injOpen
|
||||||
unsigned int PW_AN(int REQ_FUEL, byte VE, byte TPS, int corrections, int injOpen)
|
unsigned int PW_AN(int REQ_FUEL, byte VE, byte TPS, int corrections, int injOpen)
|
||||||
{
|
{
|
||||||
//Sanity check
|
//Sanity check
|
||||||
if(TPS > 100) { TPS = 100; }
|
if (TPS > 100) {
|
||||||
|
TPS = 100;
|
||||||
|
}
|
||||||
return PW(REQ_FUEL, VE, currentStatus.MAP, corrections, injOpen);
|
return PW(REQ_FUEL, VE, currentStatus.MAP, corrections, injOpen);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue