From ef7581e825a851de85918d4c3a3146ba767403a4 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sat, 23 Mar 2024 22:30:05 -0600 Subject: fixed inaccurate comment (thanks to xikteny for spotting it) --- fsm/adc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'fsm') diff --git a/fsm/adc.h b/fsm/adc.h index 02e33f8..f66bf34 100644 --- a/fsm/adc.h +++ b/fsm/adc.h @@ -15,7 +15,7 @@ volatile uint8_t adc_reset = 2; #ifndef VOLTAGE_WARNING_SECONDS #define VOLTAGE_WARNING_SECONDS 5 #endif -// low-battery threshold in volts * 10 +// low-battery threshold in volts * 40 #ifndef VOLTAGE_LOW #define VOLTAGE_LOW (4*29) #endif -- cgit v1.2.3 From a87812f436e08b14a7cede83e30306d779774872 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 25 Mar 2024 04:25:43 -0600 Subject: dammit, got alkaline detection half working and then my flashing adapter died (saving progress here so I can work on a different branch) --- fsm/ramping.c | 5 +++++ fsm/ramping.h | 3 +++ 2 files changed, 8 insertions(+) (limited to 'fsm') diff --git a/fsm/ramping.c b/fsm/ramping.c index adc8acb..63ab399 100644 --- a/fsm/ramping.c +++ b/fsm/ramping.c @@ -57,6 +57,11 @@ inline void set_level_aux_rgb_leds(uint8_t level) { void set_level(uint8_t level) { + #ifdef USE_RAMP_LEVEL_HARD_LIMIT + if (level > ramp_level_hard_limit) + level = ramp_level_hard_limit; + #endif + #ifdef USE_JUMP_START // maybe "jump start" the engine, if it's prone to slow starts // (pulse the output high for a moment to wake up the power regulator) diff --git a/fsm/ramping.h b/fsm/ramping.h index c4b7d48..6fe87fe 100644 --- a/fsm/ramping.h +++ b/fsm/ramping.h @@ -10,6 +10,9 @@ uint8_t actual_level = 0; // the level used before actual uint8_t prev_level = 0; +#ifdef USE_RAMP_LEVEL_HARD_LIMIT +uint8_t ramp_level_hard_limit = RAMP_SIZE; +#endif void set_level(uint8_t level); //void set_level_smooth(uint8_t level); -- cgit v1.2.3 From 35b5c42f8996167248b7e6d2e4053f6bbef1505c Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Tue, 26 Mar 2024 03:41:17 -0600 Subject: d3aa: got weak battery detection actually working, and not letting the magic smoke out of updi adapters any more (probably) The alkaline detection might be a little too lenient though; it could potentially fail to activate limits when the cell is completely full or stronger than an average alkaline. One of my test cells measured at 72 / 75, so if it was just a little stronger it'd pass... but most alkalines I tried were in the 40 to 60 range and failed easily. OTOH, if I make it easier to fail, it's likely to trip on normal li-ion cells, and I don't want that. So as a future enhancement idea, maybe it should have a smaller sag threshold for AA and a larger threshold for li-ion. That would reduce false negatives for AA, while still preventing false positives for li-ion. --- fsm/ramping.c | 2 +- fsm/ramping.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'fsm') diff --git a/fsm/ramping.c b/fsm/ramping.c index 63ab399..743e619 100644 --- a/fsm/ramping.c +++ b/fsm/ramping.c @@ -58,7 +58,7 @@ inline void set_level_aux_rgb_leds(uint8_t level) { void set_level(uint8_t level) { #ifdef USE_RAMP_LEVEL_HARD_LIMIT - if (level > ramp_level_hard_limit) + if (ramp_level_hard_limit && (level > ramp_level_hard_limit)) level = ramp_level_hard_limit; #endif diff --git a/fsm/ramping.h b/fsm/ramping.h index 6fe87fe..f542bd2 100644 --- a/fsm/ramping.h +++ b/fsm/ramping.h @@ -11,7 +11,7 @@ uint8_t actual_level = 0; // the level used before actual uint8_t prev_level = 0; #ifdef USE_RAMP_LEVEL_HARD_LIMIT -uint8_t ramp_level_hard_limit = RAMP_SIZE; +uint8_t ramp_level_hard_limit = 0; #endif void set_level(uint8_t level); -- cgit v1.2.3 From 7b49797be1da97f54e9df3a1b0342ab20d7f02d5 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Wed, 27 Mar 2024 07:13:26 -0600 Subject: increased voltage precision from 0.025V to 0.02V (so 0 to 255 now goes from 0.00V to 5.10V) --- fsm/adc.c | 58 +++++++++++++++++++++++++++++----------------------------- fsm/adc.h | 10 +++++++--- 2 files changed, 36 insertions(+), 32 deletions(-) (limited to 'fsm') diff --git a/fsm/adc.c b/fsm/adc.c index fbe84a1..e0bacb6 100644 --- a/fsm/adc.c +++ b/fsm/adc.c @@ -209,8 +209,8 @@ static void ADC_voltage_handler() { #endif else measurement = adc_smooth[0]; - // convert raw ADC value to FSM voltage units: Volts * 40 - // 0 .. 200 = 0.0V .. 5.0V + // convert raw ADC value to FSM voltage units: Volts * 50 + // 0 .. 250 = 0.0V .. 5.0V voltage = voltage_raw2cooked(measurement) + (VOLTAGE_FUDGE_FACTOR << 1) #ifdef USE_VOLTAGE_CORRECTION @@ -392,46 +392,46 @@ static void ADC_temperature_handler() { #ifdef USE_BATTCHECK #ifdef BATTCHECK_4bars PROGMEM const uint8_t voltage_blinks[] = { - 4*30, - 4*35, - 4*38, - 4*40, - 4*42, - 255, + 30*dV, + 35*dV, + 38*dV, + 40*dV, + 42*dV, + 255, }; #endif #ifdef BATTCHECK_6bars PROGMEM const uint8_t voltage_blinks[] = { - 4*30, - 4*34, - 4*36, - 4*38, - 4*40, - 4*41, - 4*43, - 255, + 30*dV, + 34*dV, + 36*dV, + 38*dV, + 40*dV, + 41*dV, + 43*dV, + 255, }; #endif #ifdef BATTCHECK_8bars PROGMEM const uint8_t voltage_blinks[] = { - 4*30, - 4*33, - 4*35, - 4*37, - 4*38, - 4*39, - 4*40, - 4*41, - 4*42, - 255, + 30*dV, + 33*dV, + 35*dV, + 37*dV, + 38*dV, + 39*dV, + 40*dV, + 41*dV, + 42*dV, + 255, }; #endif void battcheck() { #ifdef BATTCHECK_VpT - blink_num(voltage / 4); + blink_num(voltage / dV); #ifdef USE_EXTRA_BATTCHECK_DIGIT - // 0 1 2 3 --> 0 2 5 7, representing x.x00 x.x25 x.x50 x.x75 - blink_num(((voltage % 4)<<1) + ((voltage % 4)>>1)); + // 0.02V precision, 0 1 2 3 4 remainder -> .00 .02 .04 .06 .08V + blink_num((voltage % dV) * (10/dV)); #endif #else uint8_t i; diff --git a/fsm/adc.h b/fsm/adc.h index f66bf34..5dec6c5 100644 --- a/fsm/adc.h +++ b/fsm/adc.h @@ -4,6 +4,10 @@ #pragma once +// voltage is 0.00V to 5.10V in 0.02V steps, from 0 to 255 +// so one deci-Volt is 5 steps +#define dV 5 + #if defined(USE_LVP) || defined(USE_THERMAL_REGULATION) // use raw value instead of lowpassed value for the next N measurements // (2 = 1 for voltage + 1 for temperature) @@ -15,13 +19,13 @@ volatile uint8_t adc_reset = 2; #ifndef VOLTAGE_WARNING_SECONDS #define VOLTAGE_WARNING_SECONDS 5 #endif -// low-battery threshold in volts * 40 +// low-battery threshold in volts * 50 #ifndef VOLTAGE_LOW -#define VOLTAGE_LOW (4*29) +#define VOLTAGE_LOW (29*dV) #endif // battery is low but not critical #ifndef VOLTAGE_RED -#define VOLTAGE_RED (4*33) +#define VOLTAGE_RED (33*dV) #endif // MCU sees voltage 0.X volts lower than actual, add X/2 to readings #ifndef VOLTAGE_FUDGE_FACTOR -- cgit v1.2.3 From 7b766a7745fbf7debb90667d659f1cb546ec2a0d Mon Sep 17 00:00:00 2001 From: Andrew Slotnick Date: Mon, 5 Feb 2024 16:37:41 -0500 Subject: use low aux for chan-aux level 0 --- fsm/chan-aux.c | 2 +- fsm/chan-rgbaux.c | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'fsm') diff --git a/fsm/chan-aux.c b/fsm/chan-aux.c index e04e6a2..239316a 100644 --- a/fsm/chan-aux.c +++ b/fsm/chan-aux.c @@ -4,7 +4,7 @@ #pragma once void set_level_aux(uint8_t level) { - indicator_led(!(!(level)) << 1); // high (or off) + indicator_led((!(!(level)) << 1) + 1); // high (level > 0) or low } bool gradual_tick_null(uint8_t gt) { return true; } // do nothing diff --git a/fsm/chan-rgbaux.c b/fsm/chan-rgbaux.c index 19d18a6..a66c29e 100644 --- a/fsm/chan-rgbaux.c +++ b/fsm/chan-rgbaux.c @@ -4,31 +4,31 @@ #pragma once void set_level_auxred(uint8_t level) { - rgb_led_set(!(!(level)) * 0b000010); // red, high (or off) + rgb_led_set(0b000001 << !(!(level))); // red, high (level > 0) or low } void set_level_auxyel(uint8_t level) { - rgb_led_set(!(!(level)) * 0b001010); // red+green, high (or off) + rgb_led_set(0b000101 << !(!(level))); // red+green, high (level > 0) or low } void set_level_auxgrn(uint8_t level) { - rgb_led_set(!(!(level)) * 0b001000); // green, high (or off) + rgb_led_set(0b000100 << !(!(level))); // green, high (level > 0) or low } void set_level_auxcyn(uint8_t level) { - rgb_led_set(!(!(level)) * 0b101000); // green+blue, high (or off) + rgb_led_set(0b010100 << !(!(level))); // green+blue, high (level > 0) or low } void set_level_auxblu(uint8_t level) { - rgb_led_set(!(!(level)) * 0b100000); // blue, high (or off) + rgb_led_set(0b010000 << !(!(level))); // blue, high (level > 0) or low } void set_level_auxprp(uint8_t level) { - rgb_led_set(!(!(level)) * 0b100010); // red+blue, high (or off) + rgb_led_set(0b010001 << !(!(level))); // red+blue, high (level > 0) or low } void set_level_auxwht(uint8_t level) { - rgb_led_set(!(!(level)) * 0b101010); // red+green+blue, high (or off) + rgb_led_set(0b010101 << !(!(level))); // red+green+blue, high (level > 0) or low } bool gradual_tick_null(uint8_t gt) { return true; } // do nothing -- cgit v1.2.3