BLDC motor driver

Dependencies:   mbed-dev-f303 FastPWM3

Files at this revision

API Documentation at this revision

Comitter:
benkatz
Date:
Wed Jul 17 03:40:12 2019 +0000
Parent:
50:ba72df25d10f
Commit message:
adding field-weakening to the user menu, switch "torque limit" to "current limit"

Changed in this revision

Config/current_controller_config.h Show annotated file Show diff for this revision Revisions of this file
Config/user_config.h Show annotated file Show diff for this revision Revisions of this file
FOC/foc.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Config/current_controller_config.h	Thu Apr 04 13:53:58 2019 +0000
+++ b/Config/current_controller_config.h	Wed Jul 17 03:40:12 2019 +0000
@@ -13,10 +13,6 @@
 #define D_INT_LIM V_BUS/(K_D*KI_D)  // Amps*samples
 #define Q_INT_LIM V_BUS/(K_Q*KI_Q)  // Amps*samples
 
-#define I_MAX 40.0f                 // Max Current
-#define I_MAX_FW 10.0f               // Max field weakening current
-#define I_MAX_CONT 15.0f            // Max continuous current, for thermal limiting
-
 //Observer//
 #define DT 0.000025f
 #define K_O 0.02f
--- a/Config/user_config.h	Thu Apr 04 13:53:58 2019 +0000
+++ b/Config/user_config.h	Wed Jul 17 03:40:12 2019 +0000
@@ -7,9 +7,10 @@
 #define E_OFFSET                __float_reg[0]                                  // Encoder electrical offset
 #define M_OFFSET                __float_reg[1]                                  // Encoder mechanical offset
 #define I_BW                    __float_reg[2]                                  // Current loop bandwidth
-#define TORQUE_LIMIT            __float_reg[3]                                  // Torque limit (current limit = torque_limit/(kt*gear ratio))
+#define I_MAX                   __float_reg[3]                                  // Torque limit (current limit = torque_limit/(kt*gear ratio))
 #define THETA_MIN               __float_reg[4]                                  // Minimum position setpoint
 #define THETA_MAX               __float_reg[5]                                  // Maximum position setpoint
+#define I_FW_MAX                __float_reg[6]                                  // Maximum field weakening current
 
 
 #define PHASE_ORDER             __int_reg[0]                                    // Phase swapping during calibration
@@ -20,6 +21,7 @@
 
 
 
+
 extern float __float_reg[];
 extern int __int_reg[];
 
--- a/FOC/foc.cpp	Thu Apr 04 13:53:58 2019 +0000
+++ b/FOC/foc.cpp	Wed Jul 17 03:40:12 2019 +0000
@@ -165,7 +165,7 @@
        /// Field Weakening ///
        
        controller->fw_int += .001f*(0.5f*OVERMODULATION*controller->v_bus - controller->v_ref);
-       controller->fw_int = fmaxf(fminf(controller->fw_int, 0.0f), -I_MAX_FW);
+       controller->fw_int = fmaxf(fminf(controller->fw_int, 0.0f), -I_FW_MAX);
        controller->i_d_ref = controller->fw_int;
        //float i_cmd_mag_sq = controller->i_d_ref*controller->i_d_ref + controller->i_q_ref*controller->i_q_ref;
        limit_norm(&controller->i_d_ref, &controller->i_q_ref, I_MAX);
--- a/main.cpp	Thu Apr 04 13:53:58 2019 +0000
+++ b/main.cpp	Wed Jul 17 03:40:12 2019 +0000
@@ -10,7 +10,7 @@
 #define SETUP_MODE 4
 #define ENCODER_MODE 5
 
-#define VERSION_NUM "1.8"
+#define VERSION_NUM "1.9"
 
 
 float __float_reg[64];                                                          // Floats stored in flash
@@ -110,7 +110,7 @@
 void enter_setup_state(void){
     printf("\n\r\n\r Configuration Options \n\r\n\n");
     wait_us(10);
-    printf(" %-4s %-31s %-5s %-6s %-5s\n\r\n\r", "prefix", "parameter", "min", "max", "current value");
+    printf(" %-4s %-31s %-5s %-6s %-2s\n\r\n\r", "prefix", "parameter", "min", "max", "current value");
     wait_us(10);
     printf(" %-4s %-31s %-5s %-6s %.1f\n\r", "b", "Current Bandwidth (Hz)", "100", "2000", I_BW);
     wait_us(10);
@@ -118,7 +118,9 @@
     wait_us(10);
     printf(" %-4s %-31s %-5s %-6s %-5i\n\r", "m", "CAN Master ID", "0", "127", CAN_MASTER);
     wait_us(10);
-    printf(" %-4s %-31s %-5s %-6s %.1f\n\r", "l", "Torque Limit (N-m)", "0.0", "18.0", TORQUE_LIMIT);
+    printf(" %-4s %-31s %-5s %-6s %.1f\n\r", "l", "Current Limit (A)", "0.0", "40.0", I_MAX);
+    wait_us(10);
+    printf(" %-4s %-31s %-5s %-6s %.1f\n\r", "f", "FW Current Limit (A)", "0.0", "33.0", I_FW_MAX);
     wait_us(10);
     printf(" %-4s %-31s %-5s %-6s %d\n\r", "t", "CAN Timeout (cycles)(0 = none)", "0", "100000", CAN_TIMEOUT);
     wait_us(10);
@@ -178,7 +180,7 @@
         controller.theta_mech = (1.0f/GR)*spi.GetMechPosition();
         controller.dtheta_mech = (1.0f/GR)*spi.GetMechVelocity();  
         controller.dtheta_elec = spi.GetElecVelocity();
-        controller.v_bus = 0.95f*controller.v_bus + 0.05f*((float)controller.adc3_raw)*V_SCALE;
+        controller.v_bus = 0.95f*controller.v_bus + 0.05f*((float)controller.adc3_raw)*V_SCALE; //filter the dc link voltage measurement
         ///
         
         /// Check state machine state, and run the appropriate function ///
@@ -306,7 +308,10 @@
                         CAN_MASTER = atoi(cmd_val);
                         break;
                     case 'l':
-                        TORQUE_LIMIT = fmaxf(fminf(atof(cmd_val), 18.0f), 0.0f);
+                        I_MAX = fmaxf(fminf(atof(cmd_val), 40.0f), 0.0f);
+                        break;
+                    case 'f':
+                        I_FW_MAX = fmaxf(fminf(atof(cmd_val), 33.0f), 0.0f);
                         break;
                     case 't':
                         CAN_TIMEOUT = atoi(cmd_val);
@@ -374,9 +379,6 @@
     zero_current(&controller.adc1_offset, &controller.adc2_offset);             // Measure current sensor zero-offset
     drv.disable_gd();
 
-
-    
-    
     wait(.1);
     /*
     gpio.enable->write(1);
@@ -406,7 +408,8 @@
     if(isnan(E_OFFSET)){E_OFFSET = 0.0f;}
     if(isnan(M_OFFSET)){M_OFFSET = 0.0f;}
     if(isnan(I_BW) || I_BW==-1){I_BW = 1000;}
-    if(isnan(TORQUE_LIMIT) || TORQUE_LIMIT ==-1){TORQUE_LIMIT=18;}
+    if(isnan(I_MAX) || I_MAX ==-1){I_MAX=40;}
+    if(isnan(I_FW_MAX) || I_FW_MAX ==-1){I_FW_MAX=0;}
     if(isnan(CAN_ID) || CAN_ID==-1){CAN_ID = 1;}
     if(isnan(CAN_MASTER) || CAN_MASTER==-1){CAN_MASTER = 0;}
     if(isnan(CAN_TIMEOUT) || CAN_TIMEOUT==-1){CAN_TIMEOUT = 0;}