Skip to content

Commit

Permalink
avr32dd20-devkit: use unimplemented "CH" pin as a boost bypass control
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ToyKeeper committed Jan 30, 2024
1 parent 76ce3c5 commit cbfc1a1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
13 changes: 13 additions & 0 deletions hw/thefreeman/avr32dd20-devkit/hwdef.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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;
Expand Down
22 changes: 20 additions & 2 deletions hw/thefreeman/avr32dd20-devkit/hwdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@
* 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
* HDR FET switches between high value Rsense (low current range, pin low),
* 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
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;

}


Expand Down

0 comments on commit cbfc1a1

Please sign in to comment.