FOC算法笔记

目录

 FOC框图

 一、坐标变换

二、SVPWM

        1、扇区判断

        2、相邻矢量作用时长

        3、每个扇区的作用时长


 FOC框图

 一、坐标变换

        1、反Park变换

                公式:

                                        \left\{\begin{matrix} V\alpha = Vd\cos\theta - Vq\sin\theta & & \\ V\beta = Vd\sin\theta + Vq\cos\theta& & \end{matrix}\right.

        2、反Clark变换

                公式:

                                      \left\{\begin{matrix} Va = V\alpha & & \\ Vb = (-V\alpha + \sqrt{3}*V\beta)/2 & & \\ Vc = (-V\alpha - \sqrt{3}*V\beta)/2 & & \end{matrix}\right.

        3、Clark变换

                公式:

                                        \left\{\begin{matrix} ia + ib + ic = 0 & & \\ i\alpha= ia& & \\ i\beta = (ia+2ib)/\sqrt(3)& & \end{matrix}\right.

        4、Park变换

                公式:

                                        \left\{\begin{matrix} Id = i\alpha*\cos(\theta) + i\beta*\sin(\theta) & & \\ Iq = -i\alpha*\cos(\theta) + i\beta*\sin(\theta)& & \end{matrix}\right.

        C代码如下:

#include <stdio.h>
#include <math.h>

typedef struct {
    double  Ualpha;  double  Ubeta;   double  Ud;  double  Uq;
    double  Ua;      double  Ub;      double  Uc;

    double ia;       double ib;       double ic;
    double iq;       double id;       double ialpha;
    double ibeta;    double id_pre;   double iq_pre;
    double angle;
}MOTOR_PARAM;

MOTOR_PARAM motor_param;

int Res_Upark();
int Res_Uclark();

int Ipark();
int Iclark();



int main(void) {
    motor_param.Ud = 0.0;
    motor_param.Uq = 10.0;
    motor_param.angle = 30.0;
    Res_Upark(); 
    printf("alpha轴电压:%f  beta轴电压:%f\n",motor_param.Ualpha,motor_param.Ubeta);

    Res_Uclark();
    printf("A相电压:%f B相电压:%f C相电压:%f\n",motor_param.Ua,motor_param.Ub,motor_param.Uc);
    motor_param.ia = motor_param.Ua;
    motor_param.ib = motor_param.Ub;
    motor_param.ic = motor_param.Uc;

    Iclark();
    printf("alpha轴电流:%f beta轴电流:%f\n",motor_param.ialpha,motor_param.ibeta);

    Ipark();
    printf("D轴电流:%f Q轴电流:%f D轴电流(预):%f Q轴电流(预):%f\n",motor_param.id,motor_param.iq,motor_param.id_pre,motor_param.iq_pre);
    return 0;
}

 


int Res_Upark(){
    motor_param.Ualpha = motor_param.Ud * cos(motor_param.angle) - motor_param.Uq * sin(motor_param.angle);
    motor_param.Ubeta  = motor_param.Ud * sin(motor_param.angle) + motor_param.Uq * cos(motor_param.angle);
    return 0;
}

int Res_Uclark(){
    motor_param.Ua = motor_param.Ualpha;
    motor_param.Ub = -0.5*motor_param.Ualpha + ((sqrt(3.0)/2.0) *motor_param.Ubeta);
    motor_param.Uc = -0.5*motor_param.Ualpha - ((sqrt(3.0)/2.0) *motor_param.Ubeta);
    return 0;
}
int Iclark(){
    motor_param.ialpha = motor_param.ia;
    motor_param.ibeta  = (motor_param.ia + 2*motor_param.ib)/sqrt(3.0);
    return 0;
}
int Ipark(){
    motor_param.id = motor_param.ialpha * cos(motor_param.angle) +motor_param.ibeta * sin(motor_param.angle);
    motor_param.iq = -motor_param.ialpha * sin(motor_param.angle) + motor_param.ibeta * cos(motor_param.angle);
    motor_param.id_pre = motor_param.id *1.5;
    motor_param.iq_pre = motor_param.iq *1.5;
    return 0;
}

执行效果如下:

 

二、SVPWM

        将坐标变换中的反Park变换得到的 Valpha 、Vbeta 转换六路PWM输出。

        1、扇区判断

                根据推导可得:

                                  \left\{\begin{matrix} A = V\beta & & \\ B = (\sqrt(3) *V\alpha - V\beta )/2& & \\ C = (-\sqrt(3)*V\alpha - V\beta)/2 & & \end{matrix}\right.

                                        N = 4C + 2B + A;

扇区
N315462

        2、相邻矢量作用时长

                推导可得:

                                   \left\{\begin{matrix} x = (\sqrt(3)*Ts*V\beta)/Vdc & & \\ y = ((\sqrt(3)*Ts)/Vdc) *(\sqrt(3)/2*V\alpha+0.5*V\beta) & & \\ z = ((\sqrt(3)*Ts)/Vdc) *(-\sqrt(3)/2*V\alpha+0.5*V\beta) & & \end{matrix}\right.

                Ts :定时器的频率,Vdc : 母线电压。

                 扇区与作用时长的关系:

123456
Txzy-z-xx-y
Tyy-xxz-y-z

                       表中数字代表扇区判断中N的值,1对应的是第二扇区,以此类推。

                        Tx,Ty代表两个矢量的时长。可以理解为两个分量上的占空比输出。

        3、每个扇区的作用时长

               第一扇区:  Sa = (Ts - Tx - Ty)/4,  Sb = (Ts + Tx - Ty)/4, Sc = (Ts + Tx + Ty)/4;

               第二扇区:  Sa = (Ts + Tx - Ty)/4, Sb = (Ts - Tx - Ty)/4,  Sc = (Ts + Tx + Ty)/4;    

               第三扇区:  Sa = (Ts + Tx + Ty)/4, Sb = (Ts - Tx - Ty)/4,  Sc = (Ts + Tx - Ty)/4; 

               第四扇区:  Sa = (Ts + Tx + Ty)/4, Sb = (Ts + Tx - Ty)/4,  Sc = (Ts - Tx - Ty)/4; 

               第五扇区:  Sa = (Ts + Tx - Ty)/4,  Sb = (Ts + Tx +Ty)/4,  Sc = (Ts - Tx - Ty)/4; 

               第六扇区:  Sa = (Ts - Tx - Ty)/4, Sb = (Ts + Tx + Ty)/4,  Sc = (Ts + Tx - Ty)/4; 

                Sa、 Sb、 Sc 可以理解为U、V、W 三项的占空比输出。

                以下为MATLAB svpwm仿真模块的代码:

function [Tpwm1,Tpwm2,Tpwm3,sector] = fcn(Valpha,Vbeta,Udc,Tpwm)
%#codegen
sector = single(0);
Tpwm1 = single(0);
Tpwm2 = single(0);
Tpwm3 = single(0);

Uref1 = Vbeta;
Uref2 = (sqrt(3)*Valpha - Vbeta)/2;
Uref3 = (-sqrt(3)*Valpha - Vbeta)/2;

if(Uref1 > 0)
    sector = single(1);
end
if(Uref2 > 0)
    sector = sector + single(2);
end
if(Uref3 > 0)
    sector = sector + single(4);
end

X = (sqrt(3)*Tpwm*Vbeta)/Udc;
Y = Tpwm/Udc*(3/2*Valpha +sqrt(3)/2*Vbeta);
Z = Tpwm/Udc*(-3/2*Valpha +sqrt(3)/2*Vbeta);

switch(sector)
    case 1
        Tx = Z;Ty = Y;
    case 2
        Tx = Y;Ty = -X;
    case 3
        Tx = -Z;Ty = X;
    case 4
        Tx = -X;Ty = Z;
    case 5
        Tx = X;Ty = -Y;
    otherwise
        Tx = -Y;Ty = -Z;
end

if(Tx+Ty>Tpwm)
    Tx = Tx/(Tx+Ty);
    Ty = Ty/(Tx+Ty);
else
    Tx = Tx;
    Ty = Ty;
end

ta = (Tpwm-Tx-Ty)/4.0;
tb = ta+Tx/2;
tc = tb+Ty/2;

switch(sector)
    case 1
        Tpwm1 = tb;
        Tpwm2 = ta;
        Tpwm3 = tc;
    case 2
        Tpwm1 = ta;
        Tpwm2 = tc;
        Tpwm3 = tb;
    case 3
        Tpwm1 = ta;
        Tpwm2 = tb;
        Tpwm3 = tc;
    case 4
        Tpwm1 = tc;
        Tpwm2 = tb;
        Tpwm3 = ta;
    case 5
        Tpwm1 = tc;
        Tpwm2 = ta;
        Tpwm3 = tb;
    case 6   
        Tpwm1 = tb;
        Tpwm2 = tc;
        Tpwm3 = ta;
end
        
end

执行的效果如下:标准的马鞍波

 未完待续

  • 2
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值