From cbfc1a13a9c9a8c08c054658ed26d2350383d209 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 30 Jan 2024 14:54:13 -0700 Subject: [PATCH] avr32dd20-devkit: use unimplemented "CH" pin as a boost bypass control For 3V LEDs on a boost/buck dual fuel driver, this allows routing power around the boost converter in li-ion mode, to reduce resistance and increase maximum output. The AA/NiMH mode is unaffected, and boosts as normal. --- hw/thefreeman/avr32dd20-devkit/hwdef.c | 13 +++++++++++++ hw/thefreeman/avr32dd20-devkit/hwdef.h | 22 ++++++++++++++++++++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/hw/thefreeman/avr32dd20-devkit/hwdef.c b/hw/thefreeman/avr32dd20-devkit/hwdef.c index 3e5dd797..460082fd 100644 --- a/hw/thefreeman/avr32dd20-devkit/hwdef.c +++ b/hw/thefreeman/avr32dd20-devkit/hwdef.c @@ -30,6 +30,11 @@ void set_level_zero() { delay_4ms(IN_NFET_DELAY_TIME/4); IN_NFET_ENABLE_PORT &= ~(1 << IN_NFET_ENABLE_PIN); + #ifdef USE_BST_BYPASS + // turn off bypass + BST_BYPASS_PORT |= (1 << BST_BYPASS_PIN); + #endif + // turn off boost last BST_ENABLE_PORT &= ~(1 << BST_ENABLE_PIN); // BST off } @@ -48,6 +53,14 @@ void set_level_main(uint8_t level) { // BST on first, to give it a few extra microseconds to spin up BST_ENABLE_PORT |= (1 << BST_ENABLE_PIN); + #ifdef USE_BST_BYPASS + // turn on bypass in li-ion mode + if (voltage > DUAL_VOLTAGE_FLOOR) + BST_BYPASS_PORT &= ~(1 << BST_BYPASS_PIN); // low = bypass + else // turn off bypass in AA/NiMH mode + BST_BYPASS_PORT |= (1 << BST_BYPASS_PIN); // high = boost + #endif + // pre-load ramp data so it can be assigned faster later // DAC level register is left-aligned PWM1_DATATYPE dac_lvl = PWM1_GET(level) << 6; diff --git a/hw/thefreeman/avr32dd20-devkit/hwdef.h b/hw/thefreeman/avr32dd20-devkit/hwdef.h index f1b60953..231f74ad 100644 --- a/hw/thefreeman/avr32dd20-devkit/hwdef.h +++ b/hw/thefreeman/avr32dd20-devkit/hwdef.h @@ -28,6 +28,7 @@ * 18 PA1 G: aux green * 19 PA2 B: aux blue * 20 PA3 CH: detect charging + * or BBY: boost bypass PFET * * BST EN enable the boost regulator and Op-Amp * DAC sets the current, max current depends on Vset voltage divider and Rsense @@ -35,6 +36,8 @@ * and low value Rsense (high current range, pin high) * IN- NFET : pull up after BST enable to eliminate startup flash, pull down otherwise * CH senses the status of the onboard charger + * BBY routes power around the boost converter in li-ion 3V mode + * (pin low = bypass, pin high = boost) * BATT LVL : Vbat * (100.0/(330+100)) * LVB is for OTSM firmware, not used here */ @@ -77,6 +80,11 @@ enum CHANNEL_MODES { #define BST_ENABLE_PIN PIN5_bp #define BST_ENABLE_PORT PORTD_OUT +// BST bypass +#define USE_BST_BYPASS +#define BST_BYPASS_PIN PIN3_bp +#define BST_BYPASS_PORT PORTA_OUT + // HDR // turns on HDR FET for the high current range #define HDR_ENABLE_PIN PIN7_bp @@ -133,7 +141,9 @@ inline void hwdef_setup() { VPORTA.DIR = PIN0_bm // R | PIN1_bm // G | PIN2_bm // B - //| PIN3_bm // CH + #ifdef USE_BST_BYPASS + | PIN3_bm // BBY + #endif | PIN7_bm; // HDR VPORTD.DIR = PIN5_bm // EN | PIN6_bm // DAC @@ -143,7 +153,9 @@ inline void hwdef_setup() { //PORTA.PIN0CTRL = PORT_PULLUPEN_bm; // R //PORTA.PIN1CTRL = PORT_PULLUPEN_bm; // G //PORTA.PIN2CTRL = PORT_PULLUPEN_bm; // B - //PORTA.PIN3CTRL = PORT_PULLUPEN_bm; // CH + #ifdef USE_BST_BYPASS + PORTA.PIN3CTRL = PORT_PULLUPEN_bm; // BBY + #endif PORTA.PIN4CTRL = PORT_PULLUPEN_bm; PORTA.PIN5CTRL = PORT_PULLUPEN_bm; //PORTA.PIN6CTRL = PORT_PULLUPEN_bm; // BATT LVL @@ -177,6 +189,12 @@ inline void hwdef_setup() { // to generate a zero without spending power on the DAC // (and do this in set_level_zero() too) + // TCA/TCB/TCD aren't being used, so turn them off + TCA0.SINGLE.CTRLA = 0; + TCB0.CTRLA = 0; + TCB1.CTRLA = 0; + TCD0.CTRLA = 0; + }