Fixes for motor overload detection
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Fri, 26 Apr 2019 01:15:43 +0000 (18:15 -0700)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Fri, 26 Apr 2019 01:15:43 +0000 (18:15 -0700)
src/pwr/config.h
src/pwr/main.c

index 81736dc8c3cbf80f173a5cc855692784d80b8e86..364e8d311cf2b0240c9087bd0aaf05dfefecad7b 100644 (file)
@@ -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
index d8348f398dd366448fd53b252a22b738c86bbb71..a32652084fde9d8d44eefbee73ad8cd46c148dfb 100644 (file)
@@ -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;
   }