本帖最后由 Imbalyc 于 2023-7-17 15:28 编辑
我是初学DSP,在网上看的普中的视频,按照普中的官方例程改的程序,能正常烧录。目的:控制epwm1(对应GPIO0和GPIO1)、epwm6(对应GPIO10和GPIO11)发出四路互补带死区PWM信号
现象:只有GPIO0和GPIO1两引脚上能采到互补带死区PWM信号,剩下两路没有采到信号。后来试过屏蔽GPIO0和GPIO1的程序,只使能GPIO10和GPIO11,还是只能在GPIO0和GPIO1两引脚上采到互补带死区PWM信号。
想请教一下各位大佬,根据我的描述或看一下我改的程序,给点意见,这问题困扰我很久了,谢谢!
###NextPage[title=epwm.c]###/*
* epwm.c
#include "epwm.h"
#include "leds.h"
void EPWM1_Init(Uint16 tbprd)
{
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // Disable TBCLK within the ePWM
SysCtrlRegs.PCLKCR1.bit.EPWM1ENCLK = 1; // ePWM1
EDIS;
InitEPwm1Gpio();
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Stop all the TB clocks
EDIS;
// Setup Sync
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE; // Pass through
// Allow each timer to be sync'ed
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;
EPwm1Regs.TBPHS.half.TBPHS = 0;
EPwm1Regs.TBCTR = 0x0000; // Clear counter
EPwm1Regs.TBPRD = tbprd;
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm1Regs.TBCTL.bit.HSPCLKDIV=TB_DIV1;
EPwm1Regs.TBCTL.bit.CLKDIV=TB_DIV1;
// Setup shadow register load on ZERO
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
// Set Compare values
EPwm1Regs.CMPA.half.CMPA = 0; // Set compare A value
EPwm1Regs.CMPB = 0; // Set Compare B value
// Set actions
EPwm1Regs.AQCTLA.bit.ZRO = AQ_CLEAR; // Set PWM1A on Zero
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; // Clear PWM1A on event A, up count
EPwm1Regs.AQCTLB.bit.ZRO = AQ_SET; // Set PWM1B on Zero
EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR; // Clear PWM1B on event B, up count
EPwm1Regs.DBCTL.bit.IN_MODE =2; //EPwm1A为上升沿延时,1B为下降沿延时
EPwm1Regs.DBCTL.bit.POLSEL =1; //1A翻转
EPwm1Regs.DBCTL.bit.OUT_MODE =3; //使能上升沿和下降沿延时
EPwm1Regs.DBRED =5000; //上升沿死区时间5us
EPwm1Regs.DBFED =5000; //下降沿死区时间5us
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; // Select INT on Zero event
EPwm1Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm1Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on 1st event
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // Start all the timers synced
EDIS;
}
void EPwm1A_SetCompare(Uint16 val)
{
EPwm1Regs.CMPA.half.CMPA = val; //设置占空比
}
void EPwm1B_SetCompare(Uint16 val)
{
EPwm1Regs.CMPB = val; //设置占空比
}
void EPWM6_Init(Uint16 tbprd)
{
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Disable TBCLK within the ePWM
SysCtrlRegs.PCLKCR1.bit.EPWM6ENCLK = 1; // ePWM6
EDIS;
InitEPwm6Gpio();
// Setup Sync
EPwm6Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE; // Pass through
// Allow each timer to be sync'ed
EPwm6Regs.TBCTL.bit.PHSEN = TB_DISABLE;
EPwm6Regs.TBPHS.half.TBPHS = 0;
EPwm6Regs.TBCTR = 0x0000; // Clear counter
EPwm6Regs.TBPRD = tbprd;
EPwm6Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm6Regs.TBCTL.bit.HSPCLKDIV=TB_DIV1;
EPwm6Regs.TBCTL.bit.CLKDIV=TB_DIV1;
// Setup shadow register load on ZERO
EPwm6Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm6Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm6Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm6Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
// Set Compare values
EPwm6Regs.CMPA.half.CMPA = 0; // Set compare A value
EPwm6Regs.CMPB = 0; // Set Compare B value
// Set actions
EPwm6Regs.AQCTLA.bit.ZRO = AQ_CLEAR; // Set PWM1A on Zero
EPwm6Regs.AQCTLA.bit.CAU = AQ_SET; // Clear PWM1A on event A, up count
EPwm6Regs.AQCTLB.bit.ZRO = AQ_CLEAR; // Set PWM1B on Zero
EPwm6Regs.AQCTLB.bit.CBU = AQ_SET; // Clear PWM1B on event B, up count
EPwm6Regs.DBCTL.bit.IN_MODE =2; //EPwm1A为上升沿延时,1B为下降沿延时
EPwm6Regs.DBCTL.bit.POLSEL =1; //1A翻转
EPwm6Regs.DBCTL.bit.OUT_MODE =3; //使能上升沿和下降沿延时
EPwm6Regs.DBRED =5000; //上升沿死区时间5us
EPwm6Regs.DBFED =5000; //下降沿死区时间5us
EPwm6Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO; // Select INT on Zero event
EPwm6Regs.ETSEL.bit.INTEN = 1; // Enable INT
EPwm6Regs.ETPS.bit.INTPRD = ET_1ST; // Generate INT on 1st event
EALLOW;
SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // Start all the timers synced
EDIS;
}
void EPwm6A_SetCompare(Uint16 val)
{
EPwm6Regs.CMPA.half.CMPA = val; //设置占空比
}
void EPwm6B_SetCompare(Uint16 val)
{
EPwm6Regs.CMPB = val; //设置占空比
}
###NextPage[title=leds.c]###
#include "leds.h"
void LED_Init(void)
{
EALLOW;
SysCtrlRegs.PCLKCR3.bit.GPIOINENCLK = 1;// 开启GPIO时钟
GpioCtrlRegs.GPAMUX1.bit.GPIO0=0;
GpioCtrlRegs.GPADIR.bit.GPIO0=1;
GpioCtrlRegs.GPAPUD.bit.GPIO0=0;
GpioCtrlRegs.GPAMUX1.bit.GPIO1=0;
GpioCtrlRegs.GPADIR.bit.GPIO1=1;
GpioCtrlRegs.GPAPUD.bit.GPIO1=0;
GpioCtrlRegs.GPAMUX1.bit.GPIO10=0;
GpioCtrlRegs.GPADIR.bit.GPIO10=1;
GpioCtrlRegs.GPAPUD.bit.GPIO10=0;
GpioCtrlRegs.GPAMUX1.bit.GPIO11=0;
GpioCtrlRegs.GPADIR.bit.GPIO11=1;
GpioCtrlRegs.GPAPUD.bit.GPIO11=0;
GpioDataRegs.GPASET.bit.GPIO10=1;
GpioDataRegs.GPASET.bit.GPIO11=1;
GpioDataRegs.GPASET.bit.GPIO0=1;
GpioDataRegs.GPASET.bit.GPIO1=1;
EDIS;
}
###NextPage[title=main.c]###
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#include "leds.h"
#include "time.h"
#include "epwm.h"
void main()
{
InitSysCtrl();
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
LED_Init();
EPWM6_Init(150);
EPWM1_Init(150);
while(1)
{
EPwm1A_SetCompare(75);
EPwm1B_SetCompare(75);
EPwm6A_SetCompare(75);
EPwm6B_SetCompare(75);
DELAY_US(10*1000);
}
}
|