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 */
|
||||
#if EFI_HIP_9011
|
||||
if (engineConfiguration->isHip9011Enabled) {
|
||||
hipAdcCallback(getFastAdc(hipSampleIndex));
|
||||
hipAdcCallback(adcToVoltsDivided(getFastAdc(hipSampleIndex)));
|
||||
}
|
||||
#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 */
|
||||
if (instance.adv_mode)
|
||||
return;
|
||||
|
@ -320,7 +320,9 @@ void hipAdcCallback(adcsample_t adcValue) {
|
|||
} else if (instance.state == WAITING_FOR_RESULT_ADC) {
|
||||
/* offload calculations to driver thread */
|
||||
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;
|
||||
hip_wake_driver();
|
||||
|
@ -483,19 +485,16 @@ static msg_t hipThread(void *arg) {
|
|||
|
||||
/* calculations */
|
||||
if (instance.adv_mode) {
|
||||
/* store for debug */
|
||||
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 */
|
||||
knockNormalized = ((float)rawValue) / HIP9011_DIGITAL_OUTPUT_MAX;
|
||||
/* convert to magic volts */
|
||||
knockVolts = knockNormalized * HIP9011_DESIRED_OUTPUT_VALUE;
|
||||
} else {
|
||||
rawValue = instance.rawValue[idx];
|
||||
/* first calculate ouput volts */
|
||||
knockVolts = adcToVolts(rawValue) * engineConfiguration->analogInputDividerCoefficient;
|
||||
/* and then normalize */
|
||||
knockNormalized = knockVolts / HIP9011_DESIRED_OUTPUT_VALUE;
|
||||
}
|
||||
/* convert to magic volts
|
||||
* TODO: remove conversion to volts */
|
||||
knockVolts = knockNormalized * HIP9011_ANALOG_OUTPUT_MAX;
|
||||
|
||||
/* Check for correct cylinder/input */
|
||||
if (correctCylinder) {
|
||||
|
|
|
@ -14,7 +14,7 @@ void initHip9011();
|
|||
void startHip9001_pins();
|
||||
void stopHip9001_pins();
|
||||
#if HAL_USE_ADC
|
||||
void hipAdcCallback(adcsample_t value);
|
||||
void hipAdcCallback(float volts);
|
||||
#endif /* HAL_USE_ADC */
|
||||
|
||||
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
|
||||
*/
|
||||
float integrationTimeUs = timeUs * 2 * CONST_PI * HIP9011_DESIRED_OUTPUT_VALUE;
|
||||
float integrationTimeUs = timeUs * 2 * CONST_PI * HIP9011_ANALOG_OUTPUT_MAX;
|
||||
/**
|
||||
* rpm = 60 seconds / time
|
||||
* '60000000' because revolutions per MINUTE in uS conversion
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#endif
|
||||
|
||||
#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 HIP_INPUT_CHANNELS 2
|
||||
|
||||
|
|
Loading…
Reference in New Issue