a fork of priustroller

Dependencies:   mbed

Fork of priustroller_current by N K

Committer:
bwang
Date:
Sun Mar 08 08:37:38 2015 +0000
Revision:
11:dccbaa9274c5
Parent:
currentsensors.cpp@6:99ee0ce47fb2
Child:
24:f1ff9c7256b5
--Initial Commit: 03-08-2015 new context-based code; no more timers (=easier debugging)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bwang 0:54cf32d35f4d 1 #include "includes.h"
bwang 1:1f58bdcf2956 2 #include "sensors.h"
bwang 0:54cf32d35f4d 3
bwang 0:54cf32d35f4d 4 AnalogCurrentSensor::AnalogCurrentSensor(PinName pin, float volts_per_amp) {
bwang 0:54cf32d35f4d 5 _in = new AnalogIn(pin);
bwang 0:54cf32d35f4d 6 _volts_per_amp = volts_per_amp;
bwang 0:54cf32d35f4d 7 Zero();
bwang 0:54cf32d35f4d 8 }
bwang 0:54cf32d35f4d 9
bwang 0:54cf32d35f4d 10 void AnalogCurrentSensor::Zero() {
nki 6:99ee0ce47fb2 11 float mean = 0;
nki 6:99ee0ce47fb2 12 for(int i = 1; i<=1000; i++){
nki 6:99ee0ce47fb2 13 mean = 0.1f*((float) *_in) + 0.9f*mean;
nki 6:99ee0ce47fb2 14 }
nki 6:99ee0ce47fb2 15 _zero_level = mean;
bwang 0:54cf32d35f4d 16 }
bwang 0:54cf32d35f4d 17
bwang 0:54cf32d35f4d 18 float AnalogCurrentSensor::GetCurrent() {
bwang 0:54cf32d35f4d 19 return ((float) *_in - _zero_level) * 3.3f / _volts_per_amp;
bwang 0:54cf32d35f4d 20 }