a fork of priustroller

Dependencies:   mbed

Fork of priustroller_current by N K

Committer:
bwang
Date:
Mon Mar 09 11:33:14 2015 +0000
Revision:
24:f1ff9c7256b5
Parent:
11:dccbaa9274c5
Child:
27:846c08fb3697
Added multi-channel debug logger in debug/, set up #channels and depth in main(), write in log() function. motor stops turning after trace is captured, requires reset to restart

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 24:f1ff9c7256b5 7 wait_us(100000);
bwang 0:54cf32d35f4d 8 Zero();
bwang 0:54cf32d35f4d 9 }
bwang 0:54cf32d35f4d 10
bwang 0:54cf32d35f4d 11 void AnalogCurrentSensor::Zero() {
nki 6:99ee0ce47fb2 12 float mean = 0;
bwang 24:f1ff9c7256b5 13 for(int i = 0; i < 1000; i++){
bwang 24:f1ff9c7256b5 14 mean += (float) *_in;
nki 6:99ee0ce47fb2 15 }
bwang 24:f1ff9c7256b5 16 _zero_level = mean / 1000;
bwang 0:54cf32d35f4d 17 }
bwang 0:54cf32d35f4d 18
bwang 0:54cf32d35f4d 19 float AnalogCurrentSensor::GetCurrent() {
bwang 0:54cf32d35f4d 20 return ((float) *_in - _zero_level) * 3.3f / _volts_per_amp;
bwang 0:54cf32d35f4d 21 }