From dbe0aaf636ccb78a3cc1281b6a1ea6c662af6756 Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Fri, 18 Dec 2020 15:23:31 -0600 Subject: Add AVR 1-Series and t1616 board and scripts --- spaghetti-monster/fsm-wdt.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'spaghetti-monster/fsm-wdt.c') diff --git a/spaghetti-monster/fsm-wdt.c b/spaghetti-monster/fsm-wdt.c index 9e8d9af..7bb8acc 100644 --- a/spaghetti-monster/fsm-wdt.c +++ b/spaghetti-monster/fsm-wdt.c @@ -23,6 +23,10 @@ #include #include +// *** Note for the AVRXMEGA3 (1-Series, eg 816 and 817), the WDT +// is not used for time-based interrupts. A new peripheral, the +// Periodic Interrupt Timer ("PIT") is used for this purpose. + void WDT_on() { #if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85) @@ -35,6 +39,10 @@ void WDT_on() #elif (ATTINY == 1634) wdt_reset(); // Reset the WDT WDTCSR = (1< 0) {} // make sure the register is ready to be updated + RTC.PITCTRLA = RTC_PERIOD_CYC512_gc | RTC_PITEN_bm; // Period = 16ms, enable the PI Timer #else #error Unrecognized MCU type #endif @@ -53,6 +61,10 @@ inline void WDT_slow() #elif (ATTINY == 1634) wdt_reset(); // Reset the WDT WDTCSR = (1< 0) {} // make sure the register is ready to be updated + RTC.PITCTRLA = RTC_PERIOD_CYC16384_gc | RTC_PITEN_bm; // Period = 0.5s, enable the PI Timer #else #error Unrecognized MCU type #endif @@ -75,13 +87,21 @@ inline void WDT_off() CCP = 0xD8; // enable config changes WDTCSR = 0; // disable and clear all WDT settings sei(); + #elif defined(AVRXMEGA3) // ATTINY816, 817, etc + while (RTC.PITSTATUS > 0) {} // make sure the register is ready to be updated + RTC.PITCTRLA = 0; // Disable the PI Timer #else #error Unrecognized MCU type #endif } // clock tick -- this runs every 16ms (62.5 fps) +#ifdef AVRXMEGA3 // ATTINY816, 817, etc +ISR(RTC_PIT_vect) { + RTC.PITINTFLAGS = RTC_PI_bm; // clear the PIT interrupt flag +#else ISR(WDT_vect) { +#endif irq_wdt = 1; // WDT event happened } -- cgit v1.2.3 From 8b67b3a6e21342aefb1fffef72469588ecab2614 Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Sun, 20 Dec 2020 12:27:05 -0600 Subject: Fix 1-Series standby tick speed, use 2C Turbo --- spaghetti-monster/fsm-wdt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spaghetti-monster/fsm-wdt.c') diff --git a/spaghetti-monster/fsm-wdt.c b/spaghetti-monster/fsm-wdt.c index 7bb8acc..ea2efac 100644 --- a/spaghetti-monster/fsm-wdt.c +++ b/spaghetti-monster/fsm-wdt.c @@ -64,7 +64,7 @@ inline void WDT_slow() #elif defined(AVRXMEGA3) // ATTINY816, 817, etc RTC.PITINTCTRL = RTC_PI_bm; // enable the Periodic Interrupt while (RTC.PITSTATUS > 0) {} // make sure the register is ready to be updated - RTC.PITCTRLA = RTC_PERIOD_CYC16384_gc | RTC_PITEN_bm; // Period = 0.5s, enable the PI Timer + RTC.PITCTRLA = (1<<6) | (STANDBY_TICK_SPEED<<3) | RTC_PITEN_bm; // Set period, enable the PI Timer #else #error Unrecognized MCU type #endif -- cgit v1.2.3