andior:
用TMS320LF2407实现三相SPWM波形发生器FCL.usect ".data0",1;保存载波频率浮点数的低位FCH.usect ".data0",1;保存载波频率浮点数的高位FRL.usect ".data0",1;保存信号频率浮点数的低位FRH.usect ".data0",1;保存信号频率浮点数的高位AL.usect ".data0",1;保存调谐度浮点数低位AH.usect ".data0",1;保存调谐度浮点数高位N .usect ".data0",1 ;保存一个周期要输出的PWM脉冲个数NL.usect ".data0",1;保存一个周期要输出的PWM脉冲个数浮点数低位NH.usect ".data0",1;保存一个周期要输出的PWM脉冲个数浮点数低位I.usect ".data0",1;保存当前输出的是第几个脉冲T3PR_TEMPL .usect".data0",1;保存定时器3周期寄存器值的浮点数低位 T3PR_TEMPH.usect".data0",1;保存定时器3周期寄存器值的浮点数高位 DATIOL .usect".data0",1;保存占空比浮点数低位DATIOH .usect".data0",1;保存占空比浮点数低位DFLAG.usect ".data0",1;送出一个脉冲的标志寄存器.include "F2407REGS.H";引用头部文件.refF$$ITOF,F$$DIV,F$$MUL,F$$FTOI,F$$ADD,F$$LTOF,F$$SUB.ref _sin.def _c_int0;(1)建立中断向量表.sect".vectors";定义主向量段RSVECTB _c_int0;PM0ResetVector1INT1 B PHANTOM;PM2Intlevel14INT2 B GISR2;PM4Intlevel25INT3 B PHANTOM;PM6Intlevel36INT4 B PHANTOM;PM8Intlevel47INT5 B PHANTOM;PMAIntlevel58INT6 B PHANTOM;PMCIntlevel69RESERVED B PHANTOM;PME(AnalysisInt)10SW_INT8 B PHANTOM;PM10 UserS/Wint— • •SW_INT31 B PHANTOM;PM3E UserS/Wint—;中断子向量入口定义pvecs.sect".pvecs";定义子向量段PVECTORSBPHANTOM;Reservedpvectoraddroffset-0000hBPHANTOM;Reservedpvectoraddroffset-0001h • •BPHANTOM;Reservedpvectoraddroffset-002EhBT3GP_ISR;Reservedpvectoraddroffset-002Fh T3PINT中断BPHANTOM;Reservedpvectoraddroffset-0030h • •BPHANTOM;Reservedpvectoraddroffset-0041h;(2)主程序.text_c_int0: CALLSYSINIT;调系统初始化子程序CALLPWM_INIT;调PWM初始化子程序 LDP#5SPLK#2710H,FCL;载波频率SPLK#0,FCHSPLK#032H,FRL;信号频率SPLK#0,FRHSPLK#3E8H,AL;调谐度AL=A*1000SPLK#0,AHSPLK#0,I;I=0SPLK#1,DFLAG CALL JISUANLOOP:LDP#5BITDFLAG,BIT0BCNDLOOP,NTCLACLDFLAGAND#0FFFEHSACLDFLAGCALLDATIOBLOOP;(3)系统初始化程序SYSINIT:SETCINTMCLRCCNFLDP#0SPLK#02h,IMR;使能第1级中断2SPLK#0FFFFh,IFR;清第1级所有中断标志位LDP#DP_PF1SPLK#0E8h,WDCR;禁止WDTLDP#00E0HSPLK#81FEH,SCSR1 ;CLKIN=6M,CLKOUT=24MRET;(4)EVB模块的PWM初始化程序PWM_INIT:LDP#DP_PF2LACLMCRAOR#07EH;IOPE1~IOPE6SACLMCRC;配置为特殊功能LACLMCRCOR#600hSACLMCRCLDP#DP_EVBSPLK#0FFFFh,EVBIFRA;清EVA的所有中断标志位SPLK#0555h,ACTRB;PWM6,4,2为低,PWM5,3,1为高SPLK#00h,DBTCONB;禁止死区控制SPLK#1fh,CMPR4;给比较寄存器赋初值SPLK#2Fh,CMPR5SPLK#3fh,CMPR6SPLK#0960h,T3PR;给周期寄存器赋初值LDP#5SPLK#0960h,T3PR_TEMPLSPLK#0,T3PR_TEMPHLDP#DP_EVBSPLK#0A600h,COMCONB;禁止比较功能SPLK0,T3CNTSPLK#41h,GPTCONBSPLK#080h,EVBIMRASPLK#0000101101001110b,T3CONCLRCINTMRET;(5)将一些整数转换为浮点数子程序,得到计算占空比要用的常数JISUAN:LDP#5;调谐度由整形转换为浮点LACLALLRLK AR1,STACK ;设置STACK指针SETCSXMCALLF$$ITOF,AR1;A=a×1000CLRCSXMMAR*-LACC*-,16ADDS*SACLALSACHAHLRLKAR1,STACK;A/2000=0.5aSETCSXMLACL#0SACL*+LACL#44FAH;44FA0000h=2000SACL*+LACLALSACL*+LACLAHSACL*+CALLF$$DIVMAR*-LACC*-,16ADDS*SACLALSACHAHLACLT3PR_TEMPLLRLK AR1,STACKSETCSXM;定时器周期寄存器;的值转换为浮点数CALLF$$ITOF,AR1CLRCSXMMAR*-LACC*-,16ADDS*SACLT3PR_TEMPLSACHT3PR_TEMPHLACLFCL;FC值转换为浮点数LRLK AR1,STACKSETCSXMCALLF$$LTOF,AR1CLRCSXMMAR*-LACC*-,16ADDS*SACLFCLSACHFCHLACLFRLLRLK AR1,STACKSETCSXM ;FR值转换为浮点数CALLF$$ITOF,AR1CLRCSXMMAR*-LACC*-,16ADDS*SACLFRLSACHFRHLRLK AR1,STACK;N=FC/FRLACLFRLSACL*+LACLFRHSACL*+LACLFCLSACL*+LACLFCHSACL*+CALLF$$DIVMAR*-LACC*-,16ADDS*SACLNLSACHNH;N的浮点数LRLK AR1,STACKSETCSXMSACL*+SACH*+CALLF$$FTOISACLN;N的整数LRLKAR1,STACKSACL*+LACLNHSACL*+LACL#0F5C3H;40C8F5C3h=6.282=2×3.141SACL*+LACL#40C8HSACL*+CALLF$$DIVMAR*-LACC*-,16ADDS*SACLNLSACHNHRET;(6)计算占空比子程序DATIO:LDP#5LACLI ;I由整形转换为浮点数LRLK AR1,STACKSETCSXMCALLF$$ITOF,AR1CLRCSXMMAR*-LACC*-,16ADDS*;结果保存在ACCLRLKAR1,STACK;i*2*3.14/NSACL*+SACH*+LACLNLSACL*+LACLNHSACL*+CALLF$$MULMAR*-ZALH*-ADDS*LRLK AR1,STACK;sin(i*2*3.14/N)SACL*+SACH*+CALL_sin;结果在ACCLRLK AR1,STACK;0.5a*sin(i*2*3.14/N)SACL*+SACH*+LACLALSACL*+LACLAHSACL*+CALLF$$MULMAR*-ZALH*-ADDS*;结果在ACCLRLK AR1,STACK;D=0.5+A*sin(i*2*3.14/N)SACL*+SACH*+LACL#0SACL*+LACL#3F00H;3F000000h=0.5SACL *+CALLF$$ADDMAR*-ZALH*-ADDS*;结果在ACCLRLKAR1,STACKSACL*+SACH*+LACLT3PR_TEMPLSACL*+LACLT3PR_TEMPHSACL*+CALLF$$MULMAR*-ZALH*-ADDS*;结果在ACCLRLK AR1,STACK;CMPR的浮点数转换为整数SETCSXMSACL*+SACH*+CALLF$$FTOI,AR1CLRCSXM;结果在ACCSACLDATIOLLDP#5LACCISUBNBCNDNSPWM,GEQLACCIADD#1SACLIBRRETNSPWM:SPLK#0,I;断是否是下一个周期RRET:RET PHANTOM:KICK_DOG;复位WD计数器RET;(7)定时器3中断程序GISR2:SST#0,ST0_CON1;保存状态寄存器SST#1,ST1_CON1LDP#0E0h;DP指针指向PIVR所在的数据区LACCPIVR,1;读EVIVRB,结果左移一位ADD#PVECTORS;加上偏移量BACCT3GP_ISR:LDP#5LACCDFLAGOR#1;设置DFLAG.15=1SACLDFLAGLACLDATIOLLDP#DP_EVBSACLCMPR4;更新比较寄存器的值ADD#32HSACLCMPR5ADD#32HSACLCMPR6LDP#0LST#1,ST1_CON1LST#0,ST0_CON1LDP#DP_EVBSPLK#0FFFFH,EVBIFRACLRCINTMRETEND