hellen81_config merge: firmware adc unit test #3658
This commit is contained in:
parent
bb24b89377
commit
fed8ea18ff
File diff suppressed because it is too large
Load Diff
|
@ -26,12 +26,28 @@
|
|||
|
||||
extern TriggerAdcDetector trigAdcState;
|
||||
|
||||
static EngineTestHelper *eth = nullptr;
|
||||
|
||||
void setTriggerAdcMode(triggerAdcMode_t adcMode) {
|
||||
trigAdcState.curAdcMode = adcMode;
|
||||
|
||||
if (trigAdcState.curAdcMode == TRIGGER_ADC_ADC)
|
||||
printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MODE = ANALOG!\r\n");
|
||||
else if (trigAdcState.curAdcMode == TRIGGER_ADC_EXTI)
|
||||
printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!! MODE = DIGITAL!\r\n");
|
||||
}
|
||||
|
||||
void onTriggerChanged(efitick_t stamp, bool isPrimary, bool isRising) {
|
||||
printf("*\r\n");
|
||||
Engine *engine = ð->engine;
|
||||
EXPAND_Engine;
|
||||
|
||||
//!!!!!!!!!!!
|
||||
static int cnt = 0;
|
||||
static efitick_t prevstamp = 0;
|
||||
printf("[%d] %lld\r\n", cnt++, stamp - prevstamp);
|
||||
prevstamp = stamp;
|
||||
|
||||
hwHandleShaftSignal(isPrimary ? 0 : 1, isRising, stamp PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
}
|
||||
|
||||
static void simulateTrigger(TriggerAdcDetector &trigAdcState, CsvReader &reader, float voltageDiv, float adcMaxVoltage) {
|
||||
|
@ -42,8 +58,13 @@ static void simulateTrigger(TriggerAdcDetector &trigAdcState, CsvReader &reader,
|
|||
while (reader.haveMore()) {
|
||||
double value = 0;
|
||||
double stamp = reader.readTimestampAndValues(&value);
|
||||
efitick_t stampUs = (efitick_t)(stamp * 1'000'000);
|
||||
printf("-- %lld %f\r\n", stamp, (float)value);
|
||||
long stampUs = (long)(stamp * 1'000'000);
|
||||
efitick_t stampNt = getTimeNowNt();
|
||||
|
||||
//printf("-- %ld %f\r\n", stamp, (float)value);
|
||||
|
||||
eth->setTimeAndInvokeEventsUs(stampUs);
|
||||
|
||||
// convert into mcu-adc voltage
|
||||
value = minF(maxF(value / voltageDiv, 0), adcMaxVoltage);
|
||||
if (trigAdcState.curAdcMode == TRIGGER_ADC_EXTI) {
|
||||
|
@ -52,49 +73,83 @@ static void simulateTrigger(TriggerAdcDetector &trigAdcState, CsvReader &reader,
|
|||
if (value < Vil || value > Vih) {
|
||||
logicValue = value > Vih;
|
||||
// we need at least two values to detect an edge
|
||||
if (prevLogicValue != -1) {
|
||||
printf("--> DIGITAL %d %d\r\n", logicValue, prevLogicValue);
|
||||
if (prevLogicValue != -1 && logicValue != prevLogicValue) {
|
||||
//printf("--> DIGITAL %d %d\r\n", logicValue, prevLogicValue);
|
||||
|
||||
trigAdcState.digitalCallback(stampUs, true, logicValue > prevLogicValue ? true : false);
|
||||
trigAdcState.digitalCallback(stampNt, true, logicValue > prevLogicValue ? true : false);
|
||||
}
|
||||
prevLogicValue = logicValue;
|
||||
}
|
||||
} else if (trigAdcState.curAdcMode == TRIGGER_ADC_ADC) {
|
||||
triggerAdcSample_t sampleValue = value * ADC_MAX_VALUE / adcMaxVoltage;
|
||||
|
||||
printf("--> ANALOG %d\r\n", sampleValue);
|
||||
//printf("--> ANALOG %d\r\n", sampleValue);
|
||||
|
||||
trigAdcState.analogCallback(stampUs, sampleValue);
|
||||
trigAdcState.analogCallback(stampNt, sampleValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(big, testTriggerInputAdc) {
|
||||
printf("====================================================================================== testTriggerInputAdc\r\n");
|
||||
|
||||
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
|
||||
|
||||
template<typename Func>
|
||||
static void testTriggerSignal(const char *testName, const char *fName, int numTriggerErrors, int numRevolutions, int rpm, Func&& additionalSetup) {
|
||||
EngineTestHelper _eth(TEST_ENGINE, std::unordered_map<SensorType, float>{});
|
||||
eth = &_eth;
|
||||
Engine *engine = ð->engine;
|
||||
EXPAND_Engine;
|
||||
|
||||
engineConfiguration->ignitionMode = IM_WASTED_SPARK;
|
||||
engineConfiguration->useOnlyRisingEdgeForTrigger = true;
|
||||
engineConfiguration->invertPrimaryTriggerSignal = true;
|
||||
|
||||
engineConfiguration->adcVcc = 3.3f;
|
||||
engineConfiguration->analogInputDividerCoefficient = 2.0f;
|
||||
|
||||
additionalSetup();
|
||||
|
||||
// we'll test on 60-2 wheel
|
||||
eth.setTriggerType(TT_TOOTHED_WHEEL_60_2 PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
eth->setTriggerType(TT_TOOTHED_WHEEL_60_2 PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
ASSERT_EQ(0, engine->triggerCentral.triggerState.totalTriggerErrorCounter);
|
||||
ASSERT_EQ(0, GET_RPM()) << "testTriggerInputAdc RPM #1";
|
||||
ASSERT_EQ(0, GET_RPM());
|
||||
|
||||
CsvReader reader(1, 0);
|
||||
const int indices[2] = { 0, 1 };
|
||||
|
||||
trigAdcState.init(PASS_ENGINE_PARAMETER_SIGNATURE);
|
||||
setTriggerAdcMode(TRIGGER_ADC_ADC);
|
||||
|
||||
CsvReader reader(1, 0);
|
||||
int indices[2] = {0, 1};
|
||||
reader.open("tests/trigger/resources/trigger_adc_1.csv", indices);
|
||||
|
||||
reader.open(fName, indices);
|
||||
simulateTrigger(trigAdcState, reader, 2.0f, 3.3f);
|
||||
|
||||
ASSERT_EQ(0, engine->triggerCentral.triggerState.totalTriggerErrorCounter);
|
||||
ASSERT_EQ(0, GET_RPM()) << "testTriggerInputAdc RPM #2";
|
||||
|
||||
ASSERT_EQ(numTriggerErrors, engine->triggerCentral.triggerState.totalTriggerErrorCounter);
|
||||
ASSERT_EQ(numRevolutions, engine->triggerCentral.triggerState.getTotalRevolutionCounter());
|
||||
ASSERT_EQ(rpm, GET_RPM()) << testName;
|
||||
}
|
||||
|
||||
|
||||
TEST(big, testTriggerInputAdc) {
|
||||
printf("====================================================================================== testTriggerInputAdc\r\n");
|
||||
#if 0
|
||||
// low signal 7500 RPM, analog mode test
|
||||
testTriggerSignal("testTriggerInputAdc RPM #1", "tests/trigger/resources/trigger_adc_750.csv", 0, 2, 750, []() { });
|
||||
|
||||
// strong signal 1000 RPM, digital mode test
|
||||
testTriggerSignal("testTriggerInputAdc RPM #2", "tests/trigger/resources/trigger_adc_1000.csv", 0, 2, 1000, []() { });
|
||||
|
||||
// RPM acceleration test (analog mode)
|
||||
testTriggerSignal("testTriggerInputAdc RPM #3", "tests/trigger/resources/trigger_adc_incr.csv", 0, 3, 1329, []() { });
|
||||
|
||||
// ditital-to-analog deceleration test (teeth: 0-4 = analog, 5-183 = digital, 184-226 = analog)
|
||||
testTriggerSignal("testTriggerInputAdc RPM #4", "tests/trigger/resources/trigger_adc_decr.csv", 0, 2, 420, []() { });
|
||||
|
||||
// real oscilloscope-recorded signal
|
||||
testTriggerSignal("testTriggerInputAdc RPM #5", "tests/trigger/resources/trigger_adc_real1.csv", 0, 15, 322, []() { });
|
||||
// real oscilloscope-recorded signal
|
||||
testTriggerSignal("testTriggerInputAdc RPM #6", "tests/trigger/resources/trigger_adc_real2.csv", 0, 36, 322, []() { eth->engine.engineConfiguration->useNoiselessTriggerDecoder = true; });
|
||||
// real oscilloscope-recorded signal (bad distorted signal)
|
||||
testTriggerSignal("testTriggerInputAdc RPM #7", "tests/trigger/resources/trigger_adc_real3.csv", 7, 28, 322, []() { eth->engine.engineConfiguration->useNoiselessTriggerDecoder = true; });
|
||||
#endif
|
||||
// real oscilloscope-recorded signal (bad distorted signal)
|
||||
testTriggerSignal("testTriggerInputAdc RPM #8", "tests/trigger/resources/trigger_adc_real6.csv", 0, 9, 322, []() { eth->engine.engineConfiguration->useNoiselessTriggerDecoder = true; });
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue