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"
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:
uint8_t calculateAfrTarget | ( | table3d16RpmLoad & | afrLookUpTable, |
const statuses & | current, | ||
const config2 & | page2, | ||
const config6 & | page6 | ||
) |
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.
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):
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).
Correction for current barometric / ambient pressure.
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.
Ignition correction for coolant temperature (CLT).
Cranking Enrichment corrections. Additional fuel % to be added when the engine is cranking
Correct ignition timing to configured fixed value to use during craning. Must be called near end to override all other corrections.
Ignition DFCO taper correction.
Correct ignition timing to configured fixed value. Must be called near end to override all other corrections.
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.
Simple check to see whether we are cranking with the TPS above the flood clear threshold.
Simple temperature based corrections lookup based on the inlet air temperature (IAT). This corrects for changes in air density from movement of the temperature.
Ignition correction for inlet air temperature (IAT).
Ignition Idle advance correction.
Ignition knock (retard) correction.
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
Ignition Nitrous oxide correction.
Ignition Dwell Correction.
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
Dispatch calculations for all ignition related corrections.
base_advance | - Base ignition advance (deg. ?) |
Ignition correction for soft flat shift.
Ignition soft launch correction.
Ignition soft revlimit correction.
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
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 dfcoDelay |
uint8_t dfcoTaper |
uint8_t idleAdvTaper |
uint8_t knockLastRecoveryStep |
long PID_AFRTarget |
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 |