From c486e1f01ec128d9c485e546ccec0d7d856ce45b Mon Sep 17 00:00:00 2001 From: Mike Naberezny Date: Tue, 21 Nov 2023 13:24:47 -0800 Subject: [PATCH] Drop down to 1 MHz to save a little power --- firmware/fuses.asm | 2 +- firmware/main.asm | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/firmware/fuses.asm b/firmware/fuses.asm index 6a41566..dac8ac6 100644 --- a/firmware/fuses.asm +++ b/firmware/fuses.asm @@ -13,7 +13,7 @@ ;Oscillator Configuration .org 0+FUSE_OSCCFG_offset -.byte (0<INTERNAL_SRAM_START @@ -75,7 +82,15 @@ reset: rcall eeprom_read_contacts ;Read 4066 contacts saved in EEPROM rcall gpio_write_contacts ; and restore the 4066 to that state - ldi r16, 0 ;Initialize variables to defaults + ;Now that the 4066 is set up, drop down to 1 MHz. The clock + ;will run at 1 MHz from now on to save a little power. + ldi r16, CPU_CCP_IOREG_gc + ldi r17, 0x03<<1 | CLKCTRL_PEN_bm ;Prescaler for 1 MHz + out CPU_CCP, r16 ;Unlock Protected I/O Registers + sts CLKCTRL_MCLKCTRLB, r17 ;Set main clock prescaler + + ;Initialize variables to defaults + clr r16 sts current_keys, r16 sts previous_keys, r16 sts lock0_down_ticks, r16 @@ -107,7 +122,7 @@ main_loop: ;Check each key and toggle its 4066 contact if it was just pushed down. ; task_keys: - ldi r18, 1<EEPROM_START brne 1$ - ldi r16, 0 ;EEPROM is empty; return 0 (all off) + clr r16 ;EEPROM is empty; return 0 (all off) 2$: ret ;Store R16 as the 4066 contact state in the EEPROM