N K
/
GaNtroller
a fork of priustroller
Fork of priustroller_current by
sensors/currentsensors.cpp
- Committer:
- nki
- Date:
- 2015-03-14
- Revision:
- 27:846c08fb3697
- Parent:
- 24:f1ff9c7256b5
- Child:
- 28:af9d43bcb371
File content as of revision 27:846c08fb3697:
#include "includes.h" #include "sensors.h" 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; float last = 0; float count = 0; while(count <= 1000){ if(*_in != last){ mean = 0.99f * mean + (1.0f - 0.99f)*(*_in); count += 1.0f; } } _zero_level = mean; } float AnalogCurrentSensor::GetCurrent() { return ((float) *_in - _zero_level) * 3.3f / _volts_per_amp; }