auto-sync

This commit is contained in:
rusEfi 2015-01-14 22:03:40 -06:00
parent 85b43ccee5
commit b9a811ea8e
8 changed files with 46 additions and 6 deletions

View File

@ -505,6 +505,7 @@ void updateTunerStudioState(Engine *engine, TunerStudioOutputChannels *tsOutputC
tsOutputChannels->atmospherePressure = getBaroPressure();
tsOutputChannels->manifold_air_pressure = getMap();
tsOutputChannels->engineLoad = engineLoad;
tsOutputChannels->rpmAcceleration = engine->rpmCalculator.getRpmAcceleration();
tsOutputChannels->checkEngine = hasErrorCodes();
#if EFI_PROD_CODE

View File

@ -80,7 +80,8 @@ typedef struct {
unsigned int isAcSwitchEngaged : 1; // bit 4
int tsConfigVersion;
egt_values_s egtValues;
int unused3[3];
float rpmAcceleration;
int unused3[2];
} TunerStudioOutputChannels;
#endif /* TUNERSTUDIO_CONFIGURATION_H_ */

View File

@ -612,7 +612,8 @@ typedef struct {
*/
brain_pin_e clutchUpPin;
pin_input_mode_e clutchUpPinMode;
int unused3[182];
float hipThreshold;
int unused3[181];
le_formula_t timingMultiplier;
le_formula_t timingAdditive;

View File

@ -68,6 +68,7 @@ bool RpmCalculator::isRunning(DECLARE_ENGINE_PARAMETER_F) {
}
void RpmCalculator::setRpmValue(int value) {
previousRpmValue = rpmValue;
rpmValue = value;
if (rpmValue <= 0) {
oneDegreeUs = NAN;
@ -89,6 +90,10 @@ uint32_t RpmCalculator::getRevolutionCounterSinceStart(void) {
return revolutionCounterSinceStart;
}
float RpmCalculator::getRpmAcceleration() {
return 1.0 * previousRpmValue / rpmValue;
}
/**
* WARNING: this is a heavy method because 'getRpm()' is relatively heavy
*

View File

@ -38,14 +38,19 @@ public:
*/
bool isRunning(DECLARE_ENGINE_PARAMETER_F);
int rpm(DECLARE_ENGINE_PARAMETER_F);
/**
* This method is invoked once per engine cycle right after we calculate new RPM value
*/
void onNewEngineCycle();
uint32_t getRevolutionCounter(void);
void setRpmValue(int value);
uint32_t getRevolutionCounterSinceStart(void);
float getRpmAcceleration();
/**
* This is public because sometimes we cannot afford to call isRunning() and the value is good enough
*/
volatile int rpmValue;
int previousRpmValue;
/**
* This is a performance optimization: let's pre-calulate this each time RPM changes
*/

View File

@ -32,6 +32,7 @@
#include "trigger_central.h"
#include "hip9011_lookup.h"
#include "HIP9011.h"
#include "adc_inputs.h"
#if EFI_HIP_9011 || defined(__DOXYGEN__)
@ -47,6 +48,10 @@ static int bandIndex;
static int currentGainIndex = -1;
static int currentIntergratorIndex = -1;
static int settingUpdateCount = 0;
static int totalKnockEventsCount = 0;
static hip_state_e state = READY_TO_INTEGRATE;
static efitimeus_t timeOfLastKnockEvent = 0;
/**
* Int/Hold pin is controlled from scheduler callbacks which are set according to current RPM
@ -96,9 +101,11 @@ static void showHipInfo(void) {
scheduleMsg(logger, "bore=%f freq=%f", engineConfiguration->cylinderBore, BAND(engineConfiguration->cylinderBore));
scheduleMsg(logger, "band_index=%d gain %f/index=%d", bandIndex, boardConfiguration->hip9011Gain, currentGainIndex);
scheduleMsg(logger, "integrator index=%d", currentIntergratorIndex);
scheduleMsg(logger, "integrator index=%d hip_threshold=%f totalKnockEventsCount=%d", currentIntergratorIndex,
engineConfiguration->hipThreshold, totalKnockEventsCount);
scheduleMsg(logger, "spi= int=%s response count=%d", hwPortname(boardConfiguration->hip9011IntHoldPin), nonZeroResponse);
scheduleMsg(logger, "spi= int=%s response count=%d", hwPortname(boardConfiguration->hip9011IntHoldPin),
nonZeroResponse);
scheduleMsg(logger, "CS=%s updateCount=%d", hwPortname(boardConfiguration->hip9011CsPin), settingUpdateCount);
}
@ -110,6 +117,8 @@ void setHip9011FrankensoPinout(void) {
boardConfiguration->hip9011CsPin = GPIOD_0;
boardConfiguration->hip9011IntHoldPin = GPIOB_11;
boardConfiguration->is_enabled_spi_2 = true;
engineConfiguration->hipThreshold = 2;
}
static void startIntegration(void) {
@ -119,6 +128,7 @@ static void startIntegration(void) {
* until we are done integrating
*/
isIntegrating = true;
state = IS_INTEGRATING;
intHold.setValue(true);
}
}
@ -136,6 +146,7 @@ static void endIntegration(void) {
int gainIndex = getHip9011GainIndex(boardConfiguration->hip9011Gain);
if (currentGainIndex != gainIndex) {
state = IS_SENDING_SPI_COMMAND;
tx_buff[0] = gainIndex;
currentGainIndex = gainIndex;
@ -146,6 +157,7 @@ static void endIntegration(void) {
}
if (currentIntergratorIndex != integratorIndex) {
state = IS_SENDING_SPI_COMMAND;
tx_buff[0] = integratorIndex;
currentIntergratorIndex = integratorIndex;
@ -154,6 +166,7 @@ static void endIntegration(void) {
spiStartExchangeI(driver, 1, tx_buff, rx_buff);
return;
}
state = READY_TO_INTEGRATE;
}
}
@ -190,7 +203,14 @@ static void endOfSpiCommunication(SPIDriver *spip) {
}
void hipAdcCallback(adcsample_t value) {
if (state == WAITING_FOR_ADC_TO_SKIP) {
state = WAITING_FOR_RESULT_ADC;
} else if (state == WAITING_FOR_RESULT_ADC) {
if (adcToVoltsDivided(value) > engineConfiguration->hipThreshold) {
totalKnockEventsCount++;
timeOfLastKnockEvent = getTimeNowUs();
}
}
}
void initHip9011(Logging *sharedLogger) {

View File

@ -9,6 +9,14 @@
#ifndef HIP9011_H_
#define HIP9011_H_
typedef enum {
READY_TO_INTEGRATE,
IS_INTEGRATING,
IS_SENDING_SPI_COMMAND,
WAITING_FOR_ADC_TO_SKIP,
WAITING_FOR_RESULT_ADC,
} hip_state_e;
// 0b01000000
#define SET_PRESCALER_CMD 0x40

View File

@ -14,7 +14,6 @@
#if HAL_USE_ADC || defined(__DOXYGEN__)
const char * getAdcMode(adc_channel_e hwChannel);
int getAdcChannelPin(adc_channel_e hwChannel);
void initAdcInputs(bool boardTestMode);