版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年热保护器项目发展计划
- 2024年深冷技术设备项目发展计划
- 2024年智能电能表项目建议书
- 2024年船专用码头合作协议书
- 2024年液晶聚合物LCP项目合作计划书
- 2024年飞行试验地面设备项目发展计划
- 2024年电路保护元器件项目发展计划
- 山西省大同市2023-2024学年高二下学期7月期末考试语文试题(解析版)
- 北师大版小学数学四年级下册期末试卷含参考答案
- 北师大版小学科学五年级上册期末试卷含参考答案
- 苏荷汤-验方新编卷十五-方剂加减变化汇总
- 《西雅图夜未眠》电影中英语对白台词字幕
- 小学纪念九一八事变主持词
- 2021-2022学年四川省成都市高新区五年级下学期期末语文试卷
- 《文创产品设计》课程标准
- 湖北省普通高等学校招生考生体格检查表
- 第5课《水能溶解多少物质》教学设计(教科版小学三年级上册科学第一单元)
- 三年级班级工作计划第一学期5篇
- 报联商——有效沟通PPT通用课件
- YD∕T 5060-2019 通信设备安装抗震设计图集
- 患者隐私保护.(课堂PPT)
评论
0/150
提交评论