auto-sync

This commit is contained in:
rusEfi 2015-01-14 22:03:40 -06:00
parent 95e172586f
commit 262449a085
9 changed files with 50 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);

View File

@ -465,6 +465,7 @@ fileVersion = { 20150112 }
firmwareTsVersion = scalar,U32, 84, "version", 1, 0
egt0 = scalar, S16, 88, "°C", 1, 0
egt1 = scalar, S16, 90, "°C", 1, 0
rpmAcceleration = scalar, F32, 104, "dRpm, 1, 0
egoCorrection = { 1 }
time = { timeNow }
engineLoad = { fuelAlgorithm == 0 ? MAF : TPS }
@ -601,6 +602,7 @@ fileVersion = { 20150112 }
dwellGauge = sparkDwell, "Dwell", "mSec", 0, 10, 0.5, 1.0, 6.0, 8.0, 1, 1
egt0Gauge = egt0, "EGT#0", "C", 0, 2000
vssGauge = vehicleSpeedKph, "Speed", "kmh", 0, 200, 0, 1, 3, 4, 1, 1
rpmAccelerationGa = rpmAcceleration, "rpm d", "dRpm", 0, 3, 0, 1, 3, 4, 1, 1
[FrontPage]
; Gauges are numbered left to right, top to bottom.
@ -660,6 +662,8 @@ fileVersion = { 20150112 }
entry = baseFuel, "baseFuel", float, "%.2f"
entry = ign_adv, "ignAdv", float, "%.2f"
entry = vehicleSpeedKph, "speed", float, "%.2f"
entry = rpmAcceleration, "dRPM", float, "%.3f"
; tpsADC = U16, "ADC",
; alignmet = U16, "al",