Added input parameter for vref constant #featureadd

Added an option to change the vref constant over serial
This commit is contained in:
pyr0ball 2019-09-25 14:43:53 -07:00
parent a58a7d029f
commit e416f14072
3 changed files with 39 additions and 5 deletions

View file

@ -27,9 +27,10 @@
by Alan "pyr0ball" Weinstock
This code is in the public domain.
*/
------------------------------------------------------------*/
/* To set the below parameters using serial input, use the following:
/*-----------------------------------------------------------
To set the below parameters using serial input, use the following:
To change trigger active duration: TRG_D [integer for milliseconds]
To change gain factor: GAIN_F [integer for gain state - see note*]
@ -37,6 +38,7 @@ To change ADC hysteresis value: HYST [integer]
To change sensor input pullup vRef low threshold: VFOL [integer in millivolts]
To change comparator trigger high threshold: VCOMP [integer in millivolts]
To change the duration between ADC measurements: LOOP_D [integer in milliseconds]
To update the internal vRef constant value **(see notes below): CONST [long value]
You can also enable or disable DEBUG output with: DEBUG [0|1]
@ -45,7 +47,6 @@ You can query the current state (including ADC measurements) with: STATE
To reset all settings to defaults, use: RESET
These commands should be wrapped in this format:
CMD INT
@ -62,9 +63,24 @@ The gain STATE is representative of these values:
2 = 4.33x
3 = 6x
4 = 11x
*/
/*------------------------------------------------------------*/
**Note for calibrating internal 1.1v vRef:
The ADC reading function assumes an "ideal" multiplier constant. Each Atmega
chip is slightly different, so it won't be completely accurate without tuning.
Most of the time this won't be necessary, so don't mess with this if you don't
know what you're doing!
The reading can be fine-tuned by using a multimeter, and this equation:
scale_constant = internal1.1Ref * 1023 * 1000
where
internal1.1Ref = 1.1 * Vcc1 (per voltmeter) / Vcc2 (per readVcc() function)
If the scale_constant calculated is different from the default 1125300,
update the voltMeterConstant variable in pP_config.h with the correct value
------------------------------------------------------------*/
// Debug output toggle. Uncomment to enable
#define DEBUG true

View file

@ -47,11 +47,13 @@
extern int Debug;
#endif
#define VM_CONST_ADDRESS 28
#if !(defined(voltMeterConstant))
extern long voltMeterConstant = 1125300L; // For fine tuning input voltage sense
#endif
#ifdef I2C_INPUT
#define I2C_SLAVE_ADDRESS 24
#if !(defined(pP_i2c_address))
extern byte pP_i2c_address = 0xa0; // I2C Bus Address
#endif

View file

@ -118,6 +118,16 @@ void updateHysteresis() {
}
/*------------------------------------------------*/
void updateConstant() {
if (serialInt >= 0)
{
voltMeterConstant = serialInt;
EEPROM.put(VM_CONST_ADDRESS, voltMeterConstant);
}
}
/*------------------------------------------------*/
void updateDebug() {
if (serialInt > 0) {
Debug = 1;
@ -168,6 +178,9 @@ void serialPrintConfig()
Serial.print("HYST ");
Serial.println(Hyst);
Serial.print("VM_CONST ");
Serial.println(voltMeterConstant);
}
void serialPrintState()
@ -212,6 +225,9 @@ void updateParams() {
else if (strcmp(serialMessageIn, "HYST") == 0) {
updateHysteresis();
}
else if (strcmp(serialMessageIn, "CONST") == 0) {
updateConstant();
}
else if (strcmp(serialMessageIn, "DEBUG") == 0) {
updateDebug();
}