Merge pull request #116 from luggi/Powermeter

fixed negative currents messing up the mAh counter
This commit is contained in:
dongie 2014-06-01 22:39:59 +09:00
commit d2e40b555d
3 changed files with 7 additions and 7 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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);