![]() |
Speeduino
|
#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"Variables | |
| long | PID_O2 |
| long | PID_output |
| long | PID_AFRTarget |
| byte | activateMAPDOT |
| byte | activateTPSDOT |
| bool | idleAdvActive = false |
| uint16_t | AFRnextCycle |
| unsigned long | knockStartTime |
| byte | lastKnockCount |
| int16_t | knockWindowMin |
| int16_t | knockWindowMax |
| uint8_t | aseTaper |
| uint8_t | dfcoTaper |
| uint8_t | idleAdvTaper |
| uint8_t | crankingEnrichTaper |
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:
| 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)
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.


| 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:
PID (Best suited to wideband sensors):


| 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).


| byte correctionBaro | ( | void | ) |
Correction for current barometric / ambient pressure.


| 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.


| int8_t correctionCLTadvance | ( | int8_t | advance | ) |
Ignition correction for coolant temperature (CLT).


| uint16_t correctionCranking | ( | void | ) |
Cranking Enrichment corrections. Additional fuel % to be added when the engine is cranking


| 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.


| bool correctionDFCO | ( | void | ) |

| int8_t correctionFixedTiming | ( | int8_t | advance | ) |
Correct ignition timing to configured fixed value. Must be called near end to override all other corrections.


| 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.


| int8_t correctionFlexTiming | ( | int8_t | advance | ) |


| byte correctionFloodClear | ( | void | ) |
Simple check to see whether we are cranking with the TPS above the flood clear threshold.

| byte correctionFuelTemp | ( | void | ) |


| 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.


| int8_t correctionIATretard | ( | int8_t | advance | ) |
Ignition correction for inlet air temperature (IAT).


| int8_t correctionIdleAdvance | ( | int8_t | advance | ) |
Ignition Idle advance correction.


| int8_t correctionKnock | ( | int8_t | advance | ) |
Ignition knock (retard) correction.


| 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

| int8_t correctionNitrous | ( | int8_t | advance | ) |
Ignition Nitrous oxide correction.


| uint16_t correctionsDwell | ( | uint16_t | dwell | ) |
Ignition Dwell Correction.


| 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


|
inlinestatic |

| int8_t correctionsIgn | ( | int8_t | base_advance | ) |
Dispatch calculations for all ignition related corrections.
| base_advance | - Base ignition advance (deg. ?) |


| int8_t correctionSoftFlatShift | ( | int8_t | advance | ) |
Ignition correction for soft flat shift.


| int8_t correctionSoftLaunch | ( | int8_t | advance | ) |
Ignition soft launch correction.


| int8_t correctionSoftRevLimit | ( | int8_t | advance | ) |
Ignition soft revlimit correction.


| int8_t correctionWMITiming | ( | int8_t | advance | ) |


| 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


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

| byte activateMAPDOT |
| byte activateTPSDOT |
| uint16_t AFRnextCycle |
| uint8_t aseTaper |
| uint8_t crankingEnrichTaper |
| uint8_t dfcoTaper |
| bool idleAdvActive = false |
| uint8_t idleAdvTaper |
| unsigned long knockStartTime |
| int16_t knockWindowMax |
| int16_t knockWindowMin |
| byte lastKnockCount |
| long PID_AFRTarget |
| 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.
| long PID_output |