1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File #include "math.h" #include "stdio.h" #define VDC 100 #define ERPI 6.2831852 #define N 200 #define PWMPRD 200 struct SVPWM { float32 Vain; float32 Vbin; float32 Vcin; float32 Vaout; float32 Vbout; float32 Vcout; float32 Ubeta; float32 Ualfa; float32 Ta; float32 Tb; float32 Tc; }; struct SVPWM*V; float32 t1,t2; Uint32 ticker=0; float32 waveadata[N]; float32 wavebdata[N]; float32 wavecdata[N]; float32 temp[N]; int16 Amp; Uint16 sector; Uint32 interrupttickers; void init_eva(void); interrupt void svpwm_isr(); int A,B,C; int a=0; void comput_Vs(struct SVPWM*v); void main(void) { InitSysCtrl();//初始化系统函数 EALLOW; GpioMuxRegs.GPAMUX.all=0x00FF; GpioMuxRegs.GPADIR.all=0x00FF; GpioMuxRegs.GPBMUX.all=0x00FF; GpioMuxRegs.GPBDIR.all=0x00FF; DINT; // 禁止CPU中断和清除所有CPU中断标志 IER = 0x0000; IFR = 0x0000; InitPieCtrl(); //初始化PI控制寄存器 InitPieVectTable();//初始化PIE中断向量表,并使其指向中断服务子程序(ISR) EALLOW; PieVectTable.T1PINT=&svpwm_isr; EDIS; init_eva(); interrupttickers=0; PieCtrlRegs.PIEIER2.all=M_INT4; IER |= M_INT2;//开CPU中断 EINT; //使能全局中断 ERTM; //使能实时中断 //EvaRegs.T1CON.bit.TENABLE=1; ticker=0; Amp=55; sector=0; for(; ;); } void init_eva() { EvaRegs.T1CON.bit.TMODE = 1; //通用定时器计数模式 EvaRegs.T1CON.bit.TPS = 1; //输入时钟预定标因子HSPCLK/1 EvaRegs.T1CON.bit.TENABLE = 0;//定时器使能为 EvaRegs.T1CON.bit.TCLKS10=0;//时钟源选择,内部时钟 EvaRegs.T1CON.bit.TECMPR=1;//定时器比较使能 EvaRegs.T1PR=PWMPRD;//周期寄存器的值 EvaRegs.T1CNT=0;//计数器的初值 EvaRegs.COMCONA.bit.CENABLE=1;// 比较器使能 EvaRegs.COMCONA.bit.FCOMPOE=1;// 全比较器输出使能 EvaRegs.COMCONA.bit.CLD=2;//比较器重新装载使能 EvaRegs.ACTRA.all=0x0666; /* EvaRegs.GPTCONA.all=0; EvaRegs.T1PR=PWMPRD; EvaRegs.T1CMPR=0x0000; EvaRegs.EVAIFRA.bit.T1PINT=1; EvaRegs.EVAIMRA.bit.T1PINT=1; EvaRegs.T1CNT=0x0000; EvaRegs.T1CON.all=0x0842; EvaRegs.GPTCONA.bit.T1TOADC=2; EvaRegs.ACTRA.all=0x0666;*/ } void comput_Vs(struct SVPWM*v) { sector=0; if(ticker>=N) ticker=0; else ticker++; v->Vain=wavebdata[ticker]=Amp*sin(ticker*6.285185307/N); v->Vbin=wavebdata[ticker]=Amp*sin(ticker*6.285185307/N-2.094395102); v->Vcin=wavebdata[ticker]=Amp*sin(ticker*6.285185307/N+2.094395102); v->Ualfa=0.816496583*(v->Vain-0.5*v->Vbin-0.5*v->Vcin); v->Ubeta=0.816496583*(0.8660254*v->Vbin-0.8660254*v->Vcin); v->Vaout=v->Ubeta; v->Vbout=-0.5*v->Ubeta+0.8660254*v->Ualfa; v->Vcout=-0.5*v->Ubeta-0.8660254*v->Ualfa; if(v->Vaout>0) A=1; else A=0; if(v->Vbout>0) B=1; else B=0; if(v->Vcout>0) C=1; else C=0; sector=A+2*B+4*C; v->Vaout=PWMPRD*v->Ubeta/VDC; v->Vbout=PWMPRD*(0.5*v->Ubeta+0.8660254*v->Ualfa)/VDC; v->Vcout=PWMPRD*(0.5*v->Ubeta-0.8660254*v->Ualfa)/VDC; if(sector==1) { t1=v->Vcout; t2=v->Vbout; v->Tb=0.5*(PWMPRD-t1-t2); v->Ta=v->Tb+t1; v->Tc=v->Ta+t2; } else if(sector==2) { t1=v->Vbout; t2=v->Vaout; v->Ta=0.5*(PWMPRD-t1-t2); v->Tc=v->Ta+t1; v->Tb=v->Tc+t2; } else if(sector==3) { t1=v->Vcout; t2=v->Vaout; v->Ta=0.5*(PWMPRD-t1-t2); v->Tb=v->Ta+t1; v->Tc=v->Tb+t2; } else if(sector==4) { t1=v->Vaout; t2=v->Vcout; v->Tc=0.5*(PWMPRD-t1-t2); v->Tb=v->Tc+t1; v->Ta=v->Tb+t2; } else if(sector==5) { t1=v->Vaout; t2=v->Vbout; v->Tb=0.5*(PWMPRD-t1-t2); v->Tc=v->Tb+t1; v->Ta=v->Tc+t2; } else if(sector==6) { t1=v->Vbout; t2=v->Vcout; v->Tc=0.5*(PWMPRD-t1-t2); v->Ta=v->Tc+t1; v->Tb=v->Ta+t2; } EvaRegs.CMPR1=(int)(v->Ta); EvaRegs.CMPR2=(int)(v->Tb); EvaRegs.CMPR3=(int)(v->Tc); } interrupt void svpwm_isr(void) { interrupttickers++; void comput_Vs(struct SVPWM*v); EvaRegs.EVAIMRA.bit.T1PINT=1; EvaRegs.EVAIFRA.all=BIT7; PieCtrlRegs.PIEACK.all=PIEACK_GROUP2; } 不知道哪里错了,不能输出波形,求大神指点,谢谢 |
|
相关推荐 |
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
基于 DSP5509 进行数字图像处理中 Sobel 算子边缘检测的硬件连接电路图
3262 浏览 0 评论
796 浏览 0 评论
普中科技F28335开发板中,如何使用aic23播放由代码生成的正弦波
3695 浏览 0 评论
4454 浏览 1 评论
1376 浏览 1 评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 16:17 , Processed in 0.521439 second(s), Total 73, Slave 56 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号