2022年svpwm源程序_第1頁
2022年svpwm源程序_第2頁
2022年svpwm源程序_第3頁
2022年svpwm源程序_第4頁
2022年svpwm源程序_第5頁
已閱讀5頁,還剩6頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、/ ti file $revision: /main/8 $/ checkin $date: april 21, 2008 15:41:53 $/#/ file: example_2833xepwmupdownaq.c/ title: 空間電壓矢量產(chǎn)生程序svpwm/ assumptions:/ this program requires the dsp2833x header files. / monitor epwm1-epwm3 pins on an oscilloscope as described/ below./ epwm1a is on gpio0-5腳/ epwm1b is o

2、n gpio1-6腳/ epwm2a is on gpio2-7腳/ epwm2b is on gpio3-10腳/ epwm3a is on gpio4-11腳/ epwm3b is on gpio5-12腳/#/ $ti release: dsp2833x/dsp2823x header files v1.20 $/ $release date: august 1, 2008 $/#includedsp28x_project.h/ device headerfile and examples include file/ prototype statements for functions

3、found within this file.voidinitepwm1example( void ); voidinitepwm2example( void ); voidinitepwm3example( void ); voidsvpwmgen( void ); interruptvoidsvpwm_isr( void ); volatilefloat ualpha,ubeta; volatilefloat a,b,c; 精品學習資料 可選擇p d f - - - - - - - - - - - - - - 第 1 頁,共 11 頁 - - - - - - - - -精品學習資料 可選擇

4、p d f - - - - - - - - - - - - - - 第 1 頁,共 11 頁 - - - - - - - - -volatilefloat t0,t1,t2,t3,t4,t5,t6; volatilefloat taon,tbon,tcon; float ua,ub,uc; float ts; int a,b,c; int n= 0,sector= 0; #define tprd 800 #define udc 800 voidmain ( void ) / step 1. initialize system control:/ pll, watchdog, enable pe

5、ripheral clocks/ this example function is found in the dsp2833x_sysctrl.c file. initsysctrl(); / step 2. initalize gpio: / this example function is found in the dsp2833x_gpio.c file and/ illustrates how to set the gpio to its default state./ initgpio(); / skipped for this example / for this case jus

6、t init gpio pins for epwm1, epwm2, epwm3/ these functions are in the dsp2833x_epwm.c file initepwm1gpio(); initepwm2gpio(); initepwm3gpio(); / step 3. clear all interrupts and initialize pie vector table:/ disable cpu interrupts dint; / initialize the pie control registers to their default state./ t

7、he default state is all pie interrupts disabled and flags/ are cleared. / this function is found in the dsp2833x_piectrl.c file. initpiectrl(); / disable cpu interrupts and clear all cpu interrupt flags: ier = 0 x0000; 精品學習資料 可選擇p d f - - - - - - - - - - - - - - 第 2 頁,共 11 頁 - - - - - - - - -精品學習資料

8、可選擇p d f - - - - - - - - - - - - - - 第 2 頁,共 11 頁 - - - - - - - - - ifr = 0 x0000; / initialize the pie vector table with pointers to the shell interrupt / service routines (isr). / this will populate the entire table, even if the interrupt/ is not used in this example. this is useful for debug purp

9、oses./ the shell isr routines are found in dsp2833x_defaultisr.c./ this function is found in dsp2833x_pievect.c. initpievecttable(); / interrupts that are used in this example are re-mapped to/ isr functions found within this file. eallow; / this is needed to write to eallow protected registers piev

10、ecttable.epwm1_int = &svpwm_isr; /pievecttable.epwm2_int = &epwm2_isr;/pievecttable.epwm3_int = &epwm3_isr; edis; / this is needed to disable write to eallow protected registers/ step 4. initialize all the device peripherals:/ this function is found in dsp2833x_initperipherals.c/ initper

11、ipherals(); / not required for this example/ for this example, only initialize the epwm eallow; sysctrlregs.pclkcr0.bit.tbclksync = 0; edis; initepwm1example(); initepwm2example(); initepwm3example(); eallow; sysctrlregs.pclkcr0.bit.tbclksync = 1; edis; / step 5. user specific code, enable interrupt

12、s:/ enable cpu int3 which is connected to epwm1-3 int: ier |= m_int3; / enable epwm intn in the pie: group 3 interrupt 1-3 piectrlregs.pieier3.bit.intx1 = 1; 精品學習資料 可選擇p d f - - - - - - - - - - - - - - 第 3 頁,共 11 頁 - - - - - - - - -精品學習資料 可選擇p d f - - - - - - - - - - - - - - 第 3 頁,共 11 頁 - - - - - -

13、 - - -/piectrlregs.pieier3.bit.intx2 = 1;/piectrlregs.pieier3.bit.intx3 = 1;/ enable global interrupts and higher priority real-time debug events: eint; / enable global interrupt intm ertm; / enable global realtime interrupt dbgm / step 6. idle loop. just sit and loop forever (optional):for (;) asm(

14、 nop); /main結(jié)束/=interruptvoidsvpwm_isr( void ) svpwmgen(); / set compare valuesepwm1regs.cmpa.half.cmpa = taon; / adjust duty for output epwm1aepwm2regs.cmpa.half.cmpa = tbon; / adjust duty for output epwm2aepwm3regs.cmpa.half.cmpa = tcon; / adjust duty for output epwm3a/ clear int flag for this tim

15、erepwm1regs.etclr.bit.int = 1; / acknowledge this interrupt to receive more interrupts from group 3piectrlregs.pieack.all = pieack_group3; voidinitepwm1example() 精品學習資料 可選擇p d f - - - - - - - - - - - - - - 第 4 頁,共 11 頁 - - - - - - - - -精品學習資料 可選擇p d f - - - - - - - - - - - - - - 第 4 頁,共 11 頁 - - - -

16、 - - - - - / setup tbclkepwm1regs.tbprd = tprd; / tprd=800,period = 1600 tbclk countsepwm1regs.tbphs.half.tbphs = 0; / set phase register to zeroepwm1regs.tbctr = 0 x0000; / clear counter/ setup counter modeepwm1regs.tbctl.bit.ctrmode = tb_count_updown;/ symmetrical modeepwm1regs.tbctl.bit.phsen = t

17、b_disable; /master moduleepwm1regs.tbctl.bit.prdld = tb_shadow; epwm1regs.tbctl.bit.syncosel = tb_ctr_zero; / sync down-stream module/ setup tpwmepwm1regs.tbctl.bit.hspclkdiv = tb_div2; / clock ratio to sysclkoutepwm1regs.tbctl.bit.clkdiv = 5; / 原為 tb_div1 , 對于上下計數(shù):tpwm = 2 x tbprd x ttbclk fpwm = 1

18、 / (tpwm)/setup shadowingepwm1regs.cmpctl.bit.shdwamode = cc_shadow; epwm1regs.cmpctl.bit.shdwbmode = cc_shadow; epwm1regs.cmpctl.bit.loadamode = cc_ctr_zero; / load on ctr=zeroepwm1regs.cmpctl.bit.loadbmode = cc_ctr_zero; / load on ctr=zero/ set actionsepwm1regs.aqctla.bit.cau = aq_set; / set actio

19、ns for epwm1aepwm1regs.aqctla.bit.cad = aq_clear; / set dead-bandepwm1regs.dbctl.bit.out_mode = db_full_enable; / enable dead-band moduleepwm1regs.dbctl.bit.polsel = db_actv_hic; / active hi complementaryepwm1regs.dbfed = 50; / fed = 50 tbclksepwm1regs.dbred = 50; / red = 50 tbclks/ interrupt where

20、we will change the compare valuesepwm1regs.etsel.bit.intsel = et_ctr_zero; / select int on zero eventepwm1regs.etsel.bit.inten = 1; / enable intepwm1regs.etps.bit.intprd = et_3rd; / generate int on 3rd event /*/ set compare values/=epwm1regs.cmpa.half.cmpa = 500; / adjust duty for output epwm1aepwm2

21、regs.cmpa.half.cmpa = 600; / adjust duty for output epwm2aepwm3regs.cmpa.half.cmpa = 700; / adjust duty for output epwm3a*/精品學習資料 可選擇p d f - - - - - - - - - - - - - - 第 5 頁,共 11 頁 - - - - - - - - -精品學習資料 可選擇p d f - - - - - - - - - - - - - - 第 5 頁,共 11 頁 - - - - - - - - - voidinitepwm2example() / set

22、up tbclkepwm2regs.tbprd = tprd; / tprd=800,period = 1600 tbclk countsepwm2regs.tbphs.half.tbphs = 0; / set phase register to zeroepwm2regs.tbctr = 0 x0000; / clear counter/ setup counter modeepwm2regs.tbctl.bit.ctrmode = tb_count_updown;/ symmetrical modeepwm2regs.tbctl.bit.phsen = tb_enable; / slav

23、e moduleepwm2regs.tbctl.bit.prdld = tb_shadow; epwm2regs.tbctl.bit.syncosel = tb_sync_in; / sync flow-through/ setup tpwmepwm2regs.tbctl.bit.hspclkdiv = tb_div2; / clock ratio to sysclkoutepwm2regs.tbctl.bit.clkdiv = 5; / for up and down count-tpwm = 2 x tbprd x ttbclk; fpwm = 1 / (tpwm)/ setup shad

24、owingepwm2regs.cmpctl.bit.shdwamode = cc_shadow; epwm2regs.cmpctl.bit.shdwbmode = cc_shadow; epwm2regs.cmpctl.bit.loadamode = cc_ctr_zero; / load on ctr=zeroepwm2regs.cmpctl.bit.loadbmode = cc_ctr_zero; / load on ctr=zero/ set actionsepwm2regs.aqctla.bit.cau = aq_set; / set actions for epwm2aepwm2re

25、gs.aqctla.bit.cad = aq_clear; / set dead-bandepwm2regs.dbctl.bit.out_mode = db_full_enable; / enable dead-band moduleepwm2regs.dbctl.bit.polsel = db_actv_hic; / active hi complementaryepwm2regs.dbfed = 50; / fed = 50 tbclksepwm2regs.dbred = 50; / red = 50 tbclks/ interrupt where we will change the c

26、ompare valuesepwm2regs.etsel.bit.intsel = et_ctr_zero; / select int on zero eventepwm2regs.etsel.bit.inten = 1; / enable intepwm2regs.etps.bit.intprd = et_3rd; / generate int on 3rd event / set compare values 精品學習資料 可選擇p d f - - - - - - - - - - - - - - 第 6 頁,共 11 頁 - - - - - - - - -精品學習資料 可選擇p d f -

27、 - - - - - - - - - - - - - 第 6 頁,共 11 頁 - - - - - - - - -voidinitepwm3example() / setup tbclkepwm3regs.tbprd = tprd; / tprd=800,period = 1600 tbclk countsepwm3regs.tbphs.half.tbphs = 0; / set phase register to zeroepwm1regs.tbctr = 0 x0000; / clear counter/ setup counter modeepwm3regs.tbctl.bit.ctrm

28、ode = tb_count_updown;/ symmetrical modeepwm3regs.tbctl.bit.phsen = tb_enable; / slave moduleepwm3regs.tbctl.bit.prdld = tb_shadow; epwm3regs.tbctl.bit.syncosel = tb_sync_in; / sync flow-through/ setup tpwmepwm3regs.tbctl.bit.hspclkdiv = tb_div2; / clock ratio to sysclkoutepwm3regs.tbctl.bit.clkdiv

29、= 5; / for up and down count:tpwm = 2 x tbprd x ttbclk; fpwm = 1 / (tpwm)/ setup shadowingepwm3regs.cmpctl.bit.shdwamode = cc_shadow; epwm3regs.cmpctl.bit.shdwbmode = cc_shadow; epwm3regs.cmpctl.bit.loadamode = cc_ctr_zero; / load on ctr=zeroepwm3regs.cmpctl.bit.loadbmode = cc_ctr_zero; / load on ct

30、r=zero/ set actionsepwm3regs.aqctla.bit.cau = aq_set; / set actions for epwm3aepwm3regs.aqctla.bit.cad = aq_clear; / set dead-bandepwm3regs.dbctl.bit.out_mode = db_full_enable; / enable dead-band moduleepwm3regs.dbctl.bit.polsel = db_actv_hic; / active hi complementaryepwm3regs.dbfed = 50; / fed = 5

31、0 tbclksepwm3regs.dbred = 50; / red = 50 tbclks/ interrupt where we will change the compare valuesepwm3regs.etsel.bit.intsel = et_ctr_zero; / select int on zero eventepwm3regs.etsel.bit.inten = 1; / enable intepwm3regs.etps.bit.intprd = et_3rd; / generate int on 3rd event / set compare values 精品學習資料

32、 可選擇p d f - - - - - - - - - - - - - - 第 7 頁,共 11 頁 - - - - - - - - -精品學習資料 可選擇p d f - - - - - - - - - - - - - - 第 7 頁,共 11 頁 - - - - - - - - -voidsvpwmgen( void ) /clarke ualpha= 0.6666667*(ua-0.5*ub-0.5*uc);/ 0.8660254 = sqrt(3)/2 ubeta = 0.6666667*(0.8660254*ub-0.8660254*uc );/0.6666667=2/3/sector

33、 a= ubeta; b= 1.7320508*ualpha-ubeta; c= -1.7320508*ualpha-ubeta; if(a= 0) a= 1; else a= 0; if(b= 0) b= 1; else b= 0; if(c= 0) c= 1; else c= 0; n=a+2*b+4*c; switch(n) case 1: sector = 2; break ; case 2: sector = 6; break ; case 3: sector = 1; break ; case 4: sector = 4; break ; case 5: sector = 3; b

34、reak ; case 6: sector = 5; break ; default: break ; /time ts=2*tprd;/ts為開關周期與載波周期(計數(shù)周期)相等if (sector= 1) t1= 1.5*ts*(ualpha-0.5773503*ubeta)/udc;/0.5773503=1/sqrt(3) t2= 1.7320508*ts*ubeta/udc; t0= ts-t1-t2; if(t1+t2ts) t1= t1*ts/(t1+t2); t2= t2*ts/(t1+t2); t0= ts-t1-t2; 精品學習資料 可選擇p d f - - - - - - -

35、 - - - - - - - 第 8 頁,共 11 頁 - - - - - - - - -精品學習資料 可選擇p d f - - - - - - - - - - - - - - 第 8 頁,共 11 頁 - - - - - - - - -elseif (sector= 2) t2= 1.5*ts*(ualpha+0.5773503*ubeta)/udc; t3= 1.5*ts*(0.5773503*ubeta-ualpha)/udc; t0= ts-t2-t3; if(t2+t3ts) t2= t2*ts/(t2+t3); t3= t3*ts/(t2+t3); t0= ts-t2-t3; el

36、seif (sector= 3) t3= 1.7320508*ts*ubeta/udc; t4= 1.5*ts*(ualpha+0.5773503*ubeta)/udc; t0= ts-t3-t4; if(t3+t4ts) t3= t3*ts/(t3+t4); t4= t4*ts/(t3+t4); t0= ts-t3-t4; elseif (sector= 4) t4= 1.5*ts*(0.5773503*ubeta-ualpha)/udc;/0.5773503=1/sqrt(3) t5= 1.7320508*ts*ubeta/udc; t0= ts-t4-t5; if(t4+t5ts) t4= t4*ts/(t4+t5); t5= t5*ts/(t4+t5); t0= ts-t4-t5; 精品學習資料 可選擇p d f - - - - - - - - - - - - - - 第 9 頁,

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論