Speeduino
Loading...
Searching...
No Matches
Functions | Variables
corrections.cpp File Reference
#include "globals.h"
#include "corrections.h"
#include "speeduino.h"
#include "timers.h"
#include "maths.h"
#include "sensors.h"
#include "src/PID_v1/PID_v1.h"

Functions

void initialiseCorrections (void)
 
uint16_t correctionsFuel (void)
 
byte correctionWUE (void)
 
uint16_t correctionCranking (void)
 
byte correctionASE (void)
 
uint16_t correctionAccel (void)
 
byte correctionFloodClear (void)
 
byte correctionBatVoltage (void)
 
byte correctionIATDensity (void)
 
byte correctionBaro (void)
 
byte correctionLaunch (void)
 
byte correctionDFCOfuel (void)
 
bool correctionDFCO (void)
 
byte correctionFlex (void)
 
byte correctionFuelTemp (void)
 
uint8_t calculateAfrTarget (table3d16RpmLoad &afrLookUpTable, const statuses &current, const config2 &page2, const config6 &page6)
 
byte correctionAFRClosedLoop (void)
 
int8_t correctionsIgn (int8_t base_advance)
 
int8_t correctionFixedTiming (int8_t advance)
 
int8_t correctionCrankingFixedTiming (int8_t advance)
 
int8_t correctionFlexTiming (int8_t advance)
 
int8_t correctionWMITiming (int8_t advance)
 
int8_t correctionIATretard (int8_t advance)
 
int8_t correctionCLTadvance (int8_t advance)
 
int8_t correctionIdleAdvance (int8_t advance)
 
int8_t correctionSoftRevLimit (int8_t advance)
 
int8_t correctionNitrous (int8_t advance)
 
int8_t correctionSoftLaunch (int8_t advance)
 
int8_t correctionSoftFlatShift (int8_t advance)
 
uint8_t _calculateKnockRecovery (uint8_t curKnockRetard)
 
int8_t correctionKnockTiming (int8_t advance)
 
int8_t correctionDFCOignition (int8_t advance)
 
uint16_t correctionsDwell (uint16_t dwell)
 

Variables

long PID_O2
 
long PID_output
 
long PID_AFRTarget
 
byte activateMAPDOT
 
byte activateTPSDOT
 
bool idleAdvActive = false
 
uint16_t AFRnextCycle
 
unsigned long knockStartTime
 
uint8_t knockLastRecoveryStep
 
uint8_t aseTaper
 
uint8_t dfcoDelay
 
uint8_t idleAdvTaper
 
uint8_t crankingEnrichTaper
 
uint8_t dfcoTaper
 

Detailed Description

Corrections to injection pulsewidth. The corrections functions in this file affect the fuel pulsewidth (Either increasing or decreasing) based on factors other than the VE lookup.

These factors include:

Most correction functions return value 100 (like 100% == 1) for no need for correction.

There are 2 top level functions that call more detailed corrections for Fuel and Ignition respectively:

Function Documentation

◆ _calculateKnockRecovery()

uint8_t _calculateKnockRecovery ( uint8_t  curKnockRetard)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ calculateAfrTarget()

uint8_t calculateAfrTarget ( table3d16RpmLoad afrLookUpTable,
const statuses current,
const config2 page2,
const config6 page6 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionAccel()

uint16_t correctionAccel ( void  )

Acceleration enrichment correction calculation.

Calculates the % change of the throttle over time (%/second) and performs a lookup based on this Coolant-based modifier is applied on the top of this. When the enrichment is turned on, it runs at that amount for a fixed period of time (taeTime)

Returns
uint16_t The Acceleration enrichment modifier as a %. 100% = No modification.

As the maximum enrichment amount is +255% and maximum cold adjustment for this is 255%, the overall return value from this function can be 100+(255*255/100)=750. Hence this function returns a uint16_t rather than byte.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionAFRClosedLoop()

byte correctionAFRClosedLoop ( void  )

Lookup the AFR target table and perform either a simple or PID adjustment based on this.

Simple (Best suited to narrowband sensors): If the O2 sensor reports that the mixture is lean/rich compared to the desired AFR target, it will make a 1% adjustment It then waits egoDelta number of ignition events and compares O2 against the target table again. If it is still lean/rich then the adjustment is increased to 2%.

This continues until either:

  • the O2 reading flips from lean to rich, at which point the adjustment cycle starts again at 1% or
  • the adjustment amount increases to egoLimit at which point it stays at this level until the O2 state (rich/lean) changes

PID (Best suited to wideband sensors):

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionASE()

byte correctionASE ( void  )

After Start Enrichment calculation. This is a short period (Usually <20 seconds) immediately after the engine first fires (But not when cranking) where an additional amount of fuel is added (Over and above the WUE amount).

Returns
uint8_t The After Start Enrichment modifier as a %. 100% = No modification.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionBaro()

byte correctionBaro ( void  )

Correction for current barometric / ambient pressure.

Returns
A percentage value indicating the amount the fuelling should be changed based on the barometric reading. 100 = No change. 110 = 10% increase. 90 = 10% decrease
Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionBatVoltage()

byte correctionBatVoltage ( void  )

Battery Voltage correction. Uses a 2D enrichment table (WUETable) where the X axis is engine temp and the Y axis is the amount of extra fuel to add.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionCLTadvance()

int8_t correctionCLTadvance ( int8_t  advance)

Ignition correction for coolant temperature (CLT).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionCranking()

uint16_t correctionCranking ( void  )

Cranking Enrichment corrections. Additional fuel % to be added when the engine is cranking

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionCrankingFixedTiming()

int8_t correctionCrankingFixedTiming ( int8_t  advance)

Correct ignition timing to configured fixed value to use during craning. Must be called near end to override all other corrections.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionDFCO()

bool correctionDFCO ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionDFCOfuel()

byte correctionDFCOfuel ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionDFCOignition()

int8_t correctionDFCOignition ( int8_t  advance)

Ignition DFCO taper correction.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionFixedTiming()

int8_t correctionFixedTiming ( int8_t  advance)

Correct ignition timing to configured fixed value. Must be called near end to override all other corrections.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionFlex()

byte correctionFlex ( void  )

Flex fuel adjustment to vary fuel based on ethanol content. The amount of extra fuel required is a linear relationship based on the % of ethanol.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionFlexTiming()

int8_t correctionFlexTiming ( int8_t  advance)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionFloodClear()

byte correctionFloodClear ( void  )

Simple check to see whether we are cranking with the TPS above the flood clear threshold.

Returns
100 (not cranking and thus no need for flood-clear) or 0 (Engine cranking and TPS above config4::floodClear limit).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionFuelTemp()

byte correctionFuelTemp ( void  )
Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionIATDensity()

byte correctionIATDensity ( void  )

Simple temperature based corrections lookup based on the inlet air temperature (IAT). This corrects for changes in air density from movement of the temperature.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionIATretard()

int8_t correctionIATretard ( int8_t  advance)

Ignition correction for inlet air temperature (IAT).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionIdleAdvance()

int8_t correctionIdleAdvance ( int8_t  advance)

Ignition Idle advance correction.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionKnockTiming()

int8_t correctionKnockTiming ( int8_t  advance)

Ignition knock (retard) correction.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionLaunch()

byte correctionLaunch ( void  )

Launch control has a setting to increase the fuel load to assist in bringing up boost. This simple check applies the extra fuel if we're currently launching

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionNitrous()

int8_t correctionNitrous ( int8_t  advance)

Ignition Nitrous oxide correction.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionsDwell()

uint16_t correctionsDwell ( uint16_t  dwell)

Ignition Dwell Correction.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionsFuel()

uint16_t correctionsFuel ( void  )

Dispatch calculations for all fuel related corrections. Calls all the other corrections functions and combines their results. This is the only function that should be called from anywhere outside the file

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionsIgn()

int8_t correctionsIgn ( int8_t  base_advance)

Dispatch calculations for all ignition related corrections.

Parameters
base_advance- Base ignition advance (deg. ?)
Returns
Advance considering all (~12) individual corrections
Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionSoftFlatShift()

int8_t correctionSoftFlatShift ( int8_t  advance)

Ignition correction for soft flat shift.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionSoftLaunch()

int8_t correctionSoftLaunch ( int8_t  advance)

Ignition soft launch correction.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionSoftRevLimit()

int8_t correctionSoftRevLimit ( int8_t  advance)

Ignition soft revlimit correction.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionWMITiming()

int8_t correctionWMITiming ( int8_t  advance)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ correctionWUE()

byte correctionWUE ( void  )

Warm Up Enrichment (WUE) corrections. Uses a 2D enrichment table (WUETable) where the X axis is engine temp and the Y axis is the amount of extra fuel to add

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initialiseCorrections()

void initialiseCorrections ( void  )

Initialise instances and vars related to corrections (at ECU boot-up).

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ activateMAPDOT

byte activateMAPDOT

◆ activateTPSDOT

byte activateTPSDOT

◆ AFRnextCycle

uint16_t AFRnextCycle

◆ aseTaper

uint8_t aseTaper

◆ crankingEnrichTaper

uint8_t crankingEnrichTaper

◆ dfcoDelay

uint8_t dfcoDelay

◆ dfcoTaper

uint8_t dfcoTaper

◆ idleAdvActive

bool idleAdvActive = false

◆ idleAdvTaper

uint8_t idleAdvTaper

◆ knockLastRecoveryStep

uint8_t knockLastRecoveryStep

◆ knockStartTime

unsigned long knockStartTime

◆ PID_AFRTarget

long PID_AFRTarget

◆ PID_O2

PID egoPID & PID_O2

Instance of the PID object in case that algorithm is used (Always instantiated). Needs to be global as it maintains state outside of each function call. Comes from Arduino (?) PID library.

◆ PID_output

long PID_output