DSP学习笔记
EPWM
结构框图
代码分析
代码配置
//1.关时基时钟(配置前一定要这么做)
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
//2.初始化GPIO引脚(选择EPWM的输出IO口)
InitEPwm2Gpio();
//3.设置同步输入脉冲触发条件(为了做后续的移相pwm控制)
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; //在Epwm2的计数器到0的时候就发一次时基同步脉冲
//4.初始化相位寄存器
EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE;//Epwm2相位寄存器失能
EPwm2Regs.TBPHS.half.TBPHS = 0;
EPwm2Regs.TBCTR = 0x0000; // Clear counter
EPwm2Regs.TBPRD = tbprd;
//5.选择计数模式(此处选择向上计数模式)
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up向上计数模式
//6.设定时基时钟
EPwm2Regs.TBCTL.bit.HSPCLKDIV=TB_DIV1;//0x00
EPwm2Regs.TBCTL.bit.CLKDIV=TB_DIV2;//0x01
// 7.设置寄存器操作模式(缓冲模式)
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
//8.设置比较点(A和B都是在零点进行比较)
EPwm2Regs.CMPA.half.CMPA = 0; // Set compare A value
EPwm2Regs.CMPB = 0; // Set Compare B value
//9.动作模块使用
EPwm2Regs.AQCTLA.bit.ZRO = AQ_CLEAR; // Set PWM1A on Zero
EPwm2Regs.AQCTLA.bit.CAU = AQ_SET; // Clear PWM1A on event A, up count
EPwm2Regs.AQCTLB.bit.ZRO = AQ_SET; // Set PWM1B on Zero
EPwm2Regs.AQCTLB.bit.CBU = AQ_CLEAR; // Clear PWM1B on event B, up count
//10.最后不要忘记,把时钟再打开!!!
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // Start all the timers synced
标签:EPwm2Regs,CC,笔记,学习,Set,TBCTL,DSP,bit,TB
From: https://www.cnblogs.com/filosefer/p/18162459