我想给DSP28335一个假的三相并网电压电流数据来测试代码,代码如下所示,但是我的ea、eb、ec、ia、ib、ic正常在变换,接下来的计算代码却不能输出结果,这是为什么?
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#include "init_sin.h"
#include "test1.h"
#include "math.h"
extern float e_A, e_B, e_C;//实际电压值
extern float i_A, i_B, i_C;//实际电流值
void ABC_ref(void) //初始化正弦波数据
{
int i;
for(i=0;i<=359;i++)
{
e_A = 311*sin(2*PI*i/360);
e_B = 311*sin(2*PI*(i-120)/360);
e_C = 311*sin(2*PI*(i+120)/360);
i_A = 6.8*sin(2*PI*i/360);
i_B = 6.8*sin(2*PI*(i-120)/360);
i_C = 6.8*sin(2*PI*(i+120)/360);
}
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#include "init_sin.h"
#include "test1.h"
#include "math.h"
extern float i_A,i_B,i_C;
extern float e_A, e_B, e_C;
extern float e_alpha;
extern float e_beta;
extern float i_alpha;
extern float i_beta;
extern float Ttype_ps;
extern float Ttype_qs;
extern float Ep;
extern float Eq;
void formula(void)
{
e_alpha = e_A-0.5*e_B-0.5*e_C; //
e_beta = 1.7320508076/2.0*e_B-1.7320508076/2.0*e_C; //
e_alpha = 0.6666666667*e_alpha;
e_beta = 0.6666666667*e_beta;
i_alpha = i_A-0.5*i_B-0.5*i_C; //
i_beta = 1.7320508076/2.0*i_B-1.7320508076/2.0*i_C; //
i_alpha = 0.6666666667*i_alpha;
i_beta = 0.6666666667*i_beta;
Ttype_ps = e_alpha*i_alpha+e_beta*i_beta;
Ttype_qs = e_beta*i_alpha-e_alpha*i_beta; //瞬时功率理论
Ttype_ps = 1.5*Ttype_ps;
Ttype_qs = 1.5*Ttype_qs;
Ep = Pref-Ttype_ps;
Eq = Qref-Ttype_qs;
}
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#include "math.h"
#include "test1.h"
#include "init_sin.h"
float e_A_arr[360], e_B_arr[360], e_C_arr[360];
float i_A_arr[360], i_B_arr[360], i_C_arr[360];
float e_A, e_B, e_C;//电压值
float i_A, i_B, i_C;//电流
float e_alpha;
float e_beta;
float i_alpha;
float i_beta;
float Ttype_ps;
float Ttype_qs;
float Ep;
float Eq;
//float fp;
//float fq;
//float u_alpha0;
//float u_beta0;
//float center_sector_alpha[6];
//float center_sector_beta[6];
//unsigned char N=0;
#define JDQ_XH GpioDataRegs.GPACLEAR.bit.GPIO31 = 1 //继电器吸合
#define JDQ_DK GpioDataRegs.GPASET.bit.GPIO31 = 1 //继电器断开
//void configtestled(void);
void configJDQ(void);
interrupt void cpu_timer0_isr(void);
void main(void)
{
InitSysCtrl();
configJDQ();
InitXintf(); // 配置外部存储器的访问时序
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓中断初始化↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
DINT; //禁用CPU中断
InitPieCtrl(); // 初始化中断控制寄存器,禁用所有PIE中断并清楚标志位
IER = 0x0000; // 关闭总中断
IFR = 0x0000; // 清除中断信号
InitPieVectTable(); // 初始化中断向量表
// EALLOW;
// SysCtrlRegs.PCLKCR3.bit.CPUTIMER0ENCLK = 1; //开启cpu time0时钟
// EDIS;
EALLOW;
PieVectTable.TINT0 = &cpu_timer0_isr;
// PieVectTable.SCIRXINTB = &sci485_isr;
EDIS;
// EALLOW;
// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC=0; //同步PWM时钟信号
// EDIS;
//
// EALLOW;
// SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC=1; //同步PWM时钟信号
// EDIS;
InitCpuTimers();
// ConfigCpuTimer(&CpuTimer0, 150, 33.3); //周期10us,开关频率18kHz
ConfigCpuTimer(&CpuTimer0, 150, 100); //周期10us,开关频率10kHz
StartCpuTimer0();//打开定时器
// Init_sci_485_config();
IER |= M_INT1;//使能CPU INT1和INT9
IER |= M_INT9;
PieCtrlRegs.PIECTRL.bit.ENPIE = 1; //使能pie模块
PieCtrlRegs.PIEIER1.bit.INTx7 = 1; //Enable TINT0(1.7)
PieCtrlRegs.PIEIER9.bit.INTx3 = 1; //Enable SCIRXINTB(9.3)
EINT;
ERTM;
//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
CpuTimer0Regs.TCR.bit.TSS = 0; //立即启动定时器0
JDQ_XH;
for(;;)
{
if(CpuTimer0Regs.TCR.bit.TIF == 0)//if(current_flag == 1) // 确保中断已更新全部数据
{
;
}
else
{;}
}
}
interrupt void cpu_timer0_isr(void)
{
ABC_ref();
formula();
// sector_partition();
CpuTimer0.InterruptCount = (CpuTimer0.InterruptCount >= 18000)? 0:CpuTimer0.InterruptCount+1; //1s
// Acknowledge this interrupt to receive more interrupts from group 1
PieCtrlRegs.PIEACK.all |= PIEACK_GROUP1;
// PieCtrlRegs.PIEACK.all |= PIEACK_GROUP9;
CpuTimer0Regs.TCR.bit.TIF = 1; //写1清除中断标志(该位为1表明进入中断,该位为0表明中断函数结束)
CpuTimer0Regs.TCR.bit.TRB = 1;
}
更多回帖