Modified Motor Driver Firmware to include Flash + Thermal

Dependencies:   FastPWM3 mbed-dev-STM-lean

Files at this revision

API Documentation at this revision

Comitter:
adimmit
Date:
Mon Aug 29 18:57:14 2022 +0000
Parent:
74:fcc5f8e7f0ef
Child:
76:4fd876d4cf2b
Commit message:
it works - had to move NPP from FLASH to normal user-set param in firmware, will need to fix later

Changed in this revision

Config/user_config.h 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/user_config.h	Mon Aug 29 18:09:36 2022 +0000
+++ b/Config/user_config.h	Mon Aug 29 18:57:14 2022 +0000
@@ -3,7 +3,10 @@
 #ifndef USER_CONFIG_H
 #define USER_CONFIG_H
 
+//MOTOR INT PARAMS 
+#define NPP                     21 //__int_reg[200]                                  //TODO --> FIX ISSUES w/ THIS IN FLASH , ask @adi, Number of motor Pole Pairs  
 
+//OFFSET PARAMS / OTHER PARAMS
 #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
@@ -23,26 +26,21 @@
 #define L_D                     __float_reg[14]                                 //D-axis inductance in HENRIES
 #define L_Q                     __float_reg[15]                                 //L-axis inductance in HENRIES
 //ACTUATOR PARAMETERS
-#define KT                      __float_reg[17]                                 //Torque Constance Nm/peak phase amp, = WB*NPP*3/2
-#define GR                      __float_reg[18]                                 //Output gear ratio
-#define KT_OUT                  __float_reg[19]                                 //KT*GR
-#define WB                      __float_reg[20]                                 //Flux linkage, Webers.  (from motor KT, see above formula)
+#define KT                      __float_reg[16]                                 //Torque Constance Nm/peak phase amp, = WB*NPP*3/2
+#define GR                      __float_reg[17]                                 //Output gear ratio
+#define KT_OUT                  __float_reg[18]                                 //KT*GR
+#define WB                      __float_reg[19]                                 //Flux linkage, Webers.  (from motor KT, see above formula)
 //THERMAL OBSERVER
-#define R_TH                    __float_reg[21]                                 //Kelvin watt per joule (motor thermal resistance)
-#define INV_M_TH                __float_reg[22]                                 //Kelvin per Joule (some observer thing)
-#define T_AMBIENT               __float_reg[23]                                 // ambient temperature during temp calibration
+#define R_TH                    __float_reg[20]                                 //Kelvin watt per joule (motor thermal resistance)
+#define INV_M_TH                __float_reg[21]                                 //Kelvin per Joule (some observer thing)
+#define T_AMBIENT               __float_reg[22]                                 // ambient temperature during temp calibration
 
 
 #define PHASE_ORDER             __int_reg[0]                                    // Phase swapping during calibration
 #define CAN_ID                  __int_reg[1]                                    // CAN bus ID
 #define CAN_MASTER              __int_reg[2]                                    // CAN bus "master" ID
 #define CAN_TIMEOUT             __int_reg[3]                                    // CAN bus timeout period
-#define ENCODER_LUT             __int_reg[5]                                    // Encoder offset LUT - 128 elements long  
-//MOTOR INT PARAMS 
-#define NPP                     __int_reg[200]                                  //Number of motor Pole Pairs            
-
-
-//CHECK THIS BC WTF why would REG[4] break it ???
+#define ENCODER_LUT             __int_reg[5]                                    // Encoder offset LUT - 128 elements long
 
 
 
--- a/main.cpp	Mon Aug 29 18:09:36 2022 +0000
+++ b/main.cpp	Mon Aug 29 18:57:14 2022 +0000
@@ -156,8 +156,8 @@
     wait_us(10);
     printf(" %-4s %-31s %-5s %-6s %f\n\r", "e", "Q-axis inductance (H)", "0", "0.1", L_Q);
     wait_us(10);
-    printf(" %-4s %-31s %-5s %-6s %d\n\r", "n", "Number of Pole Pairs (NPP)", "0", "40", NPP);
-    wait_us(10);
+    //printf(" %-4s %-31s %-5s %-6s %d\n\r", "n", "Number of Pole Pairs (NPP)", "0", "40", NPP);
+    //wait_us(10);
     //ACTUATOR PARAMS
     printf("ACTUATOR PARAMS\n\r");
     wait_us(10);
@@ -457,9 +457,9 @@
                     case 'e':
                         L_Q = fmaxf(fminf(atof(cmd_val), 0.1f), 0.0f);
                         break;
-                    case 'n':
-                        NPP = atoi(cmd_val);
-                        break;
+                    //case 'n':
+                        //NPP = atoi(cmd_val);
+                        //break;
                     case 'p':
                         KT = fmaxf(fminf(atof(cmd_val), 1.0f), 0.0f);
                         break;
@@ -590,7 +590,7 @@
     if(isnan(R_PHASE) || R_PHASE==-1){R_PHASE = 0.158f;}
     if(isnan(L_D) || L_D==-1){L_D = 0.000084f;}
     if(isnan(L_Q) || L_Q==-1){L_Q = 0.000084f;}
-    if(isnan(NPP) || NPP==-1){NPP = 21;}
+    //if(isnan(NPP) || NPP==-1){NPP = 21;}
     //ACTUATOR PARAMS
     if(isnan(KT) || KT==-1){KT = 0.1916f;}
     if(isnan(GR) || GR==-1){GR = 6.0f;}
@@ -623,6 +623,7 @@
     printf(" Position Sensor Electrical Offset:   %.4f\n\r", E_OFFSET);
     printf(" Output Zero Position:  %.4f\n\r", M_OFFSET);
     printf(" CAN ID:  %d\n\r", CAN_ID);
+    printf(" POLE PAIRS:  %d\n\r", NPP);
     
 
     TIM1->CR1 ^= TIM_CR1_UDIS;