Move the pulse width function into the speeduino.h scope
This commit is contained in:
parent
543b33c774
commit
6a8ab1015b
|
@ -2173,8 +2173,6 @@ cmdtestspk450dc = "E\x03\x0C"
|
||||||
indicator = { boostCutOut }, "Ign Cut OFF", "Ign Cut (Boost)", white, black, red, black
|
indicator = { boostCutOut }, "Ign Cut OFF", "Ign Cut (Boost)", white, black, red, black
|
||||||
indicator = { sync }, "No Sync", "Sync", white, black, green, black
|
indicator = { sync }, "No Sync", "Sync", white, black, green, black
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;-------------------------------------------------------------------------------
|
;-------------------------------------------------------------------------------
|
||||||
|
|
||||||
[OutputChannels]
|
[OutputChannels]
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef SPEEDUINO_H
|
||||||
|
#define SPEEDUINO_H
|
||||||
|
|
||||||
|
static inline unsigned int PW(int REQ_FUEL, byte VE, long MAP, int corrections, int injOpen) __attribute__((always_inline));
|
||||||
|
|
||||||
|
#endif
|
|
@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
//https://developer.mbed.org/handbook/C-Data-Types
|
//https://developer.mbed.org/handbook/C-Data-Types
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
//************************************************
|
//************************************************
|
||||||
|
#include "speeduino.h"
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "table.h"
|
#include "table.h"
|
||||||
|
@ -910,17 +911,16 @@ void loop()
|
||||||
{
|
{
|
||||||
//Speed Density
|
//Speed Density
|
||||||
currentStatus.VE = get3DTableValue(&fuelTable, currentStatus.MAP, currentStatus.RPM); //Perform lookup into fuel map for RPM vs MAP value
|
currentStatus.VE = get3DTableValue(&fuelTable, currentStatus.MAP, currentStatus.RPM); //Perform lookup into fuel map for RPM vs MAP value
|
||||||
currentStatus.PW1 = PW_SD(req_fuel_uS, currentStatus.VE, currentStatus.MAP, currentStatus.corrections, inj_opentime_uS);
|
|
||||||
currentStatus.advance = get3DTableValue(&ignitionTable, currentStatus.MAP, currentStatus.RPM) - OFFSET_IGNITION; //As above, but for ignition advance
|
currentStatus.advance = get3DTableValue(&ignitionTable, currentStatus.MAP, currentStatus.RPM) - OFFSET_IGNITION; //As above, but for ignition advance
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//Alpha-N
|
//Alpha-N
|
||||||
currentStatus.VE = get3DTableValue(&fuelTable, currentStatus.TPS, currentStatus.RPM); //Perform lookup into fuel map for RPM vs TPS value
|
currentStatus.VE = get3DTableValue(&fuelTable, currentStatus.TPS, currentStatus.RPM); //Perform lookup into fuel map for RPM vs TPS value
|
||||||
currentStatus.PW1 = PW_AN(req_fuel_uS, currentStatus.VE, currentStatus.TPS, currentStatus.corrections, inj_opentime_uS); //Calculate pulsewidth using the Alpha-N algorithm (in uS)
|
|
||||||
currentStatus.advance = get3DTableValue(&ignitionTable, currentStatus.TPS, currentStatus.RPM) - OFFSET_IGNITION; //As above, but for ignition advance
|
currentStatus.advance = get3DTableValue(&ignitionTable, currentStatus.TPS, currentStatus.RPM) - OFFSET_IGNITION; //As above, but for ignition advance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentStatus.PW1 = PW(req_fuel_uS, currentStatus.VE, currentStatus.MAP, currentStatus.corrections, inj_opentime_uS);
|
||||||
currentStatus.advance = correctionsIgn(currentStatus.advance);
|
currentStatus.advance = correctionsIgn(currentStatus.advance);
|
||||||
|
|
||||||
int injector1StartAngle = 0;
|
int injector1StartAngle = 0;
|
||||||
|
@ -1356,6 +1356,11 @@ void loop()
|
||||||
ign1EndFunction
|
ign1EndFunction
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if(ignition1EndAngle > crankAngle && configPage2.StgCycles == 0)
|
||||||
|
{
|
||||||
|
unsigned long uSToEnd = degreesToUS( (ignition1EndAngle - crankAngle) );
|
||||||
|
//refreshIgnitionSchedule1( uSToEnd + fixedCrankingOverride );
|
||||||
|
}
|
||||||
|
|
||||||
tempCrankAngle = crankAngle - channel2IgnDegrees;
|
tempCrankAngle = crankAngle - channel2IgnDegrees;
|
||||||
if( tempCrankAngle < 0) { tempCrankAngle += CRANK_ANGLE_MAX_IGN; }
|
if( tempCrankAngle < 0) { tempCrankAngle += CRANK_ANGLE_MAX_IGN; }
|
||||||
|
@ -1443,3 +1448,51 @@ void loop()
|
||||||
} //Ignition schedules on
|
} //Ignition schedules on
|
||||||
} //Has sync and RPM
|
} //Has sync and RPM
|
||||||
} //loop()
|
} //loop()
|
||||||
|
|
||||||
|
/*
|
||||||
|
This function retuns a pulsewidth time (in us) given the following:
|
||||||
|
REQ_FUEL
|
||||||
|
VE: Lookup from the main fuel table. This can either have been MAP or TPS based, depending on the algorithm used
|
||||||
|
MAP: In KPa, read from the sensor (This is used when performing a multiply of the map only. It is applicable in both Speed density and Alpha-N)
|
||||||
|
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)
|
||||||
|
*/
|
||||||
|
static inline unsigned int PW(int REQ_FUEL, byte VE, long MAP, int corrections, int injOpen)
|
||||||
|
{
|
||||||
|
//Standard float version of the calculation
|
||||||
|
//return (REQ_FUEL * (float)(VE/100.0) * (float)(MAP/100.0) * (float)(TPS/100.0) * (float)(corrections/100.0) + injOpen);
|
||||||
|
//Note: The MAP and TPS portions are currently disabled, we use VE and corrections only
|
||||||
|
uint16_t iVE, iCorrections;
|
||||||
|
uint16_t iMAP = 100;
|
||||||
|
uint16_t iAFR = 147;
|
||||||
|
|
||||||
|
//100% float free version, does sacrifice a little bit of accuracy, but not much.
|
||||||
|
iVE = ((unsigned int)VE << 7) / 100;
|
||||||
|
if ( configPage1.multiplyMAP == true ) {
|
||||||
|
iMAP = ((unsigned int)MAP << 7) / currentStatus.baro; //Include multiply MAP (vs baro) if enabled
|
||||||
|
}
|
||||||
|
if ( (configPage1.includeAFR == true) && (configPage3.egoType == 2)) {
|
||||||
|
iAFR = ((unsigned int)currentStatus.O2 << 7) / currentStatus.afrTarget; //Include AFR (vs target) if enabled
|
||||||
|
}
|
||||||
|
iCorrections = (corrections << 7) / 100;
|
||||||
|
|
||||||
|
|
||||||
|
unsigned long intermediate = ((long)REQ_FUEL * (long)iVE) >> 7; //Need to use an intermediate value to avoid overflowing the long
|
||||||
|
if ( configPage1.multiplyMAP == true ) {
|
||||||
|
intermediate = (intermediate * (unsigned long)iMAP) >> 7;
|
||||||
|
}
|
||||||
|
if ( (configPage1.includeAFR == true) && (configPage3.egoType == 2) ) {
|
||||||
|
intermediate = (intermediate * (unsigned long)iAFR) >> 7; //EGO type must be set to wideband for this to be used
|
||||||
|
}
|
||||||
|
intermediate = (intermediate * (unsigned long)iCorrections) >> 7;
|
||||||
|
if (intermediate != 0)
|
||||||
|
{
|
||||||
|
//If intermeditate is not 0, we need to add the opening time (0 typically indicates that one of the full fuel cuts is active)
|
||||||
|
intermediate += injOpen; //Add the injector opening time
|
||||||
|
if ( intermediate > 65535)
|
||||||
|
{
|
||||||
|
intermediate = 65535; //Make sure this won't overflow when we convert to uInt. This means the maximum pulsewidth possible is 65.535mS
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (unsigned int)(intermediate);
|
||||||
|
}
|
||||||
|
|
|
@ -8,9 +8,6 @@ These are some utility functions and variables used through the main code
|
||||||
|
|
||||||
uint16_t freeRam ();
|
uint16_t freeRam ();
|
||||||
void setPinMapping(byte boardID);
|
void setPinMapping(byte boardID);
|
||||||
unsigned int PW();
|
|
||||||
unsigned int PW_SD();
|
|
||||||
unsigned int PW_AN();
|
|
||||||
|
|
||||||
//This is dumb, but it'll do for now to get things compiling
|
//This is dumb, but it'll do for now to get things compiling
|
||||||
#if defined(CORE_STM32)
|
#if defined(CORE_STM32)
|
||||||
|
|
|
@ -824,66 +824,3 @@ void initialiseTriggers()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
This function retuns a pulsewidth time (in us) using a either Alpha-N or Speed Density algorithms, given the following:
|
|
||||||
REQ_FUEL
|
|
||||||
VE: Lookup from the main MAP vs RPM fuel table
|
|
||||||
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)
|
|
||||||
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%)
|
|
||||||
|
|
||||||
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, long MAP, int corrections, int injOpen)
|
|
||||||
{
|
|
||||||
//Standard float version of the calculation
|
|
||||||
//return (REQ_FUEL * (float)(VE/100.0) * (float)(MAP/100.0) * (float)(TPS/100.0) * (float)(corrections/100.0) + injOpen);
|
|
||||||
//Note: The MAP and TPS portions are currently disabled, we use VE and corrections only
|
|
||||||
uint16_t iVE, iCorrections;
|
|
||||||
uint16_t iMAP = 100;
|
|
||||||
uint16_t iAFR = 147;
|
|
||||||
|
|
||||||
//100% float free version, does sacrifice a little bit of accuracy, but not much.
|
|
||||||
iVE = ((unsigned int)VE << 7) / 100;
|
|
||||||
if ( configPage1.multiplyMAP == true ) {
|
|
||||||
iMAP = ((unsigned int)MAP << 7) / currentStatus.baro; //Include multiply MAP (vs baro) if enabled
|
|
||||||
}
|
|
||||||
if ( (configPage1.includeAFR == true) && (configPage3.egoType == 2)) {
|
|
||||||
iAFR = ((unsigned int)currentStatus.O2 << 7) / currentStatus.afrTarget; //Include AFR (vs target) if enabled
|
|
||||||
}
|
|
||||||
iCorrections = (corrections << 7) / 100;
|
|
||||||
|
|
||||||
|
|
||||||
unsigned long intermediate = ((long)REQ_FUEL * (long)iVE) >> 7; //Need to use an intermediate value to avoid overflowing the long
|
|
||||||
if ( configPage1.multiplyMAP == true ) {
|
|
||||||
intermediate = (intermediate * (unsigned long)iMAP) >> 7;
|
|
||||||
}
|
|
||||||
if ( (configPage1.includeAFR == true) && (configPage3.egoType == 2) ) {
|
|
||||||
intermediate = (intermediate * (unsigned long)iAFR) >> 7; //EGO type must be set to wideband for this to be used
|
|
||||||
}
|
|
||||||
intermediate = (intermediate * (unsigned long)iCorrections) >> 7;
|
|
||||||
if (intermediate != 0)
|
|
||||||
{
|
|
||||||
//If intermeditate is not 0, we need to add the opening time (0 typically indicates that one of the full fuel cuts is active)
|
|
||||||
intermediate += injOpen; //Add the injector opening time
|
|
||||||
if ( intermediate > 65535)
|
|
||||||
{
|
|
||||||
intermediate = 65535; //Make sure this won't overflow when we convert to uInt. This means the maximum pulsewidth possible is 65.535mS
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (unsigned int)(intermediate);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//Convenience functions for Speed Density and Alpha-N
|
|
||||||
unsigned int PW_SD(int REQ_FUEL, byte VE, long MAP, int corrections, int injOpen)
|
|
||||||
{
|
|
||||||
return PW(REQ_FUEL, VE, MAP, corrections, injOpen);
|
|
||||||
//return PW(REQ_FUEL, VE, 100, corrections, injOpen);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int PW_AN(int REQ_FUEL, byte VE, byte TPS, int corrections, int injOpen)
|
|
||||||
{
|
|
||||||
return PW(REQ_FUEL, VE, currentStatus.MAP, corrections, injOpen);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue