|
|
@@ -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;
|