版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上精選優(yōu)質(zhì)文檔-傾情為你奉上專心-專注-專業(yè)專心-專注-專業(yè)精選優(yōu)質(zhì)文檔-傾情為你奉上專心-專注-專業(yè)#include DSP28x_Project.h#include IQmathLib.h/#include math.h#define PWM1_INT_ENABLE 1#define PWM2_INT_ENABLE 1#define PWM3_INT_ENABLE 1#define PWM4_INT_ENABLE 1void InitEPwm1Example(void);void InitEPwm2Example(void);void InitEPwm3Exampl
2、e(void);interrupt void epwm1_timer_isr(void);/interrupt void epwm2_timer_isr(void);/interrupt void epwm3_timer_isr(void);Uint32 EPwm1TimerIntCount;Uint32 EPwm2TimerIntCount;Uint32 EPwm3TimerIntCount;Uint32 EPwm4TimerIntCount;Uint32 TonC1,TonC2;Uint16 k;float32 Tc,N;#define PI 3.float32 M=0.8;float32
3、 fz=20000;float32 fr=50;void main(void) InitSysCtrl(); InitEPwm1Gpio(); / InitEPwm2Gpio(); / InitEPwm3Gpio(); DINT; InitPieCtrl(); IER = 0 x0000; IFR = 0 x0000; InitPieVectTable(); EALLOW; / This is needed to write to EALLOW protected registers PieVectTable.EPWM1_INT = &epwm1_timer_isr; / PieVectTab
4、le.EPWM2_INT = &epwm2_timer_isr; / PieVectTable.EPWM3_INT = &epwm3_timer_isr; EDIS; EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; / Stop all the TB clocks EDIS; InitEPwm1Example(); / InitEPwm2Example(); / InitEPwm3Example(); EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; EDIS; EPwm1TimerIntCount =
5、0; EPwm2TimerIntCount = 0; EPwm3TimerIntCount = 0; IER |= M_INT3; PieCtrlRegs.PIEIER3.bit.INTx1 = PWM1_INT_ENABLE; / PieCtrlRegs.PIEIER3.bit.INTx2 = PWM2_INT_ENABLE; / PieCtrlRegs.PIEIER3.bit.INTx3 = PWM3_INT_ENABLE; EINT; / Enable Global interrupt INTM ERTM; for(;) asm( NOP); void InitEPwm1Example(
6、) EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO;/zhuyi EPwm1Regs.TBPRD = 1500; /載波周期=2*1500TBCLK EPwm1Regs.TBPHS.half.TBPHS = 0 x0000; / Phase is 0 EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW; EPwm1Regs.TBCTR = 0 x0000; EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; / Count up down EPwm1Regs.TBCTL.bit.PHSEN
7、= TB_DISABLE; / Disable phase loading EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; / Clock ratio to SYSCLKOUT EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1; EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; / Load registers every ZERO_PRD EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW; EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_
8、CTR_ZERO_PRD; EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO_PRD; EPwm1Regs.CMPA.half.CMPA =1000; EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR; / Clear PWM1A on CAU EPwm1Regs.AQCTLA.bit.CAD = AQ_SET; EPwm1Regs.AQCTLB.bit.CAU = AQ_SET; / SET PWM1B on CAU EPwm1Regs.AQCTLB.bit.CAD = AQ_CLEAR; /set dead band EPwm1
9、Regs.ETSEL.bit.INTSEL = ET_CTR_PRDZERO; /? Select INT on Zero Prd event EPwm1Regs.ETSEL.bit.INTEN = PWM1_INT_ENABLE; / Enable INT EPwm1Regs.ETPS.bit.INTPRD = ET_1ST;interrupt void epwm1_timer_isr(void) EPwm1TimerIntCount+; if( EPwm1Regs.TBCTR=1500) k=0; N=fz/fr; Tc=1/fz; TonC1=Tc/4*(1+M*sin(k*PI/N);
10、 k+=2; if(k(2*N-2) k=0; EPwm1Regs.CMPA.half.CMPA = TonC1; / EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR; / Clear PWM1A on CAU / EPwm1Regs.AQCTLA.bit.CAD = AQ_SET; / EPwm1Regs.AQCTLB.bit.CAU = AQ_SET; / SET PWM1B on CAU / EPwm1Regs.AQCTLB.bit.CAD = AQ_CLEAR; else k=1; N=fz/fr; Tc=1/fz; TonC2=Tc/4*(1+M*sin(k*
11、PI/N); k+=2; if(k(2*N-1) k=1; EPwm1Regs.CMPA.half.CMPA = TonC2;/ EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR; / Clear PWM1A on CAU/ EPwm1Regs.AQCTLA.bit.CAD = AQ_SET; / EPwm1Regs.AQCTLB.bit.CAU = AQ_SET; / SET PWM1B on CAU / EPwm1Regs.AQCTLB.bit.CAD = AQ_CLEAR; / Clear INT flag for this timer EPwm1Regs.ETCL
12、R.bit.INT = 1; / Acknowledge this interrupt to receive more interrupts from group 3 PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;#include DSP280 x_Device.h / DSP280 x Headerfile Include File#include DSP280 x_Examples.h / DSP280 x Examples Include Filevoid InitePWM(void) EALLOW;EPwm1Regs.TBPRD = 600; / Per
13、iod = 601 TBCLK countsEPwm1Regs.CMPA = 350; / Compare A = 350 TBCLK countsEPwm1Regs.CMPB = 200; / Compare B = 200 TBCLK countsEPwm1Regs.TBPHS = 0; / Set Phase register to zeroEPwm1Regs.TBCTR = 0; / clear TB counterEPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; / Ph
14、ase loading disabledEPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; / TBCLK = SYSCLKEPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;EPwm1Regs.CMPCT
15、L.bit.LOADAMODE = CC_CTR_ZERO; / load on CTR = ZeroEPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO; / load on CTR = ZeroEPwm1Regs.AQCTLA.bit.PRD = AQ_CLEAR;EPwm1Regs.AQCTLA.bit.CAU = AQ_SET;EPwm1Regs.AQCTLB.bit.PRD = AQ_CLEAR;EPwm1Regs.AQCTLB.bit.CBU = AQ_SET;EPwm1Regs.DBCTL.bit.OUT_MODE = DB_DISABLE;E
16、Pwm1Regs.PCCTL.bit.CHPEN = CHP_DISABLE;EPwm1Regs.TZCTL.bit.TZA = TZ_NO_CHANGE;EPwm1Regs.TZCTL.bit.TZB = TZ_NO_CHANGE;EDIS;#includeDSP28_Device.h #includestdio.h #includemath.h #includefloat.h #defineNX404 #definePI3. floatM=0.8;intk0,h1,h2;doubleaNX;externinttp=1250;voidzkb();interruptvoideva_T1UFIN
17、T_ISR(void);voidmain(void)k0=0;h1=0;h2=0;InitSysCtrl();DINT;/禁止全局中斷 IER=0;IFR=0;EALLOW;/EnablePWMpins GpioMuxRegs.GPAMUX.all=0 x00FF;/EVAPWM1-6pins /GpioMuxRegs.GPBMUX.all=0 x00FF;/EVBPWM7-12pins EDIS;InitPieCtrl();InitPieVectTable();EALLOW;PieVectTable.T1UFINT=&eva_T1UFINT_ISR;EDIS;IER|=M_INT2;PieC
18、trl.PIEIER2.bit.INTx6=1;InitEv();zkb();EvaRegs.T1CON.all=EvaRegs.T1CON.all|0 x0040;/啟動(dòng)定時(shí)器1 EINT;while(1)asm(NOP);voidzkb()unsignedintn=0;floatq,l,j;while(n=375&l3375)an=3375;elsean=375;n=n+1;*/if(l=(tp*0.1)&(l(tp*0.9)an=tp*0.9;elsean=tp*0.1;n=n+1;interruptvoideva_T1UFINT_ISR(void)/EV-A inth2;intflag;flag=(EvaRegs.EVAIFRA.all)&0
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 滬科版八年級(jí)數(shù)學(xué)上冊(cè)第12章一次函數(shù)12-1函數(shù)第2課時(shí)函數(shù)的表示方法列表法解析法課件
- 北師大版八年級(jí)生物上冊(cè)第6單元生命的延續(xù)第19章生物的生殖和發(fā)育第3節(jié)植物的生殖方式課件
- 六年級(jí)上冊(cè)第三單元總結(jié)語(yǔ)文
- 統(tǒng)編版五年級(jí)語(yǔ)文上冊(cè)第四單元知識(shí)要點(diǎn)
- DB34T 4961-2024農(nóng)村飲用水安全衛(wèi)生評(píng)價(jià)
- 人教版八年級(jí)數(shù)學(xué)上冊(cè)《12.2三角形全等的判定》同步測(cè)試題帶答案
- 【六年級(jí)】上冊(cè)道德與法治-6上2單元第4課《公民的基本權(quán)利和義務(wù)》
- 化 學(xué)物質(zhì)組成的表示課件-2024-2025學(xué)年九年級(jí)化學(xué)人教版(2024)上冊(cè)
- 期中測(cè)試卷(1-4單元)(試題)-2024-2025學(xué)年六年級(jí)上冊(cè)數(shù)學(xué)北師大版
- 青島版科學(xué)三年級(jí)上冊(cè)全冊(cè)教案
- 廚房設(shè)備物品清單
- 五年級(jí)上冊(cè)數(shù)學(xué)課件-5.3 除數(shù)是整數(shù)的小數(shù)除法丨蘇教版 (共15張PPT)
- 能源數(shù)據(jù)收集計(jì)劃表
- 實(shí)驗(yàn)室安全排查記錄表
- 《三相異步電動(dòng)機(jī)正反轉(zhuǎn)控制線路》教學(xué)課件
- 六年級(jí)上冊(cè)語(yǔ)文課件- 《12. 橋》 (共24張PPT)部編版
- 實(shí)驗(yàn)9通過(guò)串口命令控制led亮滅
- DB51∕T 1627-2013 渠道工程施工質(zhì)量檢驗(yàn)與評(píng)定規(guī)程
- AutoCAD關(guān)于“多重插入引用”(多重塊)的分解
- 2022年陜西省西安市雁塔區(qū)西安高新第一小學(xué)六上期中數(shù)學(xué)試卷
- 汽輪機(jī)發(fā)電機(jī)組發(fā)電能力計(jì)算模板
評(píng)論
0/150
提交評(píng)論