aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-07-08 03:55:02 -0600
committerSelene ToyKeeper2023-07-08 03:55:02 -0600
commit7400cbf6a1370035400607c22d57366c54304fb9 (patch)
treecb035598852203bb92a36cd63f2039e79c1c0b59
parentadded Noctigon M44 sources (diff)
downloadanduril-7400cbf6a1370035400607c22d57366c54304fb9.tar.gz
anduril-7400cbf6a1370035400607c22d57366c54304fb9.tar.bz2
anduril-7400cbf6a1370035400607c22d57366c54304fb9.zip
Fixed spurious voltage warnings in attiny1616 sleep mode. Fixed by SammysHP.
https://budgetlightforum.com/t/anduril-2-feature-change-suggestions/218045/467 I was never able to reproduce the issue here, but the fix seems good and others tested it successfully.
-rw-r--r--spaghetti-monster/fsm-adc.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/spaghetti-monster/fsm-adc.c b/spaghetti-monster/fsm-adc.c
index a196b7b..d11cca8 100644
--- a/spaghetti-monster/fsm-adc.c
+++ b/spaghetti-monster/fsm-adc.c
@@ -83,11 +83,6 @@ inline void adc_sleep_mode() {
// attiny1634
set_sleep_mode(SLEEP_MODE_ADC);
#elif defined(AVRXMEGA3) // ATTINY816, 817, etc
- // set the RUNSTDBY bit so ADC will run in standby mode
- ADC0.CTRLA |= 1;
- // set a INITDLY value because the AVR manual says so
- // (section 30.3.5)
- ADC0.CTRLD |= (1 << 5);
set_sleep_mode(SLEEP_MODE_STANDBY);
#else
#error No ADC sleep mode defined for this hardware.
@@ -133,10 +128,13 @@ inline void ADC_on()
ADCSRA = (1 << ADEN) | (1 << ADSC) | (1 << ADATE) | ADC_PRSCL;
//ADCSRA |= (1 << ADSC); // start measuring
#elif defined(AVRXMEGA3) // ATTINY816, 817, etc
- set_admux_voltage();
VREF.CTRLA |= VREF_ADC0REFSEL_1V1_gc; // Set Vbg ref to 1.1V
- ADC0.CTRLA = ADC_ENABLE_bm | ADC_FREERUN_bm; // Enabled, free-running (aka, auto-retrigger)
- ADC0.COMMAND |= ADC_STCONV_bm; // Start the ADC conversions
+ // Enabled, free-running (aka, auto-retrigger), run in standby
+ ADC0.CTRLA = ADC_ENABLE_bm | ADC_FREERUN_bm | ADC_RUNSTBY_bm;
+ // set a INITDLY value because the AVR manual says so (section 30.3.5)
+ // (delay 1st reading until Vref is stable)
+ ADC0.CTRLD |= ADC_INITDLY_DLY16_gc;
+ set_admux_voltage();
#else
#error Unrecognized MCU type
#endif
@@ -144,7 +142,7 @@ inline void ADC_on()
inline void ADC_off() {
#ifdef AVRXMEGA3 // ATTINY816, 817, etc
- ADC0.CTRLA &= ~(ADC_ENABLE_bm); // disable the ADC
+ ADC0.CTRLA &= ~(ADC_ENABLE_bm); // disable the ADC
#else
ADCSRA &= ~(1<<ADEN); //ADC off
#endif
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.