ADC and HIP: feed callback with voltage, not raw adc values (#4939)
* hip9011: use adcToVoltsDivided() helper * hip9011: feed callback with volts, not raw adc value
This commit is contained in:
parent
766ec5cde0
commit
f25edb646d
|
@ -189,7 +189,7 @@ void onFastAdcComplete(adcsample_t*) {
|
||||||
#endif /* EFI_MAP_AVERAGING */
|
#endif /* EFI_MAP_AVERAGING */
|
||||||
#if EFI_HIP_9011
|
#if EFI_HIP_9011
|
||||||
if (engineConfiguration->isHip9011Enabled) {
|
if (engineConfiguration->isHip9011Enabled) {
|
||||||
hipAdcCallback(getFastAdc(hipSampleIndex));
|
hipAdcCallback(adcToVoltsDivided(getFastAdc(hipSampleIndex)));
|
||||||
}
|
}
|
||||||
#endif /* EFI_HIP_9011 */
|
#endif /* EFI_HIP_9011 */
|
||||||
}
|
}
|
||||||
|
|
|
@ -311,7 +311,7 @@ void hip9011_onFireEvent(uint8_t cylinderNumber, efitick_t nowNt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void hipAdcCallback(adcsample_t adcValue) {
|
void hipAdcCallback(float volts) {
|
||||||
/* we read in digital mode */
|
/* we read in digital mode */
|
||||||
if (instance.adv_mode)
|
if (instance.adv_mode)
|
||||||
return;
|
return;
|
||||||
|
@ -320,7 +320,9 @@ void hipAdcCallback(adcsample_t adcValue) {
|
||||||
} else if (instance.state == WAITING_FOR_RESULT_ADC) {
|
} else if (instance.state == WAITING_FOR_RESULT_ADC) {
|
||||||
/* offload calculations to driver thread */
|
/* offload calculations to driver thread */
|
||||||
if (instance.channelIdx < HIP_INPUT_CHANNELS) {
|
if (instance.channelIdx < HIP_INPUT_CHANNELS) {
|
||||||
instance.rawValue[instance.channelIdx] = adcValue;
|
/* normalize to 0..HIP9011_DIGITAL_OUTPUT_MAX */
|
||||||
|
instance.rawValue[instance.channelIdx] =
|
||||||
|
volts * HIP9011_DIGITAL_OUTPUT_MAX / HIP9011_ANALOG_OUTPUT_MAX;
|
||||||
}
|
}
|
||||||
instance.state = NOT_READY;
|
instance.state = NOT_READY;
|
||||||
hip_wake_driver();
|
hip_wake_driver();
|
||||||
|
@ -483,19 +485,16 @@ static msg_t hipThread(void *arg) {
|
||||||
|
|
||||||
/* calculations */
|
/* calculations */
|
||||||
if (instance.adv_mode) {
|
if (instance.adv_mode) {
|
||||||
/* store for debug */
|
|
||||||
instance.rawValue[idx] = rawValue;
|
instance.rawValue[idx] = rawValue;
|
||||||
|
} else {
|
||||||
|
/* get value stored by callback */
|
||||||
|
rawValue = instance.rawValue[idx];
|
||||||
|
}
|
||||||
/* convert 10 bit integer value to 0.0 .. 1.0 float */
|
/* convert 10 bit integer value to 0.0 .. 1.0 float */
|
||||||
knockNormalized = ((float)rawValue) / HIP9011_DIGITAL_OUTPUT_MAX;
|
knockNormalized = ((float)rawValue) / HIP9011_DIGITAL_OUTPUT_MAX;
|
||||||
/* convert to magic volts */
|
/* convert to magic volts
|
||||||
knockVolts = knockNormalized * HIP9011_DESIRED_OUTPUT_VALUE;
|
* TODO: remove conversion to volts */
|
||||||
} else {
|
knockVolts = knockNormalized * HIP9011_ANALOG_OUTPUT_MAX;
|
||||||
rawValue = instance.rawValue[idx];
|
|
||||||
/* first calculate ouput volts */
|
|
||||||
knockVolts = adcToVolts(rawValue) * engineConfiguration->analogInputDividerCoefficient;
|
|
||||||
/* and then normalize */
|
|
||||||
knockNormalized = knockVolts / HIP9011_DESIRED_OUTPUT_VALUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check for correct cylinder/input */
|
/* Check for correct cylinder/input */
|
||||||
if (correctCylinder) {
|
if (correctCylinder) {
|
||||||
|
|
|
@ -14,7 +14,7 @@ void initHip9011();
|
||||||
void startHip9001_pins();
|
void startHip9001_pins();
|
||||||
void stopHip9001_pins();
|
void stopHip9001_pins();
|
||||||
#if HAL_USE_ADC
|
#if HAL_USE_ADC
|
||||||
void hipAdcCallback(adcsample_t value);
|
void hipAdcCallback(float volts);
|
||||||
#endif /* HAL_USE_ADC */
|
#endif /* HAL_USE_ADC */
|
||||||
|
|
||||||
void hip9011_onFireEvent(uint8_t cylinderNumber, efitick_t nowNt);
|
void hip9011_onFireEvent(uint8_t cylinderNumber, efitick_t nowNt);
|
||||||
|
|
|
@ -110,7 +110,7 @@ float HIP9011::getRpmByAngleWindowAndTimeUs(int timeUs, float angleWindowWidth)
|
||||||
/**
|
/**
|
||||||
* TINT = TC * 2 * PI * VOUT
|
* TINT = TC * 2 * PI * VOUT
|
||||||
*/
|
*/
|
||||||
float integrationTimeUs = timeUs * 2 * CONST_PI * HIP9011_DESIRED_OUTPUT_VALUE;
|
float integrationTimeUs = timeUs * 2 * CONST_PI * HIP9011_ANALOG_OUTPUT_MAX;
|
||||||
/**
|
/**
|
||||||
* rpm = 60 seconds / time
|
* rpm = 60 seconds / time
|
||||||
* '60000000' because revolutions per MINUTE in uS conversion
|
* '60000000' because revolutions per MINUTE in uS conversion
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define HIP9011_BAND(bore) (900 / (CONST_PI * (bore) / 2))
|
#define HIP9011_BAND(bore) (900 / (CONST_PI * (bore) / 2))
|
||||||
#define HIP9011_DESIRED_OUTPUT_VALUE 5.0f
|
#define HIP9011_ANALOG_OUTPUT_MAX 5.0f
|
||||||
#define HIP9011_DIGITAL_OUTPUT_MAX 0x03ff /* 10 bit max value */
|
#define HIP9011_DIGITAL_OUTPUT_MAX 0x03ff /* 10 bit max value */
|
||||||
#define HIP_INPUT_CHANNELS 2
|
#define HIP_INPUT_CHANNELS 2
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue