Reverted voltmeter code #bugfix
This commit is contained in:
parent
a24e2ba970
commit
e029364cdc
2 changed files with 16 additions and 19 deletions
|
|
@ -82,9 +82,6 @@ update the voltMeterConstant variable in pP_config.h with the correct value
|
||||||
|
|
||||||
------------------------------------------------------------*/
|
------------------------------------------------------------*/
|
||||||
|
|
||||||
// Debug output toggle. Uncomment to enable
|
|
||||||
#define DEBUG true
|
|
||||||
|
|
||||||
/* Debug output verbose mode will continuously output sensor readings
|
/* Debug output verbose mode will continuously output sensor readings
|
||||||
rather than waiting for user input */
|
rather than waiting for user input */
|
||||||
//#define VERBOSE true
|
//#define VERBOSE true
|
||||||
|
|
@ -116,20 +113,6 @@ void setup() {
|
||||||
|
|
||||||
attachInterrupt(digitalPinToInterrupt(Z_TRG), pulse, FALLING);
|
attachInterrupt(digitalPinToInterrupt(Z_TRG), pulse, FALLING);
|
||||||
|
|
||||||
// Atmega's Secret Voltmeter setup:
|
|
||||||
// set the reference to Vcc and the measurement to the internal 1.1V reference
|
|
||||||
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
|
||||||
ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
|
|
||||||
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
|
|
||||||
ADMUX = _BV(MUX5) | _BV(MUX0);
|
|
||||||
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
|
|
||||||
ADMUX = _BV(MUX3) | _BV(MUX2);
|
|
||||||
#else
|
|
||||||
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
delay(2); // Wait for vref to settle
|
|
||||||
|
|
||||||
Serial.println("Initializing Pyr0-Piezo Sensor...");
|
Serial.println("Initializing Pyr0-Piezo Sensor...");
|
||||||
|
|
||||||
restoreConfig();
|
restoreConfig();
|
||||||
|
|
@ -166,11 +149,10 @@ void loop() {
|
||||||
VComp = analogRead(VCOMP_SENSE_PIN);
|
VComp = analogRead(VCOMP_SENSE_PIN);
|
||||||
VFol = analogRead(V_FOLLOW_PIN);
|
VFol = analogRead(V_FOLLOW_PIN);
|
||||||
|
|
||||||
// Voltage Follower adjustment
|
|
||||||
VLast = VOld - Vin;
|
VLast = VOld - Vin;
|
||||||
if (VLast > Hyst || VLast < -Hyst) {
|
if (VLast > Hyst || VLast < -Hyst) {
|
||||||
|
// Voltage Follower adjustment
|
||||||
adjustFollow();
|
adjustFollow();
|
||||||
|
|
||||||
// Voltage Comparator adjustment
|
// Voltage Comparator adjustment
|
||||||
adjustComp();
|
adjustComp();
|
||||||
// Alert the user that auto-calibration is ongoing
|
// Alert the user that auto-calibration is ongoing
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,21 @@ void pulse() {
|
||||||
|
|
||||||
long readVcc() {
|
long readVcc() {
|
||||||
// Read 1.1V reference against AVcc
|
// Read 1.1V reference against AVcc
|
||||||
|
|
||||||
|
// Atmega's Secret Voltmeter setup:
|
||||||
|
// set the reference to Vcc and the measurement to the internal 1.1V reference
|
||||||
|
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
|
||||||
|
ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
|
||||||
|
#elif defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
|
||||||
|
ADMUX = _BV(MUX5) | _BV(MUX0);
|
||||||
|
#elif defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
|
||||||
|
ADMUX = _BV(MUX3) | _BV(MUX2);
|
||||||
|
#else
|
||||||
|
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
delay(2); // Wait for vref to settle
|
||||||
|
|
||||||
ADCSRA |= _BV(ADSC); // Start conversion
|
ADCSRA |= _BV(ADSC); // Start conversion
|
||||||
while (bit_is_set(ADCSRA,ADSC)); // measuring
|
while (bit_is_set(ADCSRA,ADSC)); // measuring
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue