2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file PwmTester.cpp
|
|
|
|
* This is a tool to measure rusEfi PWM generation quality
|
|
|
|
*
|
|
|
|
* @date Apr 29, 2014
|
2018-01-20 17:55:31 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2018
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
2018-09-16 19:26:57 -07:00
|
|
|
#include "global.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2016-07-23 10:03:57 -07:00
|
|
|
#if EFI_PWM_TESTER || defined(__DOXYGEN__)
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
#include "PwmTester.h"
|
|
|
|
#include "EfiWave.h"
|
|
|
|
#include "pwm_generator_logic.h"
|
|
|
|
#include "engine.h"
|
|
|
|
#include "pwm_generator.h"
|
|
|
|
|
|
|
|
static LoggingWithStorage logger;
|
|
|
|
|
|
|
|
static SimplePwm pwmTest[5];
|
|
|
|
|
2018-07-26 14:11:47 -07:00
|
|
|
extern OutputPin warningLedPin;
|
2016-11-03 20:02:58 -07:00
|
|
|
extern EnginePins enginePins;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
EXTERN_ENGINE;
|
|
|
|
|
|
|
|
static void startPwmTest(int freq) {
|
|
|
|
scheduleMsg(&logger, "running pwm test @%d", freq);
|
|
|
|
|
|
|
|
engine->isRunningPwmTest = true;
|
|
|
|
|
|
|
|
// PD13 pin is initialized elsewhere already
|
2018-07-26 14:11:47 -07:00
|
|
|
startSimplePwm(&pwmTest[0], "tester", &warningLedPin, 10, 0.5f, applyPinState);
|
2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* See custom_engine.cpp for pinout
|
|
|
|
*/
|
|
|
|
// currently this is PB9 by default - see boardConfiguration->injectionPins
|
|
|
|
startSimplePwm(&pwmTest[1], "tester", &enginePins.injectors[0], freq / 1.3333333333, 0.5f, applyPinState);
|
|
|
|
// currently this is PE2 by default
|
|
|
|
startSimplePwm(&pwmTest[2], "tester", &enginePins.injectors[1], freq / 1000, 0.5f, applyPinState);
|
|
|
|
// currently this is PB8 by default
|
|
|
|
startSimplePwm(&pwmTest[3], "tester", &enginePins.injectors[2], freq, 0.5, applyPinState);
|
|
|
|
// currently this is PB7 by default
|
|
|
|
startSimplePwm(&pwmTest[4], "tester", &enginePins.injectors[3], freq / 33.33333333333, 0.5, applyPinState);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static scheduling_s ioTest;
|
|
|
|
|
|
|
|
static OutputSignal outSignals[8];
|
|
|
|
|
|
|
|
static void testCallback(void *arg) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 0.1ms from now please squirt for 1.6ms
|
|
|
|
*/
|
|
|
|
float delayMs = 0.1;
|
|
|
|
float durationMs = 1.6;
|
|
|
|
|
|
|
|
efitimeus_t nowUs = getTimeNowUs();
|
|
|
|
|
|
|
|
scheduleOutput(&outSignals[0], nowUs, delayMs, durationMs);
|
|
|
|
scheduleOutput(&outSignals[1], nowUs, delayMs, durationMs);
|
|
|
|
scheduleOutput(&outSignals[2], nowUs, delayMs, durationMs);
|
|
|
|
scheduleOutput(&outSignals[3], nowUs, delayMs, durationMs);
|
|
|
|
|
|
|
|
scheduleOutput(&outSignals[4], nowUs, delayMs, durationMs);
|
|
|
|
scheduleOutput(&outSignals[5], nowUs, delayMs, durationMs);
|
|
|
|
scheduleOutput(&outSignals[6], nowUs, delayMs, durationMs);
|
|
|
|
scheduleOutput(&outSignals[7], nowUs, delayMs, durationMs);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* this would re-schedule another callback in 2ms from now
|
|
|
|
*/
|
2019-01-09 04:57:43 -08:00
|
|
|
engine->executor.scheduleForLater("test", &ioTest, MS2US(2), testCallback, NULL);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void initPwmTester(void) {
|
|
|
|
initLogging(&logger, "pwm test");
|
|
|
|
addConsoleActionI("pwmtest", startPwmTest);
|
|
|
|
startPwmTest(1000);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* injector channels #4-#8 are used for individual squirt test
|
|
|
|
*/
|
|
|
|
// todo: yet, it's some horrible code duplication
|
|
|
|
outSignals[0].output = &enginePins.injectors[4];
|
|
|
|
outSignals[1].output = &enginePins.injectors[5];
|
|
|
|
outSignals[2].output = &enginePins.injectors[6];
|
|
|
|
outSignals[3].output = &enginePins.injectors[7];
|
|
|
|
outSignals[4].output = &enginePins.injectors[8];
|
|
|
|
outSignals[5].output = &enginePins.injectors[9];
|
|
|
|
outSignals[6].output = &enginePins.injectors[10];
|
|
|
|
outSignals[7].output = &enginePins.injectors[11];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* this would schedule a callback in 2ms from now
|
|
|
|
*/
|
2019-01-09 04:57:43 -08:00
|
|
|
engine->executor.scheduleForLater("test", &ioTest, MS2US(2), testCallback, NULL);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|