Explorar o código

过调制处理

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui %!s(int64=3) %!d(string=hai) anos
pai
achega
5fb3ebd3c8

+ 4 - 4
Applications/foc/core/PMSM_FOC_Core.c

@@ -287,10 +287,10 @@ static __INLINE void PMSM_FOC_Update_Hardware(void) {
 
 static __INLINE void PMSM_FOC_Update_PI_Idq(void) {
 	/* update id pi ctrl */
-	gFoc_Ctrl.params.maxvDQ.d = gFoc_Ctrl.in.s_vDC;//CONFIG_RATED_DC_VOL;
-	gFoc_Ctrl.params.minvDQ.d = -gFoc_Ctrl.in.s_vDC;//CONFIG_RATED_DC_VOL;
-	gFoc_Ctrl.params.maxvDQ.q = gFoc_Ctrl.in.s_vDC;//CONFIG_RATED_DC_VOL;
-	gFoc_Ctrl.params.minvDQ.q = -gFoc_Ctrl.in.s_vDC;//CONFIG_RATED_DC_VOL;
+	gFoc_Ctrl.params.maxvDQ.d = gFoc_Ctrl.in.s_vDC * gFoc_Ctrl.params.n_modulation;//CONFIG_RATED_DC_VOL;
+	gFoc_Ctrl.params.minvDQ.d = -gFoc_Ctrl.in.s_vDC * gFoc_Ctrl.params.n_modulation;//CONFIG_RATED_DC_VOL;
+	gFoc_Ctrl.params.maxvDQ.q = gFoc_Ctrl.in.s_vDC * gFoc_Ctrl.params.n_modulation;//CONFIG_RATED_DC_VOL;
+	gFoc_Ctrl.params.minvDQ.q = -gFoc_Ctrl.in.s_vDC * gFoc_Ctrl.params.n_modulation;//CONFIG_RATED_DC_VOL;
 
 	if (gFoc_Ctrl.params.maxvDQ.d != gFoc_Ctrl.pi_id->max) {
 		gFoc_Ctrl.pi_id->max = gFoc_Ctrl.params.maxvDQ.d;

+ 10 - 7
Applications/foc/core/svpwm.c

@@ -524,6 +524,7 @@ void SVM_Duty_Fix(AB_t *alb, s16q5_t vbus, u32 PWM_half_period, FOC_OutP *out) {
 }
 
 #else
+#if 1
 #define Duty_Sat(max, t1, t2) \
 	do { \
 		if (t1+t2 > max) { \
@@ -532,16 +533,18 @@ void SVM_Duty_Fix(AB_t *alb, s16q5_t vbus, u32 PWM_half_period, FOC_OutP *out) {
 			t2 = r * t2; \
 		} \
 	}while(0);
+#else
+#define Duty_Sat(max, t1, t2) 
+#endif
 void SVM_Duty_Fix(AB_t *alb, s16q5_t vbus, u32 PWM_half_period, FOC_OutP *out) {
 	float alpha = (alb->a) * SQRT3_BY_2;
 	float beta  = (alb->b)  * SQRT3_BY_2;
 	u32   PWM_Period = PWM_half_period * 2;
-	u8 sector = 0xFF;
-	u32 tA, tB, tC;
-	u32 low, midle;
+	u8    sector = 0xFF;
+	int   tA, tB, tC;
+	u32   low, midle;
 	float X, Y, Z;
 	float modu = (float)(PWM_Period) / (vbus);
-//	static int _g_count = 0;
 
 	if (beta >= 0.0f) {
 		if (alpha >= 0.0f) {
@@ -657,9 +660,9 @@ void SVM_Duty_Fix(AB_t *alb, s16q5_t vbus, u32 PWM_half_period, FOC_OutP *out) {
 		default:
 			break;
 	}	
-	out->n_Duty[0] = tA;
-	out->n_Duty[1] = tB;
-	out->n_Duty[2] = tC;
+	out->n_Duty[0] = fclamp(tA, 0, PWM_half_period);
+	out->n_Duty[1] = fclamp(tB, 0, PWM_half_period);
+	out->n_Duty[2] = fclamp(tC, 0, PWM_half_period);
 	out->n_lowDuty = low;
 	out->n_midDuty = midle;
 	out->n_Sector = sector;

+ 2 - 1
Applications/foc/foc_config.h

@@ -1,5 +1,6 @@
 #ifndef _FOC_CONFIG_H__
 #define _FOC_CONFIG_H__
+#include "math/fast_math.h"
 
 #define CONFIG_DEFAULT_IDC_LIM 45
 #define CONFIG_DEFAULT_PHASE_CURR_LIM 200
@@ -10,7 +11,7 @@
 #define CONFIG_DEFAULT_EPM_RPM        200
 #define CONFIG_DEFAULT_EBRK_PHASE_CURR 10.0F //0:means disable ebrake
 #define CONFIG_DEFAULT_EBRK_IDC_LIM 15
-#define CONFIG_SVM_MODULATION       1.0F
+#define CONFIG_SVM_MODULATION       (1.0F/SQRT3_BY_2)
 #define CONFIG_BRK_SHUT_POWER_ENABLE 1
 #define CONFIG_AUTOHOLD_ENABLE 1
 

+ 9 - 0
Applications/math/fast_math.h

@@ -26,6 +26,15 @@ void fast_sincos(float angle, float *sin, float *cos);
 float fast_arctan2(float y, float x);
 void SinCos_Lut(float angle, float *s, float *c);
 
+static __INLINE float fclamp(float v, float minv, float maxv) {
+	if (v < minv) {
+		return minv;
+	}else if (v > maxv) {
+		return maxv;
+	}
+	return v;
+}
+
 static void fast_norm_angle(float *angle) {
 	*angle = fmodf(*angle, 360.0f);
 

BIN=BIN
Simulink/DQSVPWM.slx


BIN=BIN
Simulink/FOC.slx