calibrated battery voltage

This commit is contained in:
Hendrik Schutter 2018-11-23 13:03:13 +01:00
parent 591e5557ac
commit bc5f43a2e5
3 changed files with 22 additions and 16 deletions

View File

@ -17,10 +17,10 @@ charger::~charger() {
}
/* returns current charge-current in mA */
double charger::getCurrent() {
int charger::getCurrent() {
mux.setChannel(charger_settings.chI);
int tmp = (int) io.readAdc(0);
double ret = ((double) tmp) * 1.00; //TODO calibration and testing
int ret = (int) (tmp * 1.0); //TODO calibration and testing
return ret;
}
@ -28,7 +28,7 @@ double charger::getCurrent() {
double charger::getVoltage() {
mux.setChannel(charger_settings.chU);
int tmp = (int) io.readAdc(0);
double ret = ((double) tmp) * 1.00; //TODO calibration and testing
double ret = ((double) tmp) * 0.00615;
return ret;
}
@ -64,12 +64,15 @@ void charger::reset() {
/* updates the capacity */
void charger::update() {
capacity = 1;
//serialSend("update\r\n");
// 1sec / 3600
const double div = 0.000277778;
capacity = capacity + ((unsigned int) (div * getCurrent()));
//serialSend("update\r\n");
/*
char charVal[10];
dtostrf(getCurrent(), 4, 0, charVal);
serialSend(charVal);
serialSend(" mA\r\n");
*/
}

View File

@ -27,7 +27,7 @@ private:
public:
charger(const struct s_charger pCharger);
~charger();
double getCurrent();
int getCurrent();
double getVoltage();
unsigned int getCapacity();
void setStartTime(struct time_t pTime);

View File

@ -32,9 +32,8 @@ int main(void) {
//loop till power off
while (true) {
checkForBattery();
//printStatus();
printStatus();
updateChargers();
}
@ -69,9 +68,9 @@ void checkForBattery() {
bool zero = false;
double tmp1 = 0.0;
double tmp2 = 0.0;
double difference = 5.0; //TODO after calibation
double difference = 0.1;
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 8; i++) {
tmp2 = tmp1;
tmp1 = chargers[l].getVoltage();
@ -131,7 +130,11 @@ void printStatus() {
//serialSend("printing status .. \r\n");
for (int i = 0; i < CHARGER_SIZE; i++) {
if (chargers[i].getStatus()) {
chargers[i].getInfo(); //print values
//chargers[i].getInfo(); //print values
char charVal[10];
dtostrf(chargers[i].getCurrent(), 4, 0, charVal);
serialSend(charVal);
serialSend(" mA\r\n");
}
}
}