1569 views|0 replies

3836

Posts

19

Resources
The OP
 

TMS320F28377_SVPWM complete program [Copy link]

1. Main function

/*
* main.c
* author: wx
* data: 2020/1/6
* function: generate the SVPWM wave form, and use graph to see it.
* version: 1.0
*/

#include "F28x_Project.h"
#include "math.h"
#include "C28x_FPU_FastRTS.h"
#include "SVPWM_2L.h"

__interrupt void cpu_timer0_isr(void);

#define PI 3.1415926535
#define PI2 1.57079632675 // PI/2
#define Ts 1e-4 // Ts is different from T!
#define InterruptTime Ts*1e6

float table_a[200];
float table_b[200];
float table_c[200];

SVPWM_2L SVPWM;

void parameters_init()
{
SVPWM.T = 1; //i have per-unit the T.
SVPWM.Tcmpa = 0.5;
SVPWM.Tcmpb = 0.5;
SVPWM.Tcmpc = 0.5;
SVPWM.Ualpha = 0;
SVPWM.Ubeta = 0;
SVPWM.Vdc = 311;
SVPWM.calc = svpwm_2L_calc;
}

void main(void)
{
InitSysCtrl();
parameters_init();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TIMER0_INT = &cpu_timer0_isr;
EDIS;
InitCpuTimers();
ConfigCpuTimer(&CpuTimer0, 200, InterruptTime);
CpuTimer0Regs.TCR.all = 0x4000; // Allow interrupt, start timer
IER |= M_INT1;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM

for(;;)
{

}
}

__interrupt void cpu_timer0_isr(void)
{
CpuTimer0.InterruptCount++;

static int i=0;

SVPWM.Ualpha = 100 * sin(100 * PI * SVPWM.T * Ts * i);
SVPWM.Ubeta = 100 * sin(100 * PI * SVPWM.T * Ts * i + PI2);

SVPWM.calc(&SVPWM);

table_a = SVPWM.Tcmpa;
table_b = SVPWM.Tcmpb;
table_c = SVPWM.Tcmpc;
i++;

if (i >= 200) i=0;

PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}

2、svpwm.c

/*
* svpwm_2L_calc.c
*
* Created on: 2020/1/8
* Author: Administrator
*/
#include "F28x_Project.h"
#include "math.h"
#include "SVPWM_2L.h"
#include "C28x_FPU_FastRTS.h"

void svpwm_2L_calc(SVPWM_2L *p)
{
float temp;
float X,Y,Z, t1,t2;
Uint16 A,B,C,N,Sector;
float Ta, Tb, Tc;
float K=1.73205081;//sqrt(3)/2
//p->T=1.0;//Normalize the whole modulation period
X= K*p->Ubeta/p->Vdc*p->T;
Y=(K*p->Ubeta+3*p->Ualpha)/(2*p->Vdc)*p->T;
Z=(K*p->Ubeta-3*p->Ualpha)/(2*p->Vdc)*p->T;
//
if(p->Ubeta>0)
{A=1;}
else
{A=0;}

if( (K*p->Ualpha - p->Ubeta)>0 )
{B=1;}
else
{B=0;}

if((-K*p->Ualpha - p->Ubeta)>0)
{C=1;}
else
{C=0;}

N=A+2*B+4*C;
//
switch(N)
{
case 1:{Sector=2;break;}
case 2:{Sector=6;break;}
case 3:{Sector=1;break;}
case 4:{Sector=4;break;}
case 5:{Sector=3;break;}
case 6:{Sector=5;break;}
default:{;}
}
//
switch(Sector)
{
case 1: {t1=-Z; t2= X;break;}
case 2: {t1= Z; t2= Y;break;}
case 3: {t1= X; t2=-Y;break;}
case 4: {t1=-X; t2= Z;break;}
case 5: {t1=-Y; t2=-Z;break;}
case 6: {t1= Y; t2=-X;break;}
default:{;}
}

if((t1+t2)>p->T)//Adjust the overmodulation condition
{
temp=t1+t2;
t1=t1*p->T/temp;
t2=t2*p->T/temp;
}

//
Ta=(p->T-t1-t2)/4; //Action time distribution
Tb=Ta+t1/2;
Tc=Tb+t2/2;

switch(Sector)
{
case 1: {p->Tcmpa=Ta; p->Tcmpb=Tb; p->Tcmpc=Tc; break;}
case 2: {p->Tcmpa=Tb; p->Tcmpb=Ta; p->Tcmpc=Tc; break;}
case 3: {p->Tcmpa=Tc; p->Tcmpb=Ta; p->Tcmpc=Tb; break;}
case 4: {p->Tcmpa=Tc; p->Tcmpb=Tb; p->Tcmpc=Ta; break;}
case 5: {p->Tcmpa=Tb; p->Tcmpb=Tc; p->Tcmpc=Ta; break;}
case 6: {p->Tcmpa=Ta; p->Tcmpb=Tc; p->Tcmpc=Tb; break;}
default:{;}
}
}

3、svpwm.h

/*
* SVPWM_2L.h
*
* Created on: 2020/1/8
* Author: Administrator
*/

#ifndef SVPWM_2L_H_
#define SVPWM_2L_H_

typedef struct { float Ualpha; // Input: reference alpha-axis phase voltage
float Ubeta; // Input: reference beta-axis phase voltage
float Vdc; // Input: DC voltage
float T; // Input: PWM Modulation Period
float Tcmpa; // Output: reference phase-a switching function
float Tcmpb; // Output: reference phase-b switching function
float Tcmpc; // Output: reference phase-c switching function
void (*calc)(); // Pointer to calculation function
} SVPWM_2L;
void svpwm_2L_calc(SVPWM_2L *p);
#endif /* SVPWM_2L_H_ */

实现的效果图

This post is from Microcontroller MCU
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list