This commit is contained in:
rusefi 2019-01-07 23:23:50 -05:00
parent 3fd0203c9d
commit c51af79731
6 changed files with 69 additions and 57 deletions

View File

@ -31,22 +31,6 @@ const float bandFreqLookup[BAND_LOOKUP_SIZE] = { 1.22, 1.26, 1.31, 1.35, 1.4, 1.
10.12, 10.46, 10.83, 11.22, 11.65, 12.1, 12.6, 13.14, 13.72, 14.36, 15.07, 15.84, 16.71, 17.67, 18.76, 19.98 };
float rpmLookup[INT_LOOKUP_SIZE];
/**
*
* We know the set of possible integration times, we know the knock detection window width
*/
void prepareHip9011RpmLookup(float angleWindowWidth) {
/**
* out binary search method needs increasing order thus the reverse order here
*/
for (int i = 0; i < INT_LOOKUP_SIZE; i++) {
rpmLookup[i] = getRpmByAngleWindowAndTimeUs(integratorValues[INT_LOOKUP_SIZE - i - 1], angleWindowWidth);
}
}
/**
* 'TC is typically TINT/(2*Pi*VOUT)'
* Knock Sensor Training TPIC8101, page 24
@ -64,12 +48,6 @@ float getRpmByAngleWindowAndTimeUs(int timeUs, float angleWindowWidth) {
return 60000000.0f / integrationTimeUs * windowWidthMult;
}
int getIntegrationIndexByRpm(float rpm) {
int i = findIndexMsg("getIbR", rpmLookup, INT_LOOKUP_SIZE, (rpm));
return i == -1 ? INT_LOOKUP_SIZE - 1 : INT_LOOKUP_SIZE - i - 1;
}
/**
* @param frequency knock frequencey, in kHz
*/

View File

@ -23,12 +23,10 @@ extern const float bandFreqLookup[BAND_LOOKUP_SIZE];
float getRpmByAngleWindowAndTimeUs(int timeUs, float angleWindowWidth);
int getHip9011BandIndex(float frequency);
void prepareHip9011RpmLookup(float angleWindowWidth);
#define GAIN_INDEX(gain) (GAIN_LOOKUP_SIZE - 1 - findIndexMsg("fGain", gainLookupInReverseOrder, GAIN_LOOKUP_SIZE, (gain)))
extern float rpmLookup[INT_LOOKUP_SIZE];
int getIntegrationIndexByRpm(float rpm);
void initEngineNoiseTable(DECLARE_ENGINE_PARAMETER_SIGNATURE);
#endif /* CONTROLLERS_SENSORS_HIP9011_LOOKUP_H_ */

View File

@ -58,15 +58,7 @@ extern EnginePins enginePins;
uint32_t hipLastExecutionCount;
/**
* band index is only send to HIP chip on startup
*/
static int currentBandIndex;
static int currentGainIndex = -1;
static int currentIntergratorIndex = -1;
static int settingUpdateCount = 0;
static int totalKnockEventsCount = 0;
static int currentPrescaler;
static float hipValueMax = 0;
static HIP9011 instance;
@ -135,10 +127,10 @@ static void showHipInfo(void) {
char *outputName = getPinNameByAdcChannel("hip", engineConfiguration->hipOutputChannel, hipPinNameBuffer);
scheduleMsg(logger, "band_index=%d gain %.2f/index=%d output=%s", currentBandIndex, engineConfiguration->hip9011Gain, currentGainIndex,
scheduleMsg(logger, "band_index=%d gain %.2f/index=%d output=%s", instance.currentBandIndex, engineConfiguration->hip9011Gain, instance.currentGainIndex,
outputName);
scheduleMsg(logger, "integrator index=%d knockVThreshold=%.2f knockCount=%d maxKnockSubDeg=%.2f",
currentIntergratorIndex, engineConfiguration->knockVThreshold,
instance.currentIntergratorIndex, engineConfiguration->knockVThreshold,
engine->knockCount, engineConfiguration->maxKnockSubDeg);
const char * msg = invalidHip9011ResponsesCount > 0 ? "NOT GOOD" : "ok";
@ -148,7 +140,7 @@ static void showHipInfo(void) {
boardConfiguration->hip9011IntHoldPinMode,
correctResponsesCount, invalidHip9011ResponsesCount,
msg);
scheduleMsg(logger, "CS@%s updateCount=%d", hwPortname(boardConfiguration->hip9011CsPin), settingUpdateCount);
scheduleMsg(logger, "CS@%s updateCount=%d", hwPortname(boardConfiguration->hip9011CsPin), instance.settingUpdateCount);
#if EFI_PROD_CODE
scheduleMsg(logger, "hip %.2fv/last=%.2f@%s/max=%.2f adv=%d",
@ -303,27 +295,27 @@ void hipAdcCallback(adcsample_t adcValue) {
if (angleWindowWidth != currentAngleWindowWidth) {
currentAngleWindowWidth = angleWindowWidth;
prepareHip9011RpmLookup(currentAngleWindowWidth);
instance.prepareHip9011RpmLookup(currentAngleWindowWidth);
}
int integratorIndex = getIntegrationIndexByRpm(GET_RPM());
int integratorIndex = instance.getIntegrationIndexByRpm(GET_RPM());
int gainIndex = getHip9011GainIndex(PASS_HIP_PARAMS);
int bandIndex = getBandIndex(PASS_HIP_PARAMS);
int prescalerIndex = engineConfiguration->hip9011PrescalerAndSDO;
if (currentGainIndex != gainIndex) {
currentGainIndex = gainIndex;
if (instance.currentGainIndex != gainIndex) {
instance.currentGainIndex = gainIndex;
sendCommand(IS_SENDING_SPI_COMMAND, SET_GAIN_CMD + gainIndex);
} else if (currentIntergratorIndex != integratorIndex) {
currentIntergratorIndex = integratorIndex;
} else if (instance.currentIntergratorIndex != integratorIndex) {
instance.currentIntergratorIndex = integratorIndex;
sendCommand(IS_SENDING_SPI_COMMAND, SET_INTEGRATOR_CMD + integratorIndex);
} else if (currentBandIndex != bandIndex) {
currentBandIndex = bandIndex;
} else if (instance.currentBandIndex != bandIndex) {
instance.currentBandIndex = bandIndex;
sendCommand(IS_SENDING_SPI_COMMAND, SET_BAND_PASS_CMD + bandIndex);
} else if (currentPrescaler != prescalerIndex) {
currentPrescaler = prescalerIndex;
} else if (instance.currentPrescaler != prescalerIndex) {
instance.currentPrescaler = prescalerIndex;
sendCommand(IS_SENDING_SPI_COMMAND, SET_PRESCALER_CMD + prescalerIndex);
} else {
@ -346,8 +338,8 @@ static void hipStartupCode(void) {
// 0 for 4MHz
// 6 for 8 MHz
currentPrescaler = engineConfiguration->hip9011PrescalerAndSDO;
SPI_SYNCHRONOUS(SET_PRESCALER_CMD + currentPrescaler);
instance.currentPrescaler = engineConfiguration->hip9011PrescalerAndSDO;
SPI_SYNCHRONOUS(SET_PRESCALER_CMD + instance.currentPrescaler);
chThdSleepMilliseconds(10);
@ -357,7 +349,7 @@ static void hipStartupCode(void) {
chThdSleepMilliseconds(10);
// band index depends on cylinder bore
SPI_SYNCHRONOUS(SET_BAND_PASS_CMD + currentBandIndex);
SPI_SYNCHRONOUS(SET_BAND_PASS_CMD + instance.currentBandIndex);
chThdSleepMilliseconds(10);
@ -417,7 +409,7 @@ void initHip9011(Logging *sharedLogger) {
currentAngleWindowWidth =
engineConfiguration->knockDetectionWindowEnd - engineConfiguration->knockDetectionWindowStart;
prepareHip9011RpmLookup(currentAngleWindowWidth);
instance.prepareHip9011RpmLookup(currentAngleWindowWidth);
#if EFI_PROD_CODE
driver = getSpiDevice(engineConfiguration->hip9011SpiDevice);
@ -434,7 +426,7 @@ void initHip9011(Logging *sharedLogger) {
scheduleMsg(logger, "Starting HIP9011/TPIC8101 driver");
spiStart(driver, &hipSpiCfg);
currentBandIndex = getBandIndex();
instance.currentBandIndex = getBandIndex();
/**
* this engine cycle callback would be scheduling actual integration start and end callbacks

View File

@ -12,6 +12,15 @@ EXTERN_ENGINE;
HIP9011::HIP9011() {
needToInit = true;
state = NOT_READY;
/**
* band index is only send to HIP chip on startup
*/
currentBandIndex = 0;
currentGainIndex = -1;
currentIntergratorIndex = -1;
settingUpdateCount = 0;
totalKnockEventsCount = 0;
currentPrescaler = 0;
}
#define BAND(bore) (900 / (PIF * (bore) / 2))
@ -41,3 +50,20 @@ int getHip9011GainIndex(float gain) {
return i == GAIN_LOOKUP_SIZE ? GAIN_LOOKUP_SIZE - 1 : i;
}
/**
*
* We know the set of possible integration times, we know the knock detection window width
*/
void HIP9011::prepareHip9011RpmLookup(float angleWindowWidth) {
/**
* out binary search method needs increasing order thus the reverse order here
*/
for (int i = 0; i < INT_LOOKUP_SIZE; i++) {
rpmLookup[i] = getRpmByAngleWindowAndTimeUs(integratorValues[INT_LOOKUP_SIZE - i - 1], angleWindowWidth);
}
}
int HIP9011::getIntegrationIndexByRpm(float rpm) {
int i = findIndexMsg("getIbR", rpmLookup, INT_LOOKUP_SIZE, (rpm));
return i == -1 ? INT_LOOKUP_SIZE - 1 : INT_LOOKUP_SIZE - i - 1;
}

View File

@ -23,7 +23,19 @@ public:
class HIP9011 {
public:
HIP9011();
void prepareHip9011RpmLookup(float angleWindowWidth);
int getIntegrationIndexByRpm(float rpm);
/**
* band index is only send to HIP chip on startup
*/
int currentBandIndex;
int currentGainIndex;
int currentIntergratorIndex;
bool needToInit;
int settingUpdateCount;
int totalKnockEventsCount;
int currentPrescaler;
/**
* Int/Hold pin is controlled from scheduler call-backs which are set according to current RPM
*
@ -35,8 +47,9 @@ public:
* hipOutput should be set to used FAST adc device
*/
hip_state_e state;
};
float rpmLookup[INT_LOOKUP_SIZE];
};
#if EFI_PROD_CODE || EFI_SIMULATOR
#define PASS_HIP_PARAMS

View File

@ -22,12 +22,17 @@ TEST(hip9011, lookup) {
EXPECT_EQ(47, getHip9011GainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/0.234));
EXPECT_EQ(63, getHip9011GainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/0.000001));
prepareHip9011RpmLookup(50);
}
EXPECT_EQ(31, getIntegrationIndexByRpm(1));
EXPECT_EQ(21, getIntegrationIndexByRpm(1100));
EXPECT_EQ(1, getIntegrationIndexByRpm(6600));
EXPECT_EQ(0, getIntegrationIndexByRpm(16600));
TEST(hip9011, rpmLookup) {
HIP9011 instace;
instace.prepareHip9011RpmLookup(50);
EXPECT_EQ(31, instace.getIntegrationIndexByRpm(1));
EXPECT_EQ(21, instace.getIntegrationIndexByRpm(1100));
EXPECT_EQ(1, instace.getIntegrationIndexByRpm(6600));
EXPECT_EQ(0, instace.getIntegrationIndexByRpm(16600));
}
TEST(hip9011, band) {