基于DSP28035的SPWM生成程序
更新时间:2023-11-12 12:00:01 阅读量: 教育文库 文档下载
- DSP28035数据手册推荐度:
- 相关推荐
#include \#include \//#include \
#define PWM1_INT_ENABLE 1 #define PWM2_INT_ENABLE 1 #define PWM3_INT_ENABLE 1 #define PWM4_INT_ENABLE 1 void InitEPwm1Example(void); void InitEPwm2Example(void); void InitEPwm3Example(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.1415926 float32 M=0.8; float32 fz=20000; float32 fr=50; void main(void) {
InitSysCtrl(); InitEPwm1Gpio(); // InitEPwm2Gpio(); // InitEPwm3Gpio(); DINT; InitPieCtrl(); IER = 0x0000; IFR = 0x0000;
InitPieVectTable();
EALLOW; // This is needed to write to EALLOW protected registers PieVectTable.EPWM1_INT = &epwm1_timer_isr; // PieVectTable.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 = 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() {
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO;//zhuyi EPwm1Regs.TBPRD = 1500; //载波周期=2*1500TBCLK EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0 EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW; EPwm1Regs.TBCTR = 0x0000;
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up down EPwm1Regs.TBCTL.bit.PHSEN = 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_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
EPwm1Regs.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)); 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*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.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3 PieCtrlRegs.PIEACK.all = PIEACK_GROUP3; }
#include \\\Include File
#include \\\DSP280x Examples Include File
void InitePWM(void) {
EALLOW;
EPwm1Regs.TBPRD = 600; // Period = 601 TBCLK counts EPwm1Regs.CMPA = 350; // Compare A = 350 TBCLK counts EPwm1Regs.CMPB = 200; // Compare B = 200 TBCLK counts EPwm1Regs.TBPHS = 0; // Set Phase register to zero EPwm1Regs.TBCTR = 0; // clear TB counter EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Phase loading disabled
EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // TBCLK = SYSCLK EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1; EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // load on CTR = Zero
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO; // load on CTR = Zero
EPwm1Regs.AQCTLA.bit.PRD = AQ_CLEAR; EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; EPwm1Regs.AQCTLB.bit.PRD = AQ_CLEAR;
正在阅读:
基于DSP28035的SPWM生成程序11-12
读《驾驶课》有感500字06-27
发酵罐操作规程11-06
中国金融发展与经济增长03-05
小学体育与健康浙教版水平三(小学5、6年级) 排球《正面下手发球技术与接发球》优质教师资格证面试试讲教案01-18
公园一角作文400字07-12
罗马法的起源与发展02-13
论我国法律关系的分类06-05
TOM网址导航 lnk05-08
36 - 构造与论证(二) - 图文04-16
- exercise2
- 铅锌矿详查地质设计 - 图文
- 厨余垃圾、餐厨垃圾堆肥系统设计方案
- 陈明珠开题报告
- 化工原理精选例题
- 政府形象宣传册营销案例
- 小学一至三年级语文阅读专项练习题
- 2014.民诉 期末考试 复习题
- 巅峰智业 - 做好顶层设计对建设城市的重要意义
- (三起)冀教版三年级英语上册Unit4 Lesson24练习题及答案
- 2017年实心轮胎现状及发展趋势分析(目录)
- 基于GIS的农用地定级技术研究定稿
- 2017-2022年中国医疗保健市场调查与市场前景预测报告(目录) - 图文
- 作业
- OFDM技术仿真(MATLAB代码) - 图文
- Android工程师笔试题及答案
- 生命密码联合密码
- 空间地上权若干法律问题探究
- 江苏学业水平测试《机械基础》模拟试题
- 选课走班实施方案
- DSP28035
- 生成
- 基于
- 程序
- SPWM
- 华南理工大学硕士学位论文开题报告(适用于全日制硕士专业学位研究生-2014年10月版)
- 工作座椅一般人类工效学要求
- 高级摄影师考试题库10套标注答案版
- 20160321务川县镇南完小教育脱贫攻坚专题会简报 - 图文
- 高鸿宾《有机化学》(第四版)复习提纲-48课时2013
- 部编版语文一年级下册句子专项训练题
- 王安石变法 导学案 - 图文
- 02开题报告2015版 - 图文
- Z5140A、Z5150A使用说明书 - 图文
- 公路水运继续教育弯沉检测技术回顾与展望
- 方太的企业文化
- 格兰杰因果检验(正式版)
- 小学多边形的面积知识点归纳
- 2019届同心圆梦专题卷(物理)专题06(txym01)
- 2019年考研英语二考前模拟题
- 龙华新区锦华实验学校八年级英语下册Unit3主题阅读牛津深圳版
- 《幼儿的气质及其差异表现》教学设计方案
- 电阻电容电感测试仪2010山东
- 电子电工复习题精华版
- 当前政府投资项目管理中存在的问题及对策