基于controlSTICK-PiccoloF28069的SPWM波形设计摘要:正弦脉宽调制(SPWM)技术在目前是一种比较成熟且使用广泛的PWM法,在电力滤波器中有良好的应用前景。文章介绍了如何利用高性能数字信号处理器controlSTICK-PiccoloF28069的片内外设epwm模块产生单相SPWM波,给出了程序流程图及关键程序源码。采用对称规则采样算法,参数计算主要采用查表法,计算量小,实时性高。关键词:TMS320F28069;SPWM;对称规则采样法;查表法DesignoftheSPWMwavebasedoncontrolSTICK-PiccoloF28069Abstract:SPWMtechniqueisrelativelymatureandwidelyusedPWMmethodinthepresent,therearegoodprospectsfortheapplicationofactivepowerfilter.Thisarticledescribeshowtotakeadvantageofhigh-performancedigitalsignalprocessorTMS320F28069chipPeripheralepwmmoduletogeneratesinglephaseSPWMwave,processflowdiagramandthekeytotheprogramsourcecode.Themethodusesregularsamplingalgorithmparameterscalculatedmainlyusingthelook-uptablemethod,asmallamountofcalculation,realtimehigh.Keywords:TMS320F28069;SPWM;Regularsamplingmethod;Look-uptablemethod引言PWM的全称是PulseWidthModulation,它是通过改变输出方波的占空比来改变等效的输出电压。SPWM就是在PWM的基础上改变了调制脉冲方式,脉冲宽度时间占空比按正弦规律排列,这样输出波形经过适当的滤波可以做到正弦波输出。文中主要介绍使用TMS320F28069高性能DSP处理器的eEVA模块生成电压SPWM波形,产生电压SPWM波的方法可分为硬件法和软件法两类,硬件法主要是采用专用集成电路(如SA8281),但这种方法成本高、灵活性差,在实际产品中很少采用;软件法是通过ti公司提供的专用软件ccs4.2.1编程实现生成SPWM波,这种方法灵活性强,实现成本低。SPWM波的实时计算对控制器的运算速度要求较高。1SPWM算法SPWM的实现算法主要有等效面积法、自然采样法、规则采样法等。这几种方法各有优缺点,等效面积法和自然采样法的优点是所得SPWM波形最接近正弦波,但脉宽表达式是一个超越方程,计算繁琐,难以实时控制;规则采样法计算简单,对于产生单向SPWM足够用,因此本此实验设计采用规则采样法。以下主要介绍如何使用规则对称采样法生成SPWM波形。产生SPWM波的原理是:用一组三角波与一个正弦波进行比较,在正弦波和三角波的自然交点时刻控制功率开关管的开通与关断,其中这组三角形波称为载波,正弦波为调制波。图1为规则采样说明图。取三角波两个正峰值之间为一个采样周期TS。每个脉冲的中点和相应的三角波中点对称,简化计算,在三角波的负峰时刻TD对正弦波采样得到D点,过D点做一条水平直线和三角波交于A、B两点,在A点时刻tA和B点时刻tB控制功率开关器件的通断。可以看出这种规则采样法得到的脉冲宽度δ和用自然采样法得到的脉冲宽度非常接近,相对简单准确。utABDtOuCTAtDtBt//图1对称采样法原理图设正弦调制波信号为sinrruat(1)表达式中,a为调制度,0=a1,;r为正弦信号波角频率。从图中可以得到如下关系式1sin2/2/2rDCatT(2)因此可得(1sin)2CrDTat(3)2软件实现TMS320F28069的定时器处于连续递增/递减计数模式时,计数寄存器中的数值变化轨迹就是等腰三角形,相当于产生了一个连续的等腰三角形载波,当比较寄存器中的值与计数寄存器中的值相等时,对应的PWM引脚上的电平就会发生跳变,从而输出一系列的等高方波信号,方波的宽度与比较寄存器中的值一一对应,因此只要比较寄存器中的值呈正弦变化,方波的等效面积也就会呈正弦变化,从而得到SPWM波形。程序分为主程序、epwm2寄存器初始化、更新sina函数和epwm2定时中断程序三部分。主程序主要完成各部分模块的初始化工作,然后打开epwm2模块的中断使能,最后进入死循环响应epwm2模块的中断;epwm2定时中断程序完成计算比较寄存器中的数据,然后赋值给各个比较寄存器即可。本次实验的Cf=20KHZ,Sf=50HZ,即载波比n=400,每半个周期需要采集200个点,由此可知每次角度增加00.9,在计算中要用到正弦向量表,在程序中定义一个一维n点数组,数组中的数据分别对应第n点的正弦值,然后在程序中直接读取这个数组的数值即可.由上式(3)可推出脉冲宽度为对应的开通时间为ONT,ONT对应epwm2中的CMPA,得出CMPA=02(1sin(*0.9*)2360CTak(k=1,2,3……)(4)主程序和epwm定时中断程序流程图分别如图2、图3所示。结束开始中断初始化Epwm2模块初始化计算载波周期图2主程序流程图开始比较寄存器赋值清除中断标志返回主程序正弦值是否到达正半个周期正弦值是否到达负半个周期YESNOYESNO图3epwm2定时器中断函数流程图3实验结果按照以上方法实现的软件经过编译调试,运行效果良好,SPWM波形输出正常。如图4所示图4输出的spwm波形4实验遇到的问题编译出来5个错误1.C语言的语法错误。根据错误提示改正将数组中的;改为,4个PIE中断设置错误。用到一个中断变量没有被定义,以为在DeviceInit.C中已经设置过了。经查看没有,进行定义RAM中运行,之前导入的工程例程用的是FLASH,两者冲突,最后把FLASH删掉错误消失了,并且选择下载到RAM中可以运行。5程序附录#includePeripheralHeaderIncludes.h#includeF2806x_EPwm_defines.h//usefuldefinesforinitialization//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//FUNCTIONPROTOTYPES//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%voidDeviceInit(void);voidInitFlash(void);voidMemCopy(Uint16*SourceAddr,Uint16*SourceEndAddr,Uint16*DestAddr);voidupdate_sina(void);voidPieCntlInit(void);voidPieVectTableInit(void);voidInitEPwmTimer(void);interruptvoidepwm2_timer_isr(void);//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//VARIABLEDECLARATIONS-GENERAL//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//UsedforrunningBackGroundinflashandtheISRinRAMexternUint16RamfuncsLoadStart,RamfuncsLoadEnd,RamfuncsRunStart;#definePWM2_INT_ENABLE1Uint32i=0;Uint32n=400;floata=0.8;Uint16temp;floatsina[201]={0,0.0157,0.0314,0.0471,0.0628,0.0785,0.0941,0.1097,0.1253,0.1409,0.1564,0.1719,0.1874,0.2028,0.2181,0.2334,0.2487,0.2639,0.2790,0.2940,0.3090,0.3239,0.3387,0.3535,0.3681,0.3827,0.3971,0.4115,0.4258,0.4399,0.4540,0.4679,0.4818,0.4955,0.5090,0.5225,0.5358,0.5490,0.5621,0.5750,0.5878,0.6004,0.6129,0.6252,0.6374,0.6494,0.6613,0.6730,0.6845,0.6959,0.7071,0.7181,0.7290,0.7396,0.7501,0.7604,0.7705,0.7804,0.7902,0.7997,0.8090,0.8181,0.8271,0.8358,0.8443,0.8526,0.8607,0.8686,0.8763,0.8838,0.8910,0.8980,0.9048,0.9114,0.9178,0.9239,0.9298,0.9354,0.9409,0.9461,0.9511,0.9558,0.9603,0.9646,0.9686,0.9724,0.9759,0.9792,0.9823,0.9851,0.9877,0.9900,0.9921,0.9940,0.9956,0.9969,0.9980,0.9989,0.9995,0.9999,1,0.9999,0.9995,0.9989,0.9980,0.9969,0.9956,0.9940,0.9921,0.9900,0.9877,0.9851,0.9823,0.9792,0.9759,0.9724,0.9686,0.9646,0.9603,0.9558,0.9511,0.9461,0.9409,0.9354,0.9298,0.9239,0.9178,0.9114,0.9048,0.8980,0.8910,0.8838,0.8763,0.8686,0.8607,0.8526,0.8443,0.8358,0.8271,0.8181,0.8090,0.7997,0.7902,0.7804,0.7705,0.7604,0.7501,0.7396,0.7290,0.7181,0.7071,0.6959,0.6845,0.6730,0.6613,0.6494,0.6374,0.6252,0.6129,0.6004,0.5878,0.5750,0.5621,0.5490,0.5358,0.5225,0.5090,0.4955,0.4818,0.4679,0.4540,0.4399,0.4258,0.4115,0.3971,0.3827,0.3681,0.3535,0.3387,0.3239,0.3090,0.2940,0.2790,0.2639,0.2487,0.2334,0.2181,0.2028,0.1874,0.1719,0.1564,0.1409,0.1253,0.1097,0.0941,0.0785,0.0628,0.0471,0.0314,0.0157,0};floatsinb[200]={-0.0157,-0.0314,-0.0471,-0.0628,-0.0785,-0.0941,-0.1097,-0.1253,-0.1409,-