-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurrentMonitor.cpp
More file actions
40 lines (34 loc) · 848 Bytes
/
CurrentMonitor.cpp
File metadata and controls
40 lines (34 loc) · 848 Bytes
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
40
#include "CurrentMonitor.h"
#include "Calibration.h"
using namespace std;
CurrentMonitor::CurrentMonitor()
{
ina219.begin();
_desiredCurrent = 0;
}
// i: The desired current value in mA, from 0-1000
void CurrentMonitor::SetDesiredCurrent(unsigned int i)
{
_desiredCurrent = map(i,0,1000,0,4095);
analogWrite(isetPin, _desiredCurrent);
}
// Returns: The sense current from op amps
int CurrentMonitor::ReadHiSenseCurrent()
{
calibrateAdc();
// Map current from ADC value to mA scale
return map(analogRead(isensePin) + gVoltageCalibrationOffset,0,4095,0,1000);
}
// TODO: Change the current gain register to provide mode accurate measurements
float CurrentMonitor::ReadSenseCurrent()
{
float current_mA = ina219.getCurrent_mA();
if (current_mA >= 320.00)
{
return (float)ReadHiSenseCurrent();
}
else
{
return current_mA;
}
}