From 14b9cb45031ac922de4095858c4a5c41b4c63de9 Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Thu, 25 Apr 2019 18:15:43 -0700 Subject: [PATCH] Fixes for motor overload detection --- src/pwr/config.h | 6 +++--- src/pwr/main.c | 13 ++++--------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/pwr/config.h b/src/pwr/config.h index 81736dc..364e8d3 100644 --- a/src/pwr/config.h +++ b/src/pwr/config.h @@ -82,9 +82,9 @@ enum { #define VOLTAGE_MIN 11 #define VOLTAGE_MAX 39 #define CURRENT_MAX 25 -#define CURRENT_OVERTEMP 16 // Should read as ~21A but over 11.86A in an error +#define CURRENT_OVERTEMP 19 // Should read as ~21A but over 11.86A in an error #define LOAD_OVERTEMP_MAX 10 -#define MOTOR_SHUTDOWN_THRESH 10 +#define MOTOR_SHUTDOWN_THRESH 15 #define VOLTAGE_SETTLE_COUNT 5 #define VOLTAGE_SETTLE_PERIOD 20 // ms #define VOLTAGE_SETTLE_TOLERANCE 0.01 @@ -104,7 +104,7 @@ enum { #define CURRENT_REF_R2 137 #define CURRENT_REF_MUL (100.0 * 2700 / CURRENT_REF_R2) // 2700 from datasheet -#define AVG_SCALE 2 +#define AVG_SCALE 3 #define BUCKETS (1 << AVG_SCALE) // Addresses 0x60 to 0x67 diff --git a/src/pwr/main.c b/src/pwr/main.c index d8348f3..a326520 100644 --- a/src/pwr/main.c +++ b/src/pwr/main.c @@ -245,18 +245,13 @@ static void read_conversion(uint8_t ch) { case VOUT_ADC: regs[VOUT_REG] = convert_voltage(data); break; case CS1_ADC: { - uint16_t raw = convert_current(data); - bool overtemp = CURRENT_OVERTEMP * 10 < raw; + update_current(MOTOR_REG, data); + bool overtemp = CURRENT_OVERTEMP * 100 < regs[MOTOR_REG]; if (overtemp) { if (motor_overload < MOTOR_SHUTDOWN_THRESH) motor_overload++; - - } else { - if (motor_overload != MOTOR_SHUTDOWN_THRESH && motor_overload) - motor_overload--; - - update_current(MOTOR_REG, data); - } + } else if (motor_overload != MOTOR_SHUTDOWN_THRESH && motor_overload) + motor_overload--; break; } -- 2.27.0