aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-04-26 01:34:53 -0600
committerSelene ToyKeeper2023-04-26 01:34:53 -0600
commitaa4c627377b07cc07cd1e904f9f7d2f24c1155a4 (patch)
tree8d3e17b3d1f974ca20fd6b929c788ea2c91a7527
parentput RGB aux LEDs in high mode for 3 seconds after light goes to sleep (diff)
downloadanduril-aa4c627377b07cc07cd1e904f9f7d2f24c1155a4.tar.gz
anduril-aa4c627377b07cc07cd1e904f9f7d2f24c1155a4.tar.bz2
anduril-aa4c627377b07cc07cd1e904f9f7d2f24c1155a4.zip
made sleep voltage work on attiny1616 again
(oops, it has no "ADC Noise Reduction" mode... needs different setup code)
-rw-r--r--spaghetti-monster/fsm-adc.c25
-rw-r--r--spaghetti-monster/fsm-adc.h4
-rw-r--r--spaghetti-monster/fsm-standby.c8
3 files changed, 31 insertions, 6 deletions
diff --git a/spaghetti-monster/fsm-adc.c b/spaghetti-monster/fsm-adc.c
index 0b79767..a196b7b 100644
--- a/spaghetti-monster/fsm-adc.c
+++ b/spaghetti-monster/fsm-adc.c
@@ -12,6 +12,8 @@
#define ADMUX_THERM ADMUX_THERM_EXTERNAL_SENSOR
#endif
+#include <avr/sleep.h>
+
static inline void set_admux_therm() {
#if (ATTINY == 1634)
@@ -70,6 +72,29 @@ inline void set_admux_voltage() {
ADC_start_measurement();
}
+
+#ifdef TICK_DURING_STANDBY
+inline void adc_sleep_mode() {
+ // needs a special sleep mode to get accurate measurements quickly
+ // ... full power-down ends up using more power overall, and causes
+ // some weird issues when the MCU doesn't stay awake enough cycles
+ // to complete a reading
+ #ifdef SLEEP_MODE_ADC
+ // 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.
+ #endif
+}
+#endif
+
inline void ADC_start_measurement() {
#if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85) || (ATTINY == 841) || (ATTINY == 1634)
ADCSRA |= (1 << ADSC) | (1 << ADIE);
diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h
index b25b650..1bb67ed 100644
--- a/spaghetti-monster/fsm-adc.h
+++ b/spaghetti-monster/fsm-adc.h
@@ -106,3 +106,7 @@ inline void ADC_on();
inline void ADC_off();
inline void ADC_start_measurement();
+#ifdef TICK_DURING_STANDBY
+inline void adc_sleep_mode();
+#endif
+
diff --git a/spaghetti-monster/fsm-standby.c b/spaghetti-monster/fsm-standby.c
index 2ce3a24..5def07c 100644
--- a/spaghetti-monster/fsm-standby.c
+++ b/spaghetti-monster/fsm-standby.c
@@ -41,12 +41,8 @@ void sleep_until_eswitch_pressed()
// configure sleep mode
#ifdef TICK_DURING_STANDBY
- // needs a special sleep mode to get accurate measurements
- // quickly ... full power-down ends up using more power
- // overall, and causes some weird issues when the MCU
- // doesn't stay awake enough cycles to complete a reading
- if (adc_active_now)
- set_sleep_mode(SLEEP_MODE_ADC);
+ // needs a special sleep mode during measurements
+ if (adc_active_now) adc_sleep_mode();
else
#endif
set_sleep_mode(SLEEP_MODE_PWR_DOWN);