diff options
Diffstat (limited to 'hw/thefreeman/avr32dd20-devkit/hwdef.c')
| -rw-r--r-- | hw/thefreeman/avr32dd20-devkit/hwdef.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/hw/thefreeman/avr32dd20-devkit/hwdef.c b/hw/thefreeman/avr32dd20-devkit/hwdef.c index 3e5dd79..5b534d2 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; @@ -106,13 +119,13 @@ bool gradual_tick_main(uint8_t gt) { uint8_t voltage_raw2cooked(uint16_t measurement) { // In : 65535 * BATTLVL / 1.024V - // Out: uint8_t: Vbat * 40 + // Out: uint8_t: Vbat * 50 // BATTLVL = Vbat * (100.0/(330+100)) = Vbat / 4.3 - // So, Out = In * 4.3 / 1600 + // So, Out = In * 4.3 / 1280 // (plus a bit of fudging to fix the slope and offset, // based on measuring actual hardware) uint8_t result = (uint32_t)(measurement + (65535 * 4 / 1024)) - * 43 / 16128; + * 43 / 12880; return result; } |
