完成速度、电流闭环

This commit is contained in:
2024-05-17 00:43:58 +08:00
parent d531b7cc09
commit f404369a32
11 changed files with 507 additions and 174 deletions

View File

@@ -12,144 +12,38 @@ extern uint16_t cycleNum;
#define SQRT3 1.732050808f
#define LIMIT (float32_t)(0.9f / SQRT3)
#define LIMIT_UDC 16.0f
#define TS 3400
#define TS 3300
#define SQRT3_MULT_TS (float32_t)((float32_t)TS * SQRT3)
uint8_t sectionMap[7] = {0, 2, 6, 1, 4, 3, 5};
float32_t uAlpha, uBeta;
float32_t ud, uq;
uint16_t channel1, channel2, channel3,udc=12;
float channel1, channel2, channel3, udc = 12;
float uAlpha, uBeta;
float32_t iAlpha, iBeta;
float32_t id, iq;
inline void clarke_transform(float Ia, float Ib, float Ic, float *Ialpha, float *Ibeta) {
*Ialpha = Ia;
*Ibeta = (Ib - Ic) * ONE_BY_SQRT3;
}
inline void park_transform(float Ialpha, float Ibeta, float Theta, float *Id, float *Iq) {
float s = sinf(Theta / 57.29577951326093f);
float c = cosf(Theta / 57.29577951326093f);
*Id = Ialpha * c + Ibeta * s;
*Iq = -Ialpha * s + Ibeta * c;
}
inline void inversePark(float ud, float uq, float Theta, float *uAlpha, float *uBeta) {
float s = sinf(Theta / 57.2958f);
float c = cosf(Theta / 57.2958f);
float s = sinf(Theta / 57.29577951326093f);
float c = cosf(Theta / 57.29577951326093f);
*uAlpha = ud * c - uq * s;
*uBeta = ud * s + uq * c;
}
#ifdef false
inline int SVPWM(float uAlpha, float uBeta, float *tA, float *tB, float *tC) {
float U1, U2, U3;
uint8_t a, b, c, n = 0;
U1 = uBeta;
U2 = (SQRT3 * uAlpha - uBeta) / 2;
U3 = (-SQRT3 * uAlpha - uBeta) / 2;
if (U1 > 0)
a = 1;
else
a = 0;
if (U2 > 0)
b = 1;
else
b = 0;
if (U3 > 0)
c = 1;
else
c = 0;
n = (c << 2) + (b << 1) + a;
switch (sectionMap[n])
{
case 0:
{
channel1 = TS / 2;
channel2 = TS / 2;
channel3 = TS / 2;
}
break;
case 1:
{
int16_t t4 = SQRT3 * TS * U2 / udc;
int16_t t6 = SQRT3 * TS * U1 / udc;
int16_t t0 = (TS - t4 - t6) / 2;
channel1 = t4 + t6 + t0;
channel2 = t6 + t0;
channel3 = t0;
}
break;
case 2:
{
int16_t t2 = -SQRT3 * TS * U2 / udc;
int16_t t6 = -SQRT3 * TS * U3 / udc;
int16_t t0 = (TS - t2 - t6) / 2;
channel1 = t6 + t0;
channel2 = t2 + t6 + t0;
channel3 = t0;
}
break;
case 3:
{
int16_t t2 = SQRT3 * TS * U1 / udc;
int16_t t3 = SQRT3 * TS * U3 / udc;
int16_t t0 = (TS - t2 - t3) / 2;
channel1 = t0;
channel2 = t2 + t3 + t0;
channel3 = t3 + t0;
}
break;
case 4:
{
int16_t t1 = -SQRT3 * TS * U1 / udc;
int16_t t3 = -SQRT3 * TS * U2 / udc;
int16_t t0 = (TS - t1 - t3) / 2;
channel1 = t0;
channel2 = t3 + t0;
channel3 = t1 + t3 + t0;
}
break;
case 5:
{
int16_t t1 = SQRT3 * TS * U3 / udc;
int16_t t5 = SQRT3 * TS * U2 / udc;
int16_t t0 = (TS - t1 - t5) / 2;
channel1 = t5 + t0;
channel2 = t0;
channel3 = t1 + t5 + t0;
}
break;
case 6:
{
int16_t t4 = -SQRT3 * TS * U3 / udc;
int16_t t5 = -SQRT3 * TS * U1 / udc;
int16_t t0 = (TS - t4 - t5) / 2;
channel1 = t4 + t5 + t0;
channel2 = t0;
channel3 = t5 + t0;
}
break;
default:
break;
}
*tA = channel1;
*tB = channel2;
*tC = channel3;
return 0;
}
#else
inline int SVPWM(float uAlpha, float uBeta, float *tA, float *tB, float *tC) {
int Sextant;
@@ -274,5 +168,3 @@ inline int SVPWM(float uAlpha, float uBeta, float *tA, float *tB, float *tC) {
// TIM1->CCR2 = channelB;
// TIM1->CCR3 = channelC;
}
#endif

View File

@@ -7,7 +7,7 @@
#include "arm_math.h"
#define M_PI (3.14159265358f)
//#define M_PI (3.14159265358f)
#define M_2PI (6.28318530716f)
#define ONE_BY_SQRT3 (0.57735026919f)
#define TWO_BY_SQRT3 (2.0f * 0.57735026919f)
@@ -24,6 +24,10 @@
//
//extern inline void park_transform(float Ialpha, float Ibeta, float Theta, float *Id, float *Iq);
extern void clarke_transform(float Ia, float Ib, float Ic, float *Ialpha, float *Ibeta);
extern void park_transform(float Ialpha, float Ibeta, float Theta, float *Id, float *Iq);
extern void inversePark(float ud, float uq, float Theta, float *uAlpha, float *uBeta);
extern int SVPWM(float uAlpha, float uBeta, float *tA, float *tB, float *tC);