版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2024年度地基資源買賣合同協(xié)議3篇
- 概率論課程設(shè)計(jì)小標(biāo)題
- 2024-2025學(xué)年度山東省德州市臨邑博文中學(xué)高一第一學(xué)期第三次月考?xì)v史試題
- 英語學(xué)科的課程設(shè)計(jì)方案
- 猜音符課程設(shè)計(jì)
- 網(wǎng)站課程設(shè)計(jì)收獲總結(jié)
- 班級班長培訓(xùn)課程設(shè)計(jì)
- 穩(wěn)壓器課程設(shè)計(jì)
- 英語交際用語課程設(shè)計(jì)
- 教輔行業(yè)助理的工作總結(jié)和技能要求
- 自然辯證法習(xí)題及答案
- 特色農(nóng)產(chǎn)品超市方案
- 2024國有企業(yè)與民營企業(yè)之間的混合所有制改革合同
- 2024年醫(yī)院食堂餐飲獨(dú)家承包協(xié)議
- 保險(xiǎn)公司廉政風(fēng)險(xiǎn)防控制度
- DB34T4868-2024智慧醫(yī)院醫(yī)用耗材院內(nèi)物流規(guī)范
- 2025年蛇年年會(huì)匯報(bào)年終總結(jié)大會(huì)模板
- 《稻草人》閱讀題及答案
- 國家職業(yè)技術(shù)技能標(biāo)準(zhǔn) X2-10-07-17 陶瓷產(chǎn)品設(shè)計(jì)師(試行)勞社廳發(fā)200633號
- 瑜伽基礎(chǔ)知識題庫單選題100道及答案解析
- 廣東省廣州市2024年中考數(shù)學(xué)真題試卷(含答案)
評論
0/150
提交評論