基于DSP2812的SVPWM波形实现程序(共6页)_第1页
基于DSP2812的SVPWM波形实现程序(共6页)_第2页
基于DSP2812的SVPWM波形实现程序(共6页)_第3页
基于DSP2812的SVPWM波形实现程序(共6页)_第4页
基于DSP2812的SVPWM波形实现程序(共6页)_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精选优质文档-倾情为你奉上基于DSP2812的SVPWM波形实现程序 / file name: svpwm.c/generate svpwm waveforms#include "math.h"#include "DSP281x_Device.h" / DSP281x Headerfile Include File#include "DSP281x_Examples.h"#include <stdio.h> / DSP281x Examples Include File/global variablesfloat Tz=2

2、e-4;int Vdc=600;/float PI=3.1415;/int f=50;/ Prototype statements for functions found in this file.void svpwm(float *ptr,float uapha,float ubeta,float Tswitch,int vdc_link);void init_eva(void);void main(void)float cmpr3=0,0,0;/cmpr3=CMPR1,CMPR2,CMPR3)float *ptrc=&cmpr0;/point to the addrs of cmp

3、rfloat v_aphar=100;/reference value of vapharfloat v_betar=-20;/reference value of vbetar/float tstep=0.;/float tend=5/float w=2*PI*f;/float y=sin(w*t);/ Step 1. Initialize System Control:/ PLL-30MHz*10/2, disable WatchDog, enable Peripheral Clocks/ This example function is found in the DSP281x_SysC

4、trl.c file. InitSysCtrl();/ Step 2. Initalize GPIO: / This example function is found in the DSP281x_Gpio.c file and/ illustrates how to set the GPIO to it's default state.InitGpio();/ Step 3. Clear all interrupts and initialize PIE vector table:/ Disable CPU interrupts DINT; /asm(" setc INT

5、M")/ 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 DSP281x_PieCtrl.c file. /InitPieCtrl(); / Disable CPU interrupts and clear all CPU interrupt flags: IER = 0x0000; IFR = 0x0

6、000;/ 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 shell ISR routines are found in DSP281x_DefaultIsr.c./ This function

7、 is found in DSP281x_PieVect.c./ InitPieVectTable(); init_eva();svpwm(ptrc,v_aphar,v_betar,Tz,Vdc); EvaRegs.CMPR1 = cmpr0*75e6;EvaRegs.CMPR2 = cmpr1*75e6;EvaRegs.CMPR3 = cmpr2*75e6;/*/function: svpwm/discription: /*void svpwm(float *ptr,float uapha,float ubeta,float Tswitch,int vdc_link)int A,B,C,N;

8、double X,Y,Z,Tx,Ty,T0,Tl,Tm,Th;if (ubeta>0) A = 1;else A=0; if (1.*uapha-ubeta)>0) B = 1;else B=0;if (-1.*uapha-ubeta)>0) C = 1;else C=0;N=A+2*B+4*C;X=1.*ubeta*Tswitch/vdc_link;Y=(0.8660*ubeta+1.5*uapha)*Tswitch/vdc_link;Z=(-0.8660*ubeta+1.5*uapha)*Tswitch/vdc_link;switch (N) case 1: Tx= Y;

9、Ty=-Z;break; case 2: Tx=-X;Ty= Y;break; case 3: Tx= Z;Ty= X;break; case 4: Tx=-Z;Ty=-X;break; case 5: Tx= X;Ty=-Y;break; default: Tx=-Y;Ty= Z;if (Tx+Ty)>Tswitch)Tx=Tx*Tswitch/(Tx+Ty);Ty=Ty*Tswitch/(Tx+Ty);T0=(Tswitch-(Tx+Ty)/4;Tl=(Tswitch+Tx-Ty)/4;/*Tl=T0/4+Tx/2*/Tm=(Tswitch-Tx+Ty)/4;/*Tm=T0/4+Ty

10、/2*/Th=(Tswitch+Tx+Ty)/4;/*Th=T0/4+Ty/2+Ty/2*/switch (N) case 1 :*ptr=Tm; *(ptr+1)=T0; *(ptr+2)=Th;break; case 2 :*ptr=T0; *(ptr+1)=Th; *(ptr+2)=Tm;break; case 3 :*ptr=T0; *(ptr+1)=Tl; *(ptr+2)=Th;break; case 4 :*ptr=Th; *(ptr+1)=Tm; *(ptr+2)=T0;break; case 5 :*ptr=Th; *(ptr+1)=T0; *(ptr+2)=Tl;break

11、; default :*ptr=Tl; *(ptr+1)=Th; *(ptr+2)=T0;void init_eva()/ EVA Configure T1PWM, T2PWM, PWM1-PWM6 / Initalize the timers / Initalize EVA Timer1 EvaRegs.T1PR = 0x1D4C; / Timer1 period HSPCLK/fz=75E6/5E3=15000,T1PR=15000/2=0X1D4C /EvaRegs.T1CMPR = 0x3C00; / Timer1 compare EvaRegs.T1CNT = 0x0000; / T

12、imer1 counter / TMODE = continuous up/down / Timer enable / Timer compare enable /EVA_INPUT_CLK=HSPCLK/1=75MHZ EvaRegs.T1CON.all = 0x0842; / Initalize EVA Timer2 /EvaRegs.T2PR = 0x0FFF; / Timer2 period/ EvaRegs.T2CMPR = 0x03C0; / Timer2 compare/EvaRegs.T2CNT = 0x0000; / Timer2 counter/ TMODE = conti

13、nuous up/down/ Timer enable/ Timer compare enable/EvaRegs.T2CON.all = 0x1042; / Setup T1PWM and T2PWM/ Drive T1/T2 PWM by compare logicEvaRegs.GPTCONA.bit.TCMPOE = 1;/ Polarity of GP Timer 1 Compare = Active lowEvaRegs.GPTCONA.bit.T1PIN = 1;/ Polarity of GP Timer 2 Compare = Active highEvaRegs.GPTCO

14、NA.bit.T2PIN = 2;/ Enable compare for PWM1-PWM6EvaRegs.CMPR1 = 0x0C00;EvaRegs.CMPR2 = 0x3C00;EvaRegs.CMPR3 = 0xFC00; / Compare action control. Action that takes place/ on a cmpare event/ output pin 1 CMPR1 - active high/ output pin 2 CMPR1 - active low/ output pin 3 CMPR2 - active high/ output pin 4 CMPR2 - active low/ output pin 5 CMPR3 - active high/ outp

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论