Skip to content

Commit

Permalink
Fix analog to volts convertion.
Browse files Browse the repository at this point in the history
  • Loading branch information
rpineau committed Oct 15, 2018
1 parent a4b7bfd commit 98fef8c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
17 changes: 9 additions & 8 deletions PDMRotator/RotatorClass.h
@@ -1,14 +1,14 @@
/*
* PDM NexDome Rotation kit firmware. NOT compatible with original NexDome ASCOM driver.
*
* Copyright © 2018 Patrick Meloy
* Copyright 2018 Patrick Meloy
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
* files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy,
* files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
* is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Expand Down Expand Up @@ -185,6 +185,7 @@ class RotatorClass
int _moveDirection;

// Power values
float adcConvert;
int _volts;
int _cutOffVolts;
int ReadVolts();
Expand All @@ -205,6 +206,7 @@ class RotatorClass

RotatorClass::RotatorClass()
{
adcConvert = 3.0 * (5.0 / 1023.0) * 100;
LoadFromEEProm();
pinMode(HOME_PIN, INPUT_PULLUP);
pinMode(STEP_PIN, OUTPUT);
Expand Down Expand Up @@ -295,13 +297,12 @@ void RotatorClass::SetDefaultConfig()

int RotatorClass::ReadVolts()
{
int adc;
float calc;

calc = analogRead(VOLTAGE_MONITOR_PIN);
calc = calc / 2;
calc = calc * 3;
_volts = (int)calc;
return (int)calc;
adc = analogRead(VOLTAGE_MONITOR_PIN);
calc = adc * adcConvert;
return int(calc);
}
void RotatorClass::SetLowVoltageCutoff(int lowVolts)
{
Expand Down
18 changes: 10 additions & 8 deletions PDMShutter/PDMShutterClass.h
Expand Up @@ -149,6 +149,7 @@ class ShutterClass
// uint8_t _openedPin;
// uint8_t _enablePin;

float adcConvert;
uint16_t _volts;
uint64_t _batteryCheckInterval = 120000;
uint16_t _cutoffVolts = 1220;
Expand All @@ -161,7 +162,7 @@ class ShutterClass
// uint8_t _stepMode;


float MeasureVoltage();
int MeasureVoltage();
void DefaultEEProm();
};

Expand All @@ -173,6 +174,7 @@ class ShutterClass

ShutterClass::ShutterClass()
{
adcConvert = 3.0 * (5.0 / 1023.0) * 100;
ReadEEProm();
//_openedPin = OPENED_PIN;
//_closedPin = CLOSED_PIN;
Expand Down Expand Up @@ -284,16 +286,16 @@ void ShutterClass::DoButtons()
lastButtonPressed = whichButtonPressed = 0;
}
}
float ShutterClass::MeasureVoltage()

int ShutterClass::MeasureVoltage()
{
int volts, adc;
int adc;
float calc;

adc = analogRead(VOLTAGE_MONITOR_PIN);
DBPrintln("ADC returns " + String(adc));
calc = adc * 3.0 * (5.0 / 1023.0);
_volts = volts = calc * 100;
return volts;
calc = adc * adcConvert;
return int(calc);
}

// Helper functions
Expand Down Expand Up @@ -360,7 +362,7 @@ String ShutterClass::GetVoltString()
}

// Setters
void ShutterClass::EnableOutputs(bool newState)
void ShutterClass::EnableOutputs(bool newState)
{
if (newState == false)
{
Expand Down Expand Up @@ -503,7 +505,7 @@ void ShutterClass::Run()
if (nextBatteryCheck < millis() && isConfiguringWireless == false)
{
DBPrintln("Measuring Battery");
MeasureVoltage();
_volts = MeasureVoltage();
Wireless.println("K" + GetVoltString());
if (firstBatteryCheck == true)
{
Expand Down

0 comments on commit 98fef8c

Please sign in to comment.