a fork of priustroller

Dependencies:   mbed

Fork of priustroller_current by N K

Revision:
24:f1ff9c7256b5
Parent:
11:dccbaa9274c5
Child:
27:846c08fb3697
--- a/sensors/currentsensors.cpp	Mon Mar 09 08:28:22 2015 +0000
+++ b/sensors/currentsensors.cpp	Mon Mar 09 11:33:14 2015 +0000
@@ -4,15 +4,16 @@
 AnalogCurrentSensor::AnalogCurrentSensor(PinName pin, float volts_per_amp) {
     _in = new AnalogIn(pin);
     _volts_per_amp = volts_per_amp;
+    wait_us(100000);
     Zero();
 }
 
 void AnalogCurrentSensor::Zero() {
     float mean = 0;
-    for(int i = 1; i<=1000; i++){
-        mean = 0.1f*((float) *_in) + 0.9f*mean;
+    for(int i = 0; i < 1000; i++){
+        mean += (float) *_in;
     }
-    _zero_level = mean;
+    _zero_level = mean / 1000;
 }
 
 float AnalogCurrentSensor::GetCurrent() {