This commit is contained in:
rusefi 2019-01-04 19:20:32 -05:00
parent 6e1e00f42d
commit fc8755fd5a
6 changed files with 29 additions and 18 deletions

View File

@ -69,11 +69,6 @@ int getIntegrationIndexByRpm(float rpm) {
return i == -1 ? INT_LOOKUP_SIZE - 1 : INT_LOOKUP_SIZE - i - 1;
}
int getHip9011GainIndex(float gain) {
int i = GAIN_INDEX(gain);
// GAIN_LOOKUP_SIZE is returned for index which is too low
return i == GAIN_LOOKUP_SIZE ? GAIN_LOOKUP_SIZE - 1 : i;
}
/**
* @param frequency knock frequencey, in kHz

View File

@ -21,7 +21,7 @@ extern const float gainLookupInReverseOrder[GAIN_LOOKUP_SIZE];
extern const float bandFreqLookup[BAND_LOOKUP_SIZE];
float getRpmByAngleWindowAndTimeUs(int timeUs, float angleWindowWidth);
int getHip9011GainIndex(float gain);
int getHip9011BandIndex(float frequency);
void prepareHip9011RpmLookup(float angleWindowWidth);

View File

@ -307,8 +307,8 @@ void hipAdcCallback(adcsample_t adcValue) {
}
int integratorIndex = getIntegrationIndexByRpm(GET_RPM());
int gainIndex = getHip9011GainIndex(engineConfiguration->hip9011Gain);
int bandIndex = getBandIndex();
int gainIndex = getHip9011GainIndex(PASS_HIP_PARAMS);
int bandIndex = getBandIndex(PASS_HIP_PARAMS);
int prescalerIndex = engineConfiguration->hip9011PrescalerAndSDO;

View File

@ -29,3 +29,15 @@ int getBandIndex(DEFINE_HIP_PARAMS) {
return getHip9011BandIndex(freq);
}
int getHip9011GainIndex(DEFINE_HIP_PARAMS) {
int i = GAIN_INDEX(GET_CONFIG_VALUE(hip9011Gain));
// GAIN_LOOKUP_SIZE is returned for index which is too low
return i == GAIN_LOOKUP_SIZE ? GAIN_LOOKUP_SIZE - 1 : i;
}
int getHip9011GainIndex(float gain) {
int i = GAIN_INDEX(gain);
// GAIN_LOOKUP_SIZE is returned for index which is too low
return i == GAIN_LOOKUP_SIZE ? GAIN_LOOKUP_SIZE - 1 : i;
}

View File

@ -46,13 +46,16 @@ public:
#else
#define PASS_HIP_PARAMS CONFIG(knockBandCustom), \
CONFIG(cylinderBore)
CONFIG(cylinderBore), \
CONFIG(hip9011Gain)
#define FORWARD_HIP_PARAMS knockBandCustom, \
cylinderBore
cylinderBore, \
hip9011Gain
#define DEFINE_HIP_PARAMS float knockBandCustom,\
float cylinderBore
float cylinderBore, \
float hip9011Gain
#define GET_CONFIG_VALUE(x) x
#endif
@ -60,5 +63,6 @@ public:
float getHIP9011Band(DEFINE_HIP_PARAMS);
int getBandIndex(DEFINE_HIP_PARAMS);
int getHip9011GainIndex(DEFINE_HIP_PARAMS);
#endif /* HW_LAYER_HIP9011_LOGIC_H_ */

View File

@ -17,10 +17,10 @@ TEST(hip9011, lookup) {
assertEqualsM2("240us 50 degree", 1105.2435, getRpmByAngleWindowAndTimeUs(240, 50), 0.1);
assertEqualsM2("240us 50 degree", 6631.4619, getRpmByAngleWindowAndTimeUs(40, 50), 0.1);
EXPECT_EQ(0, getHip9011GainIndex(3));
EXPECT_EQ(0, getHip9011GainIndex(2));
EXPECT_EQ(47, getHip9011GainIndex(0.234));
EXPECT_EQ(63, getHip9011GainIndex(0.000001));
EXPECT_EQ(0, getHip9011GainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/3));
EXPECT_EQ(0, getHip9011GainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/2));
EXPECT_EQ(47, getHip9011GainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/0.234));
EXPECT_EQ(63, getHip9011GainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/0.000001));
prepareHip9011RpmLookup(50);
@ -32,9 +32,9 @@ TEST(hip9011, lookup) {
TEST(hip9011, band) {
EXPECT_FLOAT_EQ(3, getHIP9011Band(/* knockBandCustom*/3, /*cylinderBore*/76));
EXPECT_FLOAT_EQ(7.5389242, getHIP9011Band(/* knockBandCustom*/0, /*cylinderBore*/76));
EXPECT_FLOAT_EQ(3, getHIP9011Band(/* knockBandCustom*/3, /*cylinderBore*/76, /*hip9011Gain*/NAN));
EXPECT_FLOAT_EQ(7.5389242, getHIP9011Band(/* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/NAN));
EXPECT_EQ(42, getBandIndex(/* knockBandCustom*/0, /*cylinderBore*/76));
EXPECT_EQ(42, getBandIndex(/* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/NAN));
}