Merge pull request #116 from luggi/Powermeter
fixed negative currents messing up the mAh counter
This commit is contained in:
commit
d2e40b555d
8
src/mw.c
8
src/mw.c
|
@ -14,7 +14,7 @@ int16_t headFreeModeHold;
|
|||
|
||||
uint16_t vbat; // battery voltage in 0.1V steps
|
||||
int32_t amperage; // amperage read by current sensor in centiampere (1/100th A)
|
||||
uint32_t mAhdrawn; // milliampere hours drawn from the battery since start
|
||||
int32_t mAhdrawn; // milliampere hours drawn from the battery since start
|
||||
int16_t telemTemperature1; // gyro sensor temperature
|
||||
|
||||
int16_t failsafeCnt = 0;
|
||||
|
@ -94,8 +94,8 @@ void annexCode(void)
|
|||
static uint8_t vbatTimer = 0;
|
||||
static int32_t vbatRaw = 0;
|
||||
static int32_t amperageRaw = 0;
|
||||
static uint32_t mAhdrawnRaw = 0;
|
||||
static uint32_t vbatCycleTime = 0;
|
||||
static int64_t mAhdrawnRaw = 0;
|
||||
static int32_t vbatCycleTime = 0;
|
||||
|
||||
int i;
|
||||
|
||||
|
@ -168,7 +168,7 @@ void annexCode(void)
|
|||
amperageRaw -= amperageRaw / 8;
|
||||
amperageRaw += adcGetChannel(ADC_EXTERNAL_CURRENT);
|
||||
amperage = currentSensorToCentiamps(amperageRaw / 8);
|
||||
mAhdrawnRaw += (amperage * vbatCycleTime) / 1000; // will overflow at ~11000mAh
|
||||
mAhdrawnRaw += (amperage * vbatCycleTime) / 1000;
|
||||
mAhdrawn = mAhdrawnRaw / (3600 * 100);
|
||||
vbatCycleTime = 0;
|
||||
}
|
||||
|
|
2
src/mw.h
2
src/mw.h
|
@ -369,7 +369,7 @@ extern uint16_t rssi; // range: [0;1023]
|
|||
extern uint16_t vbat; // battery voltage in 0.1V steps
|
||||
extern int16_t telemTemperature1; // gyro sensor temperature
|
||||
extern int32_t amperage; // amperage read by current sensor in 0.01A steps
|
||||
extern uint32_t mAhdrawn; // milli ampere hours drawn from battery since start
|
||||
extern int32_t mAhdrawn; // milli ampere hours drawn from battery since start
|
||||
extern uint8_t toggleBeep;
|
||||
|
||||
#define PITCH_LOOKUP_LENGTH 7
|
||||
|
|
|
@ -472,12 +472,12 @@ static void evaluateCommand(void)
|
|||
case MSP_ANALOG:
|
||||
headSerialReply(7);
|
||||
serialize8((uint8_t)constrain(vbat, 0, 255));
|
||||
serialize16(mAhdrawn); // milliamphours drawn from battery
|
||||
serialize16((uint16_t)constrain(mAhdrawn, 0, 0xFFFF)); // milliamphours drawn from battery
|
||||
serialize16(rssi);
|
||||
if (mcfg.multiwiicurrentoutput)
|
||||
serialize16((uint16_t)constrain((abs(amperage) * 10), 0, 0xFFFF)); // send amperage in 0.001 A steps
|
||||
else
|
||||
serialize16((uint16_t)abs(amperage)); // send amperage in 0.01 A steps
|
||||
serialize16((uint16_t)constrain(abs(amperage), 0, 0xFFFF)); // send amperage in 0.01 A steps
|
||||
break;
|
||||
case MSP_RC_TUNING:
|
||||
headSerialReply(7);
|
||||
|
|
Loading…
Reference in New Issue