Reverted voltmeter code #bugfix

This commit is contained in:
Vsevolod Merenkov 2019-09-30 02:56:24 +03:00
parent a24e2ba970
commit e029364cdc
2 changed files with 16 additions and 19 deletions

View file

@ -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
rather than waiting for user input */
//#define VERBOSE true
@ -115,20 +112,6 @@ void setup() {
Serial.begin(9600);
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...");
@ -166,11 +149,10 @@ void loop() {
VComp = analogRead(VCOMP_SENSE_PIN);
VFol = analogRead(V_FOLLOW_PIN);
// Voltage Follower adjustment
VLast = VOld - Vin;
if (VLast > Hyst || VLast < -Hyst) {
// Voltage Follower adjustment
adjustFollow();
// Voltage Comparator adjustment
adjustComp();
// Alert the user that auto-calibration is ongoing

View file

@ -28,6 +28,21 @@ void pulse() {
long readVcc() {
// 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
while (bit_is_set(ADCSRA,ADSC)); // measuring