auto-sync

This commit is contained in:
rusEfi 2015-06-01 20:12:28 -04:00
parent 3dc464dbfc
commit 2bf63f1f52
9 changed files with 58 additions and 30 deletions

View File

@ -76,7 +76,7 @@ static angle_t getRunningAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAME
float iatCorrection = iatAdvanceCorrectionMap.getValue(engine->engineState.clt, (float) rpm);
float result = advanceMap.getValue(engineLoad, (float) rpm) + iatCorrection;
float result = advanceMap.getValue(engineLoad, (float) rpm) + iatCorrection - engine->knockCount;
engine->m.advanceLookupTime = GET_TIMESTAMP() - engine->m.beforeAdvance;
return result;
}

View File

@ -75,7 +75,7 @@ Engine::Engine(persistent_config_s *config) {
knockNow = false;
knockEver = false;
knockCount = 0;
injectorLagMs = fuelMs = 0;
clutchDownState = clutchUpState = false;
memset(&m, 0, sizeof(m));
@ -133,12 +133,31 @@ void Engine::printKnockState(void) {
scheduleMsg(&logger, "knock now=%s/ever=%s", boolToString(knockNow), boolToString(knockEver));
}
void Engine::setKnockNow(bool_t isKnockNow) {
this->knockNow = isKnockNow;
knockEver |= isKnockNow;
if (isKnockNow) {
timeOfLastKnockEvent = getTimeNowUs();
}
void Engine::knockLogic(float knockVolts) {
knockNow = knockVolts > engineConfiguration->knockVThreshold;
/**
* KnockCount is directly proportional to the degrees of ignition
* advance removed
* ex: degrees to subtract = knockCount;
*/
/**
* TODO use knockLevel as a factor for amount of ignition advance
* to remove
* Perhaps allow the user to set a multiplier
* ex: degrees to subtract = knockCount + (knockLevel * X)
* X = user configurable multiplier
*/
if (knockNow) {
knockEver = true;
timeOfLastKnockEvent = getTimeNowUs();
if (knockCount < engineConfiguration->maxKnockSubDeg)
knockCount++;
} else if (knockCount >= 1) {
knockCount--;
} else {
knockCount = 0;
}
}
void Engine::watchdog() {

View File

@ -203,6 +203,11 @@ public:
* Have we experienced knock since engine was started?
*/
bool_t knockEver;
/**
* KnockCount is directly proportional to the degrees of ignition
* advance removed
*/
int knockCount;
efitimeus_t timeOfLastKnockEvent;
@ -279,7 +284,7 @@ public:
monitoring_timestamps_s m;
void setKnockNow(bool_t isKnockNow);
void knockLogic(float knockVolts);
void printKnockState(void);
private:

View File

@ -1,4 +1,4 @@
// this section was generated by config_definition.jar on Sat May 30 13:04:24 EDT 2015
// this section was generated by config_definition.jar on Mon Jun 01 19:10:17 EDT 2015
// begin
#include "rusefi_types.h"
typedef struct {
@ -522,6 +522,9 @@ typedef struct {
/**
offset 384 bit 10 */
bool_t enabledStep1Limiter : 1;
/**
offset 384 bit 11 */
bool_t useTpicAdvancedMode : 1;
/**
* offset 388
*/
@ -951,9 +954,11 @@ typedef struct {
*/
int16_t pedalPositionMax;
/**
* maximum total number of degrees to subtract from ignition advance
* when knocking
* offset 576
*/
int unused12;
float maxKnockSubDeg;
/**
* offset 580
*/
@ -1143,7 +1148,7 @@ typedef struct {
/**
* offset 1552
*/
float hipThreshold;
float knockVThreshold;
/**
* offset 1556
*/
@ -1398,4 +1403,4 @@ typedef struct {
} persistent_config_s;
// end
// this section was generated by config_definition.jar on Sat May 30 13:04:24 EDT 2015
// this section was generated by config_definition.jar on Mon Jun 01 19:10:17 EDT 2015

View File

@ -182,8 +182,8 @@
#define globalFuelCorrection_offset_hex 238
#define pedalPositionMin_offset 572
#define pedalPositionMax_offset 574
#define unused12_offset 576
#define unused12_offset_hex 240
#define maxKnockSubDeg_offset 576
#define maxKnockSubDeg_offset_hex 240
#define mafAdcChannel_offset 580
#define mafAdcChannel_offset_hex 244
#define afr_offset 584
@ -343,6 +343,7 @@
#define useSerialPort_offset 1008
#define useStepperIdle_offset 1008
#define enabledStep1Limiter_offset 1008
#define useTpicAdvancedMode_offset 1008
#define logicAnalyzerPins1_offset 1012
#define logicAnalyzerPins2_offset 1016
#define logicAnalyzerPins3_offset 1020
@ -583,8 +584,8 @@
#define knockDetectionWindowEnd_offset 1544
#define knockDetectionWindowEnd_offset_hex 608
#define idleStepperReactionTime_offset 1548
#define hipThreshold_offset 1552
#define hipThreshold_offset_hex 610
#define knockVThreshold_offset 1552
#define knockVThreshold_offset_hex 610
#define fsioInputModes1_offset 1556
#define fsioInputModes1_offset_hex 614
#define fsioInputModes2_offset 1560

View File

@ -354,7 +354,7 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex DECL
if (eventIndex == engineConfiguration->ignMathCalculateAtIndex) {
if (engineConfiguration->externalKnockSenseAdc != EFI_ADC_NONE) {
float externalKnockValue = getVoltageDivided("knock", engineConfiguration->externalKnockSenseAdc);
engine->setKnockNow(externalKnockValue > 2.5);
engine->knockLogic(externalKnockValue);
}
engine->m.beforeIgnitionMath = GET_TIMESTAMP();

View File

@ -126,7 +126,7 @@ static void showHipInfo(void) {
scheduleMsg(logger, "band_index=%d gain %f/index=%d", currentBandIndex, boardConfiguration->hip9011Gain, currentGainIndex);
scheduleMsg(logger, "integrator index=%d hip_threshold=%f totalKnockEventsCount=%d", currentIntergratorIndex,
engineConfiguration->hipThreshold, totalKnockEventsCount);
engineConfiguration->knockVThreshold, totalKnockEventsCount);
scheduleMsg(logger, "spi= IntHold@%s response count=%d", hwPortname(boardConfiguration->hip9011IntHoldPin),
nonZeroResponse);
@ -149,7 +149,7 @@ void setHip9011FrankensoPinout(void) {
boardConfiguration->is_enabled_spi_2 = true;
boardConfiguration->hip9011Gain = 1;
engineConfiguration->hipThreshold = 4;
engineConfiguration->knockVThreshold = 4;
engineConfiguration->hipOutputChannel = EFI_ADC_10; // PC0
}
@ -230,11 +230,7 @@ void hipAdcCallback(adcsample_t value) {
} else if (state == WAITING_FOR_RESULT_ADC) {
float hipValue = adcToVoltsDivided(value);
hipValueMax = maxF(hipValue, hipValueMax);
bool isKnockNow = hipValue > engineConfiguration->hipThreshold;
engine->setKnockNow(isKnockNow);
if (isKnockNow) {
totalKnockEventsCount++;
}
engine->knockLogic(hipValue);
int integratorIndex = getIntegrationIndexByRpm(engine->rpmCalculator.rpmValue);
int gainIndex = getHip9011GainIndex(boardConfiguration->hip9011Gain);

View File

@ -277,7 +277,7 @@ float globalFuelCorrection;;"coef", 1, 0.0, 0, 1000.0, 2
int16_t pedalPositionMin;
int16_t pedalPositionMax;
int unused12;
float maxKnockSubDeg;maximum total number of degrees to subtract from ignition advance\nwhen knocking
adc_channel_e mafAdcChannel;
struct afr_sensor_s
@ -399,6 +399,7 @@ bit is_enabled_spi_2
bit useStepperIdle
bit enabledStep1Limiter;
bit useTpicAdvancedMode;
brain_input_pin_e[LOGIC_ANALYZER_CHANNEL_COUNT iterate] logicAnalyzerPins;
uint8_t[LOGIC_ANALYZER_CHANNEL_COUNT] logicAnalyzerMode;default or inverted input
@ -529,7 +530,7 @@ custom idle_mode_e 4 bits, U32, @OFFSET@, [0:0], "false", "true"
float idleStepperReactionTime;;"ms", 1, 0, 1, 300, 0
float hipThreshold;;"V", 1, 0, 1, 5, 2
float knockVThreshold;;"V", 1, 0, 1, 5, 2
custom pin_input_mode_e 4 scalar, F32, @OFFSET@, "ms", 1, 0, 0, 200, 1
pin_input_mode_e[LE_COMMAND_COUNT iterate] fsioInputModes;

View File

@ -40,7 +40,7 @@ enable2ndByteCanID = false
; see PAGE_0_SIZE in C source code
; CONFIG_DEFINITION_START
; this section was generated by ConfigDefinition.jar on Sun May 31 08:31:25 EDT 2015
; this section was generated by ConfigDefinition.jar on Mon Jun 01 19:10:18 EDT 2015
pageSize = 15288
page = 1
@ -137,7 +137,7 @@ page = 1
globalFuelCorrection = scalar, F32, 568, "coef", 1, 0.0, 0, 1000.0, 2
;skipping pedalPositionMin offset 572
;skipping pedalPositionMax offset 574
;skipping unused12 offset 576
;skipping maxKnockSubDeg offset 576
mafAdcChannel = bits, U32, 580, [0:3] "PA0", "PA1", "PA2", "PA3", "PA4", "PA5", "PA6", "PA7", "PB0", "PB1", "PC0", "PC1", "PC2", "PC3", "PC4", "PC5"
afr_hwChannel = bits, U32, 584, [0:3] "PA0", "PA1", "PA2", "PA3", "PA4", "PA5", "PA6", "PA7", "PB0", "PB1", "PC0", "PC1", "PC2", "PC3", "PC4", "PC5"
afr_v1 = scalar, F32, 588, "volts", 1, 0.0, 0, 10.0, 2
@ -248,6 +248,7 @@ page = 1
useSerialPort = bits, U32, 1008, [8:8], "false", "true"
useStepperIdle = bits, U32, 1008, [9:9], "false", "true"
enabledStep1Limiter = bits, U32, 1008, [10:10], "false", "true"
useTpicAdvancedMode = bits, U32, 1008, [11:11], "false", "true"
logicAnalyzerPins1 = bits, U32, 1012, [0:6], "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "PA5", "INVALID", "INVALID", "PA8", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "PC6", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "PE5", "INVALID", "PE7", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "NONE", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID"
logicAnalyzerPins2 = bits, U32, 1016, [0:6], "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "PA5", "INVALID", "INVALID", "PA8", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "PC6", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "PE5", "INVALID", "PE7", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "NONE", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID"
logicAnalyzerPins3 = bits, U32, 1020, [0:6], "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "PA5", "INVALID", "INVALID", "PA8", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "PC6", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "PE5", "INVALID", "PE7", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "NONE", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID"
@ -425,7 +426,7 @@ page = 1
;skipping knockDetectionWindowStart offset 1540
;skipping knockDetectionWindowEnd offset 1544
idleStepperReactionTime = scalar, F32, 1548, "ms", 1, 0, 1, 300, 0
hipThreshold = scalar, F32, 1552, "V", 1, 0, 1, 5, 2
knockVThreshold = scalar, F32, 1552, "V", 1, 0, 1, 5, 2
fsioInputModes1 = scalar, F32, 1556, "ms", 1, 0, 0, 200, 1
fsioInputModes2 = scalar, F32, 1560, "ms", 1, 0, 0, 200, 1
fsioInputModes3 = scalar, F32, 1564, "ms", 1, 0, 0, 200, 1