Modified Motor Driver Firmware to include Flash + Thermal

Dependencies:   FastPWM3 mbed-dev-STM-lean

Files at this revision

API Documentation at this revision

Comitter:
benkatz
Date:
Thu Aug 08 17:19:39 2019 +0000
Parent:
51:6cd89bd6fcaa
Child:
54:59575833d16f
Commit message:
fixed CAN ID filtering bug

Changed in this revision

Config/motor_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
mbed-dev.lib Show annotated file Show diff for this revision Revisions of this file
--- a/Config/motor_config.h	Wed Jul 17 03:40:12 2019 +0000
+++ b/Config/motor_config.h	Thu Aug 08 17:19:39 2019 +0000
@@ -6,7 +6,7 @@
 #define L_Q 0.00002f            //Henries
 #define KT .08f                 //N-m per peak phase amp, = WB*NPP*3/2
 #define NPP 21                  //Number of pole pairs
-#define GR 1.0f                 //Gear ratio
+#define GR 6.0f                 //Gear ratio
 #define KT_OUT 0.45f            //KT*GR
 #define WB 0.0025f              //Flux linkage, Webers.  
 #define R_TH 1.25f              //Kelvin per watt
--- a/FOC/foc.cpp	Wed Jul 17 03:40:12 2019 +0000
+++ b/FOC/foc.cpp	Thu Aug 08 17:19:39 2019 +0000
@@ -194,12 +194,12 @@
        controller->v_ref = sqrt(controller->v_d*controller->v_d + controller->v_q*controller->v_q);
        
        limit_norm(&controller->v_d, &controller->v_q, OVERMODULATION*controller->v_bus);       // Normalize voltage vector to lie within curcle of radius v_bus
-       float dtc_d = controller->v_d/controller->v_bus;
-       float dtc_q = controller->v_q/controller->v_bus;
-       linearize_dtc(&dtc_d);
-       linearize_dtc(&dtc_q);
-       controller->v_d = dtc_d*controller->v_bus;
-       controller->v_q = dtc_q*controller->v_bus;
+       //float dtc_d = controller->v_d/controller->v_bus;
+       //float dtc_q = controller->v_q/controller->v_bus;
+       //linearize_dtc(&dtc_d);
+       //linearize_dtc(&dtc_q);
+       //controller->v_d = dtc_d*controller->v_bus;
+       //controller->v_q = dtc_q*controller->v_bus;
        abc(controller->theta_elec + 0.0f*DT*controller->dtheta_elec, controller->v_d, controller->v_q, &controller->v_u, &controller->v_v, &controller->v_w); //inverse dq0 transform on voltages
        svm(controller->v_bus, controller->v_u, controller->v_v, controller->v_w, &controller->dtc_u, &controller->dtc_v, &controller->dtc_w); //space vector modulation
 
--- a/main.cpp	Wed Jul 17 03:40:12 2019 +0000
+++ b/main.cpp	Thu Aug 08 17:19:39 2019 +0000
@@ -60,7 +60,7 @@
 
 void onMsgReceived() {
     //msgAvailable = true;
-    printf("%df\n\r", rxMsg.id);
+    //printf("%d\n\r", rxMsg.id);
     can.read(rxMsg);  
     if((rxMsg.id == CAN_ID)){
         controller.timeout = 0;
@@ -396,15 +396,18 @@
     NVIC_SetPriority(TIM1_UP_TIM10_IRQn, 2);                                             // commutation > communication
     
     NVIC_SetPriority(CAN1_RX0_IRQn, 3);
-    can.filter(CAN_ID<<21, 0xFFE00004, CANStandard, 0);
+                                   // attach 'CAN receive-complete' interrupt handler    
+    
+    // If preferences haven't been user configured yet, set defaults 
+    prefs.load();                                                               // Read flash
+    
+    can.filter(CAN_ID , 0xFFF, CANStandard, 0);
                                                                     
     txMsg.id = CAN_MASTER;
     txMsg.len = 6;
     rxMsg.len = 8;
-    can.attach(&onMsgReceived);                                     // attach 'CAN receive-complete' interrupt handler    
+    can.attach(&onMsgReceived);  
     
-    // If preferences haven't been user configured yet, set defaults 
-    prefs.load();                                                               // Read flash
     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;}
@@ -449,7 +452,7 @@
     int counter = 0;
     while(1) {
         drv.print_faults();
-       wait(.1);
+        wait(.1);
        //printf("%.4f\n\r", controller.v_bus);
        /*
         if(state == MOTOR_MODE)
--- a/mbed-dev.lib	Wed Jul 17 03:40:12 2019 +0000
+++ b/mbed-dev.lib	Thu Aug 08 17:19:39 2019 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/users/benkatz/code/mbed-dev-f303/#902f8c6731d6
+https://os.mbed.com/users/benkatz/code/mbed-dev-f303/#36facd806e4a