You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Separate fuel calcs out from speeduino.ino (speeduino#1351)
* Split out unit tested fueling calcs from speeduino.ino
* Remove speeduino.h - place contents directly in speeduino.ino for simpler unit testing.
* Remove unecessay #include
* Performance - force inline
intermediate = UINT16_MAX; //Make sure this won't overflow when we convert to uInt. This means the maximum pulsewidth possible is 65.535mS
75
+
}
76
+
}
77
+
return (unsignedint)(intermediate);
78
+
}
79
+
#pragma GCC diagnostic pop
80
+
81
+
uint16_tcalculatePWLimit()
82
+
{
83
+
uint32_t tempLimit = percentage(configPage2.dutyLim, revolutionTime); //The pulsewidth limit is determined to be the duty cycle limit (Eg 85%) by the total time it takes to perform 1 revolution
//To run staged injection, the number of cylinders must be less than or equal to the injector channels (ie Assuming you're running paired injection, you need at least as many injector channels as you have cylinders, half for the primaries and half for the secondaries)
118
+
if( (configPage10.stagingEnabled == true) && (configPage2.nCylinders <= INJ_CHANNELS || configPage2.injType == INJ_TYPE_TBODY) && (currentStatus.PW1 > inj_opentime_uS) ) //Final check is to ensure that DFCO isn't active, which would cause an overflow below (See #267)
119
+
{
120
+
//Scale the 'full' pulsewidth by each of the injector capacities
121
+
currentStatus.PW1 -= inj_opentime_uS; //Subtract the opening time from PW1 as it needs to be multiplied out again by the pri/sec req_fuel values below. It is added on again after that calculation.
uint32_t tempPW3 = div100((uint32_t)currentStatus.PW1 * staged_req_fuel_mult_sec); //This is ONLY needed in in table mode. Auto mode only calculates the difference.
//If automatic mode, the primary injectors are used all the way up to their limit (Configured by the pulsewidth limit setting)
149
+
//If they exceed their limit, the extra duty is passed to the secondaries
150
+
if(tempPW1 > pwLimit)
151
+
{
152
+
currentStatus.stagingActive = true; //Set the staging active flag
153
+
uint32_t extraPW = tempPW1 - pwLimit + inj_opentime_uS; //The open time must be added here AND below because tempPW1 does not include an open time. The addition of it here takes into account the fact that pwLlimit does not contain an allowance for an open time.
154
+
currentStatus.PW1 = pwLimit;
155
+
currentStatus.PW2 = udiv_32_16(extraPW * staged_req_fuel_mult_sec, staged_req_fuel_mult_pri); //Convert the 'left over' fuel amount from primary injector scaling to secondary
156
+
currentStatus.PW2 += inj_opentime_uS;
157
+
}
158
+
else
159
+
{
160
+
//If tempPW1 < pwLImit it means that the entire fuel load can be handled by the primaries and staging is inactive.
161
+
currentStatus.PW1 += inj_opentime_uS; //Add the open time back in
162
+
currentStatus.stagingActive = false; //Clear the staging active flag
163
+
currentStatus.PW2 = 0; //Secondary PW is simply set to 0 as it is not required
164
+
}
165
+
}
166
+
167
+
//Allocate the primary and secondary pulse widths based on the fuel configuration
168
+
switch (configPage2.nCylinders)
169
+
{
170
+
case1:
171
+
//Nothing required for 1 cylinder, channels are correct already
172
+
break;
173
+
case2:
174
+
//Primary pulsewidth on channels 1 and 2, secondary on channels 3 and 4
175
+
currentStatus.PW3 = currentStatus.PW2;
176
+
currentStatus.PW4 = currentStatus.PW2;
177
+
currentStatus.PW2 = currentStatus.PW1;
178
+
break;
179
+
case3:
180
+
//6 channels required for 'normal' 3 cylinder staging support
181
+
#if INJ_CHANNELS >= 6
182
+
//Primary pulsewidth on channels 1, 2 and 3, secondary on channels 4, 5 and 6
183
+
currentStatus.PW4 = currentStatus.PW2;
184
+
currentStatus.PW5 = currentStatus.PW2;
185
+
currentStatus.PW6 = currentStatus.PW2;
186
+
#else
187
+
//If there are not enough channels, then primary pulsewidth is on channels 1, 2 and 3, secondary on channel 4
* @brief Speeduino main file containing initial setup and system loop functions
3
-
* @author Josh Stewart
4
-
*
5
-
* This file contains the main system loop of the Speeduino core and thus much of the logic of the fuel and ignition algorithms is contained within this
6
-
* It is where calls to all the auxiliary control systems, sensor reads, comms etc are made
7
-
*
8
-
* It also contains the setup() function that is called by the bootloader on system startup
9
-
*
10
-
*/
1
+
#pragma once
11
2
12
-
#ifndefSPEEDUINO_H
13
-
#defineSPEEDUINO_H
14
-
//#include "globals.h"
3
+
#include<stdint.h>
15
4
16
-
#defineCRANK_RUN_HYSTER 15
5
+
/**
6
+
* @brief This function calculates the required pulsewidth time (in us) given the current system state
7
+
*
8
+
* @param REQ_FUEL The required fuel value in uS, as calculated by TunerStudio
9
+
* @param VE Lookup from the main fuel table. This can either have been MAP or TPS based, depending on the algorithm used
10
+
* @param 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)
11
+
* @param corrections Sum of Enrichment factors (Cold start, acceleration). This is a multiplication factor (Eg to add 10%, this should be 110)
12
+
* @param injOpen Injector opening time. The time the injector take to open minus the time it takes to close (Both in uS)
externuint16_treq_fuel_uS; /**< The required fuel variable (As calculated by TunerStudio) in uS */
29
22
externuint16_tinj_opentime_uS; /**< The injector opening time. This is set within Tuner Studio, but stored here in uS rather than mS */
@@ -39,11 +32,5 @@ extern uint16_t inj_opentime_uS; /**< The injector opening time. This is set wit
39
32
* - staged_req_fuel_mult_pri = 300% (The primary injectors would have to run 3x the overall PW in order to be the equivalent of the full 750cc capacity
40
33
* - staged_req_fuel_mult_sec = 150% (The secondary injectors would have to run 1.5x the overall PW in order to be the equivalent of the full 750cc capacity
0 commit comments