-
Notifications
You must be signed in to change notification settings - Fork 6
/
measure.cpp
40 lines (34 loc) · 832 Bytes
/
measure.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "hwdefs.h"
#include "measure.h"
#include "Arduino.h"
static TMeasureCal calibration;
/**
* Initialises the measurement system.
*/
void MeasureInit(void)
{
pinMode(PIN_MEASURE_A, INPUT_ANALOG);
pinMode(PIN_MEASURE_V, INPUT_ANALOG);
calibration.cal_i = 1.0;
calibration.cal_v = 1.0;
}
/**
* Sets the calibration values.
*/
void MeasureCal(const TMeasureCal *cal)
{
calibration = *cal;
}
/**
* Gets a measurement.
*
* @param[out] time the timestamp for this measurement
* @param[out] the current (amperes)
* @param[out] the voltage (volts)
*/
void MeasureGet(unsigned long *time, float *current, float *voltage)
{
*time = micros();
*current = calibration.cal_i * 5.0 * analogRead(PIN_MEASURE_A) / 4096;
*voltage = calibration.cal_v * 19.8 * analogRead(PIN_MEASURE_V) / 4096;
}