Skip to content

Commit

Permalink
Added input parameter for vref constant #featureadd
Browse files Browse the repository at this point in the history
Added an option to change the vref constant over serial
  • Loading branch information
pyr0ball committed Sep 25, 2019
1 parent a58a7d0 commit e416f14
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
Expand Up @@ -27,16 +27,18 @@
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*]
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]
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_config.h
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions firmware/AVR-Source/Pyr0_Piezo_Sensor_v2.x.x/src/pP_serial.h
Expand Up @@ -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;
Expand Down Expand Up @@ -168,6 +178,9 @@ void serialPrintConfig()

Serial.print("HYST ");
Serial.println(Hyst);

Serial.print("VM_CONST ");
Serial.println(voltMeterConstant);
}

void serialPrintState()
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit e416f14

Please sign in to comment.