Skip to content

Commit 7761612

Browse files
author
Richard Unger
committed
working on voltage sense, not yet finished
1 parent 01d9b68 commit 7761612

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/voltage/GenericVoltageSense.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66

7-
GenericVoltageSense::GenericVoltageSense(int pin, float fullScaleVoltage, float gain, float offset, float Tf) : VoltageSense(gain, offset, Tf), fullScaleVoltage(fullScaleVoltage), pin(pin) {
7+
GenericVoltageSense::GenericVoltageSense(int pin, float gain, float offset, float Tf, float fullScaleVoltage) : VoltageSense(gain, offset, Tf), fullScaleVoltage(fullScaleVoltage), pin(pin) {
88
};
99

1010
#ifndef INPUT_ANALOG
@@ -38,7 +38,7 @@ bool GenericVoltageSense::init(int resolution){
3838

3939
float GenericVoltageSense::readRawVoltage(){
4040
uint32_t val = analogRead(pin);
41-
val = (val / maxValue) * fullScaleVoltage;
41+
val = (val / (float)maxValue) * fullScaleVoltage;
4242
return val;
4343
};
4444

src/voltage/GenericVoltageSense.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class GenericVoltageSense : public VoltageSense {
88
public:
9-
GenericVoltageSense(int pin, float fullScaleVoltage = 3.3f, float gain = 1.0f, float offset = 0.0f, float Tf = 0.1f);
9+
GenericVoltageSense(int pin, float gain = 1.0f, float offset = 0.0f, float Tf = 0.1f, float fullScaleVoltage = 3.3f);
1010
bool init(int resolution = -1);
1111
float fullScaleVoltage;
1212
protected:

src/voltage/VoltageSense.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ float VoltageSense::getVoltage(){
1818

1919
void VoltageSense::update(){
2020
float v = readRawVoltage();
21-
v = (v + offset) * gain;
21+
v = (v - offset) * gain;
2222
voltage = filter(v);
2323
};

0 commit comments

Comments
 (0)