时钟
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_SYNCO
EPwm6Regs.TBCTL.bit.PHSEN = 0;//禁止从相位寄存器 加载
EPwm6Regs.TBCTL.bit.CTRMODE = 0;//向上计数模式
EPwm6Regs.TBCTL.bit.CLKDIV = 0;//分频1
EPwm6Regs.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;
}