ImageVerifierCode 换一换
格式:DOCX , 页数:13 ,大小:17.63KB ,
资源ID:4745854      下载积分:12 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/4745854.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(svpwm源程序.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

svpwm源程序.docx

1、svpwm源程序/ TI File $Revision: /main/8 $/ Checkin $Date: April 21, 2008 15:41:53 $/#/ FILE: Example_2833xEPwmUpDownAQ.c/ TITLE: 空间电压矢量产生程序SVPWM/ ASSUMPTIONS:/ This program requires the DSP2833x header files. / Monitor ePWM1-ePWM3 pins on an oscilloscope as described/ below./ EPWM1A is on GPIO0-5脚/ EPW

2、M1B is on 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 $/#include DSP28x_Project.h / Device Headerfile and Examples Include File/ Prototype statements for

3、functions found within this file.void InitEPwm1Example(void);void InitEPwm2Example(void);void InitEPwm3Example(void);void svpwmGen(void);interrupt void svpwm_isr(void);volatile float Ualpha,Ubeta;volatile float A,B,C;volatile float T0,T1,T2,T3,T4,T5,T6;volatile float Taon,Tbon,Tcon;float Ua,Ub,Uc;fl

4、oat Ts;int a,b,c;int N= 0,sector= 0;#define TPRD 800#define Udc 800void main(void)/ Step 1. Initialize System Control:/ PLL, WatchDog, enable Peripheral Clocks/ This example function is found in the DSP2833x_SysCtrl.c file. InitSysCtrl();/ Step 2. Initalize GPIO: / This example function is found in

5、the DSP2833x_Gpio.c file and/ illustrates how to set the GPIO to its default state./ InitGpio(); / Skipped for this example / For this case just init GPIO pins for ePWM1, ePWM2, ePWM3/ These functions are in the DSP2833x_EPwm.c file InitEPwm1Gpio(); InitEPwm2Gpio(); InitEPwm3Gpio(); / Step 3. Clear

6、all interrupts and initialize PIE vector table:/ Disable CPU interrupts DINT;/ Initialize the PIE control registers to their default state./ The default state is all PIE interrupts disabled and flags/ are cleared. / This function is found in the DSP2833x_PieCtrl.c file. InitPieCtrl(); / Disable CPU

7、interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0000;/ 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 purposes./ The

8、 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 PieVectTable.EP

9、WM1_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/ InitPeripherals(); / Not requ

10、ired 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 interrupts:/ Enable CPU INT3 whi

11、ch 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; /PieCtrlRegs.PIEIER3.bit.INTx2 = 1; /PieCtrlRegs.PIEIER3.bit.INTx3 = 1;/ Enable global Interrupts and higher priority real-time debug events: EINT; / Enable Global in

12、terrupt INTM ERTM; / Enable Global realtime interrupt DBGM / Step 6. IDLE loop. Just sit and loop forever (optional): for(;) asm( NOP); /main结束 /=interrupt void svpwm_isr(void)svpwmGen();/ Set Compare valuesEPwm1Regs.CMPA.half.CMPA = Taon; / adjust duty for output EPWM1AEPwm2Regs.CMPA.half.CMPA = Tb

13、on; / adjust duty for output EPWM2AEPwm3Regs.CMPA.half.CMPA = Tcon; / adjust duty for output EPWM3A / Clear INT flag for this timerEPwm1Regs.ETCLR.bit.INT = 1;/ Acknowledge this interrupt to receive more interrupts from group 3PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;void InitEPwm1Example()/ Setup TBC

14、LKEPwm1Regs.TBPRD = TPRD; / TPRD=800,Period = 1600 TBCLK countsEPwm1Regs.TBPHS.half.TBPHS = 0; / Set Phase register to zeroEPwm1Regs.TBCTR = 0x0000; / Clear counter/ Setup counter modeEPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;/ Symmetrical modeEPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; /Master modu

15、leEPwm1Regs.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, 对于上下计数:Tpwm = 2 x TBPRD x TTBCLK Fpwm = 1 / (Tpwm)/Setup shadowingEP

16、wm1Regs.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 actions for EPWM1AEPwm1Regs.AQCTLA

17、.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 we will change the Compare Val

18、uesEPwm1Regs.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 EPWM1AEPwm2Regs.CMPA.half.CMPA = 600; / a

19、djust duty for output EPWM2AEPwm3Regs.CMPA.half.CMPA = 700; / adjust duty for output EPWM3A*/void InitEPwm2Example()/ Setup TBCLKEPwm2Regs.TBPRD = TPRD; / TPRD=800,Period = 1600 TBCLK countsEPwm2Regs.TBPHS.half.TBPHS = 0; / Set Phase register to zeroEPwm2Regs.TBCTR = 0x0000; / Clear counter/ Setup c

20、ounter modeEPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;/ Symmetrical modeEPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE; / Slave 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 SY

21、SCLKOUTEPwm2Regs.TBCTL.bit.CLKDIV = 5; / For Up and Down Count-Tpwm = 2 x TBPRD x TTBCLK; Fpwm = 1 / (Tpwm)/ Setup shadowingEPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; / load on CTR=ZeroEPwm2Regs.CMPCTL.bit.LOADB

22、MODE = CC_CTR_ZERO; / load on CTR=Zero/ Set actionsEPwm2Regs.AQCTLA.bit.CAU = AQ_SET; / set actions for EPWM2AEPwm2Regs.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 complementary

23、EPwm2Regs.DBFED = 50; / FED = 50 TBCLKsEPwm2Regs.DBRED = 50; / RED = 50 TBCLKs/ Interrupt where we will change the Compare 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 ev

24、ent / Set Compare valuesvoid InitEPwm3Example()/ Setup TBCLKEPwm3Regs.TBPRD = TPRD; / TPRD=800,Period = 1600 TBCLK countsEPwm3Regs.TBPHS.half.TBPHS = 0; / Set Phase register to zeroEPwm1Regs.TBCTR = 0x0000; / Clear counter/ Setup counter modeEPwm3Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;/ Symmetrica

25、l 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 = 5; / For Up and Down Count:Tpwm =

26、 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 CTR=Zero/ Set actionsEPwm3Regs.AQCTLA.b

27、it.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 = 50 TBCLKsEPwm3Regs.DBRED = 50; / RED =

28、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 valuesvoid svpwmGen(void) /clarke Ualpha= 0.6666667

29、*(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 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:

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1