WANG YUCHAO / Mbed 2 deprecated Motor_DRV8323RH_for_20190

Dependencies:   mbed FastPWM3

Files at this revision

API Documentation at this revision

Comitter:
benkatz
Date:
Sat Mar 12 19:55:52 2016 +0000
Parent:
5:51c6560bf624
Child:
7:dc5f27756e02
Commit message:
Switched from sinusoidal pwm to svm

Changed in this revision

CurrentRegulator/CurrentRegulator.cpp Show annotated file Show diff for this revision Revisions of this file
CurrentRegulator/CurrentRegulator.h Show annotated file Show diff for this revision Revisions of this file
PositionSensor/PositionSensor.cpp Show annotated file Show diff for this revision Revisions of this file
SVM/SVM.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/CurrentRegulator/CurrentRegulator.cpp	Sat Mar 12 18:45:22 2016 +0000
+++ b/CurrentRegulator/CurrentRegulator.cpp	Sat Mar 12 19:55:52 2016 +0000
@@ -9,7 +9,7 @@
 
 CurrentRegulator::CurrentRegulator(Inverter *inverter, PositionSensor *position_sensor, float Kp, float Ki){
     _Inverter = inverter;
-    PWM = new SPWM(inverter, 2.0);
+    PWM = new SVPWM(inverter, 2.0);
     _PositionSensor = position_sensor;
     IQ_Ref = .5;
     ID_Ref = 0;
--- a/CurrentRegulator/CurrentRegulator.h	Sat Mar 12 18:45:22 2016 +0000
+++ b/CurrentRegulator/CurrentRegulator.h	Sat Mar 12 19:55:52 2016 +0000
@@ -18,7 +18,7 @@
         void SendSPI();
         Inverter* _Inverter;
         PositionSensor* _PositionSensor;
-        SPWM* PWM;
+        SVM* PWM;
         //Serial* pc;
         //int count;
             
--- a/PositionSensor/PositionSensor.cpp	Sat Mar 12 18:45:22 2016 +0000
+++ b/PositionSensor/PositionSensor.cpp	Sat Mar 12 19:55:52 2016 +0000
@@ -1,7 +1,7 @@
 
 #include "mbed.h"
 #include "PositionSensor.h"
-#include <math.h>
+//#include <math.h>
 
     
 PositionSensorEncoder::PositionSensorEncoder(int CPR, float offset) {
--- a/SVM/SVM.cpp	Sat Mar 12 18:45:22 2016 +0000
+++ b/SVM/SVM.cpp	Sat Mar 12 19:55:52 2016 +0000
@@ -2,6 +2,8 @@
 #include "mbed.h"
 #include "SVM.h"
 #include "Inverter.h"
+#define min(x,y,z) (x < y ? (x < z ? x : z) : (y < z ? y : z))
+#define max(x,y,z) (x > y ? (x > z ? x : z) : (y > z ? y : z))
 
 SPWM::SPWM(Inverter *inverter, float V_Bus){
     _inverter = inverter;
@@ -28,10 +30,19 @@
     }
     
 void SVPWM::Update_DTC(float V_A, float V_B, float V_C){
+    
+    float Voff = (min(V_A, V_B, V_C) + max(V_A, V_B, V_C))/2.0f;
+    
+    V_A = V_A - Voff;
+    V_B = V_B - Voff;
+    V_C = V_C - Voff;
+    
     float DTC_A = V_A/_V_Bus + .5f;
     float DTC_B = V_B/_V_Bus + .5f;
     float DTC_C = V_C/_V_Bus + .5f;
     
+    
+    
     if(DTC_A > .95f) DTC_A = .95f;
     else if(DTC_A < .05f) DTC_A = .05f;
     if(DTC_B > .95f) DTC_B = .95f;
--- a/main.cpp	Sat Mar 12 18:45:22 2016 +0000
+++ b/main.cpp	Sat Mar 12 19:55:52 2016 +0000
@@ -69,7 +69,6 @@
     //testing.attach(&PrintStuff, .05);
     //inverter.SetDTC(.1, 0, 0);
     //inverter.EnableInverter();
-
     while(1) {
         //printf("%f\n\r", encoder.GetElecPosition());
         //wait(.1);