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 */ /* returns current charge-current in mA */
double charger::getCurrent() { int charger::getCurrent() {
mux.setChannel(charger_settings.chI); mux.setChannel(charger_settings.chI);
int tmp = (int) io.readAdc(0); 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; return ret;
} }
@ -28,7 +28,7 @@ double charger::getCurrent() {
double charger::getVoltage() { double charger::getVoltage() {
mux.setChannel(charger_settings.chU); mux.setChannel(charger_settings.chU);
int tmp = (int) io.readAdc(0); int tmp = (int) io.readAdc(0);
double ret = ((double) tmp) * 1.00; //TODO calibration and testing double ret = ((double) tmp) * 0.00615;
return ret; return ret;
} }
@ -64,12 +64,15 @@ void charger::reset() {
/* updates the capacity */ /* updates the capacity */
void charger::update() { void charger::update() {
// 1sec / 3600
capacity = 1; const double div = 0.000277778;
capacity = capacity + ((unsigned int) (div * getCurrent()));
//serialSend("update\r\n");
/*
//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: public:
charger(const struct s_charger pCharger); charger(const struct s_charger pCharger);
~charger(); ~charger();
double getCurrent(); int getCurrent();
double getVoltage(); double getVoltage();
unsigned int getCapacity(); unsigned int getCapacity();
void setStartTime(struct time_t pTime); void setStartTime(struct time_t pTime);

View File

@ -32,9 +32,8 @@ int main(void) {
//loop till power off //loop till power off
while (true) { while (true) {
checkForBattery(); checkForBattery();
//printStatus(); printStatus();
updateChargers(); updateChargers();
} }
@ -69,9 +68,9 @@ void checkForBattery() {
bool zero = false; bool zero = false;
double tmp1 = 0.0; double tmp1 = 0.0;
double tmp2 = 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; tmp2 = tmp1;
tmp1 = chargers[l].getVoltage(); tmp1 = chargers[l].getVoltage();
@ -131,7 +130,11 @@ void printStatus() {
//serialSend("printing status .. \r\n"); //serialSend("printing status .. \r\n");
for (int i = 0; i < CHARGER_SIZE; i++) { for (int i = 0; i < CHARGER_SIZE; i++) {
if (chargers[i].getStatus()) { 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");
} }
} }
} }