本文主要是介绍EPWM初学笔记,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
时钟
PCLKCR0
PCLKCR1
EPWM总体预览
三部分就可以简单的使用EPWM
时基模块,比较模块,动作限定模块
时基模块
TBCTL时基控制寄存器
TBCTR计数寄存器
TBPHS相位寄存器
TBPRD周期寄存器
比较模块
CMPCTL比较控制寄存器
影子模式,加载模式
CMPA比较寄存器A
动作限定模块
动作限定A和B控制寄存器都是一样
程序
/** epwm.c** Created on: 2023年12月5日* Author: Administrator*/
#include"epwm.h"
void epwm_init(Uint16 zhouqi)
{EALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;SysCtrlRegs.PCLKCR1.bit.EPWM6ENCLK = 1;EDIS;InitEPwm6Gpio();//时基控制寄存器配置EPwm6Regs.TBCTL.bit.SYNCOSEL = 0x03;//禁止EPWM_SYNCOEPwm6Regs.TBCTL.bit.PHSEN = 0;//禁止从相位寄存器 加载EPwm6Regs.TBCTL.bit.CTRMODE = 0;//向上计数模式EPwm6Regs.TBCTL.bit.CLKDIV = 0;//分频1EPwm6Regs.TBCTL.bit.HSPCLKDIV = 0;分频2//相位寄存器赋值EPwm6Regs.TBPHS.half.TBPHS = 0;EPwm6Regs.TBCTR = 0;//计数EPwm6Regs.TBPRD = zhouqi;//周期//配置比较控制寄存器EPwm6Regs.CMPCTL.bit.SHDWAMODE = 0;EPwm6Regs.CMPCTL.bit.SHDWBMODE = 0;EPwm6Regs.CMPCTL.bit.LOADAMODE = 0;EPwm6Regs.CMPCTL.bit.LOADBMODE = 0;EPwm6Regs.CMPA.half.CMPA = 0;//比较值EPwm6Regs.CMPB = 0;EPwm6Regs.AQCTLA.bit.CAU = 2;//输出高EPwm6Regs.AQCTLA.bit.ZRO = 1;//输出低EPwm6Regs.AQCTLB.bit.CAU = 2;//输出高EPwm6Regs.AQCTLB.bit.ZRO = 1;//输出低EPwm6Regs.ETSEL.bit.INTEN = 1;//中断使能EPwm6Regs.ETSEL.bit.INTSEL = 1;//计数器等于0时候产生EALLOW;SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;//同步EDIS;
}void EPWM6_set_compara(Uint16 zhouqi,Uint16 zhanbi)
{EPwm6Regs.TBPRD = zhouqi;//周期EPwm6Regs.CMPA.half.CMPA = zhanbi;EPwm6Regs.CMPB = zhanbi;
}
这篇关于EPWM初学笔记的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!