xi0 简述
pwm作为DSP主要外设,对于新接触Ti DSP的新手来说,学习门槛还是高的,但是其配置方法基本是C2000的特点,学会一个基本可以很快上手其他C2000芯片。下面就上相关驱动程序,再对其设置寄存器的关键点进行简述。
1 例程代码
下面的代码是基于C2000 ware里的 "driverlib.h" 库文件,这是个人比较推荐的配置方式,再TI 不同芯片 程序移植时,基本可以做到通用。
#define _SET_PWM_PIN(PIN,PWM) GPIO_setPadConfig(PIN, GPIO_PIN_TYPE_STD);GPIO_setPinConfig(GPIO_##PIN##_EPWM##PWM);
#define _EPWM_SET(NUM,CPUNUM) DevCfgRegs.CPUSEL0.bit.EPWM##NUM = CPUNUM
void PwmUserDef_Init(Uint16 PwmDutyC1,Uint16 DeadBandC1, Uint16 PwmDutyC2, Uint16 DeadBandC2)
{
SysCtl_setEPWMClockDivider(SYSCTL_EPWMCLK_DIV_1);
#ifdef CPU1
EALLOW;
_EPWM_SET(1,CPU2_PWM);
_EPWM_SET(2,CPU2_PWM);
_EPWM_SET(3,CPU2_PWM);
_EPWM_SET(4,CPU1_PWM);
_EPWM_SET(5,CPU1_PWM);
_EPWM_SET(6,CPU1_PWM);
_EPWM_SET(7,CPU1_PWM);
_EPWM_SET(8,CPU1_PWM);
_EPWM_SET(9,CPU1_PWM);
_EPWM_SET(10,CPU1_PWM);
_EPWM_SET(11,CPU1_PWM);
_EPWM_SET(12,CPU1_PWM);
EDIS;
SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
InitEpwmx(&EPwm4Regs,PwmDutyC1,DeadBandC1);
InitEpwmx(&EPwm5Regs,PwmDutyC1,DeadBandC1);
InitEpwmx(&EPwm6Regs,PwmDutyC1,DeadBandC1);
SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
#endif
#ifdef CPU2
SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
InitEpwm1(&EPwm1Regs,PwmDutyC2,DeadBandC2);
InitEpwmx(&EPwm2Regs,PwmDutyC2,DeadBandC2);
InitEpwmx(&EPwm3Regs,PwmDutyC2,DeadBandC2);
SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
#endif
}
#include "F2837xD_device.h"
#include "F2837xD_EPwm_defines.h"
#include "driverlib.h"
void initEPWM(uint32_t base,uint32_t EPWM_TIMER_TBPRD,uint32_t EPWM_CMPA,uint32_t DEAD_BANG)
{
//
// Set-up TBCLK
//
EPWM_setTimeBasePeriod(base, EPWM_TIMER_TBPRD);
EPWM_setPhaseShift(base, 0U);
EPWM_setTimeBaseCounter(base, 0U);
//
// Set Compare values
//
EPWM_setCounterCompareValue(base,
EPWM_COUNTER_COMPARE_A,
EPWM_CMPA);
//
// Set up counter mode
//
EPWM_setTimeBaseCounterMode(base,