mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 20:35:33 +03:00
Merge pull request #4743 from Dimand/Current_calibration_fix
Changed the current calibration to be more sensible
This commit is contained in:
commit
7a7f1ceda5
2 changed files with 5 additions and 4 deletions
|
@ -107,9 +107,10 @@ static int32_t currentMeterADCToCentiamps(const uint16_t src)
|
||||||
const currentSensorADCConfig_t *config = currentSensorADCConfig();
|
const currentSensorADCConfig_t *config = currentSensorADCConfig();
|
||||||
|
|
||||||
int32_t millivolts = ((uint32_t)src * ADCVREF) / 4096;
|
int32_t millivolts = ((uint32_t)src * ADCVREF) / 4096;
|
||||||
millivolts -= config->offset;
|
// y=x/m+b m is scale in (mV/10A) and b is offset in (mA)
|
||||||
|
int32_t centiAmps = (millivolts * 10000 / (int32_t)config->scale + (int32_t)config->offset) / 10;
|
||||||
|
|
||||||
return (millivolts * 1000) / (int32_t)config->scale; // current in 0.01A steps
|
return centiAmps; // Returns Centiamps to maintain compatability with the rest of the code
|
||||||
}
|
}
|
||||||
|
|
||||||
static void updateCurrentmAhDrawnState(currentMeterMAhDrawnState_t *state, int32_t amperageLatest, int32_t lastUpdateAt)
|
static void updateCurrentmAhDrawnState(currentMeterMAhDrawnState_t *state, int32_t amperageLatest, int32_t lastUpdateAt)
|
||||||
|
|
|
@ -65,8 +65,8 @@ typedef struct currentMeterADCState_s {
|
||||||
} currentMeterADCState_t;
|
} currentMeterADCState_t;
|
||||||
|
|
||||||
typedef struct currentSensorADCConfig_s {
|
typedef struct currentSensorADCConfig_s {
|
||||||
int16_t scale; // scale the current sensor output voltage to milliamps. Value in 1/10th mV/A
|
int16_t scale; // scale the current sensor output voltage to milliamps. Value in mV/10A
|
||||||
int16_t offset; // offset of the current sensor in millivolt steps
|
int16_t offset; // offset of the current sensor in mA
|
||||||
} currentSensorADCConfig_t;
|
} currentSensorADCConfig_t;
|
||||||
|
|
||||||
PG_DECLARE(currentSensorADCConfig_t, currentSensorADCConfig);
|
PG_DECLARE(currentSensorADCConfig_t, currentSensorADCConfig);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue