这个是我在资源分享里下的,然后我输入了三路霍尔信号(方波的)到捕获,但是观察到的六路PWM波信号都是高电平,根本就不会变化,不知道为什么,hw显示的数据是会变的,cap_number也是会增加的,不知道是什么原因,求大神帮忙
#include "DSP281x_Device.h" // DSP281x Headerfile Include File
#include "DSP281x_Examples.h" // DSP281x Examples Include File
#include "f2812a.h"
#include "stdio.h"
interrupt void cap_isr(void);
interrupt void T1_isr(void);
interrupt void T2_isr(void);
// 定义指示灯寄存器地址和寄存器类型
#define LBDS (*((unsigned int *)0xc0000))
//定义拨码开关寄存器地址和寄存器类型
#define DIPS (*((unsigned int *)0xc0001))
void zx(void);
void fx(void);
Uint16 hw=0;
Uint16 i=0;
Uint32 interrupt_cap_number=0;
Uint32 interrupt_T2_number=0;
main()
{
InitSysCtrl();
// 初始化DSP运行时钟
DINT;
/*初始化PIE*/
InitPieCtrl();
IER=0x0000;
IFR=0x0000; //清中断
/*初始化PIE中断矢量表*/
InitPieVectTable();
EALLOW;
GpioMuxRegs.GPAMUX.all=0x073F;//使能引脚作为第二功能 PWM1-6,CAP1-3;
// GpioMuxRegs.GPFMUX.all=0x0030;//使能GPIO为SCI功能;
EDIS;
EALLOW;
PieVectTable.CAPINT1=&cap_isr;//指向中断服务寄存器捕捉1的地址
PieVectTable.CAPINT2=&cap_isr;
PieVectTable.CAPINT3=&cap_isr;
PieVectTable.T1UFINT=&T1_isr;
PieVectTable.T2PINT=&T2_isr;
EDIS;
EvaRegs.EVAIMRC.bit.CAP1INT=1; //使能外设级CAP中断;
EvaRegs.EVAIMRC.bit.CAP2INT=1;
EvaRegs.EVAIMRC.bit.CAP3INT=1;
PieCtrlRegs.PIEIER3.bit.INTx5=1; //使能PIE级CAP中断;
PieCtrlRegs.PIEIER3.bit.INTx6=1;
PieCtrlRegs.PIEIER3.bit.INTx7=1;
EvaRegs.EVAIMRA.bit.T1UFINT=1; //使能T1的下溢中断;
PieCtrlRegs.PIEIER2.bit.INTx6=0x0001; //在PIE中使能T1的下溢中断;
EvaRegs.EVAIMRB.bit.T2PINT=1; //使能T2的周期中断;
PieCtrlRegs.PIEIER3.bit.INTx1=1; //在PIE中使能T1的周期中断;
EvaRegs.EVAIFRC.bit.CAP1INT=1;
EvaRegs.EVAIFRC.bit.CAP2INT=1;
EvaRegs.EVAIFRC.bit.CAP3INT=1;
EvaRegs.EVAIFRA.bit.T1UFINT=1;
EvaRegs.EVAIFRB.bit.T2PINT=1;
PieCtrlRegs.PIEACK.all=PIEACK_GROUP3;
PieCtrlRegs.PIEACK.all=PIEACK_GROUP2;
IER|=M_INT3;
IER|=M_INT2;
EINT;
EvaRegs.T1CNT=0x0000; //T1定时器初值;
EvaRegs.T1PR=0x03A9;
EvaRegs.T1CON.all=0x0A46; //连续增/减,时钟=75M/4,启动定时器1;
EvaRegs.T2CNT=0x0000; //T2定时器初值;
EvaRegs.T2PR=0xFFFF;
EvaRegs.T2CON.all=0x1706;//连续増,时钟75M 128分频,不使能定时器;
EvaRegs.CMPR1=0x0200;
EvaRegs.CMPR2=0x0200;
EvaRegs.CMPR3=0x0200;
EvaRegs.COMCONA.all=0xA6E0;//使能全比较单元;
EvaRegs.CAPFIFOA.bit.CAP1FIFO=0;//初始化捕获FIFO状态寄存器,相应位清零;
EvaRegs.CAPFIFOA.bit.CAP2FIFO=0;
EvaRegs.CAPFIFOA.bit.CAP2FIFO=0;
EvaRegs.CAPCONA.all=0x30FC;//使能CAP单元中的各个功能,选用通用定时器2;
EvaRegs.DBTCONA.all=0x04F4;//死区设置;
hw=GpioDataRegs.GPADAT.all&0x0700;
if(i==1)zx(); //正转
else fx(); //反转
while ( 1 )
{
}
}
interrupt void T1_isr(void)
{
PieCtrlRegs.PIEACK.bit.ACK2=PIEACK_GROUP2;
EvaRegs.CMPR1--;
EvaRegs.CMPR2--;
EvaRegs.CMPR3--;
if(EvaRegs.CMPR1>150&&EvaRegs.CMPR2>150&&EvaRegs.CMPR3>150)
{
EvaRegs.EVAIFRA.bit.T1UFINT=1;
}
else
{ EvaRegs.CMPR1=150;
EvaRegs.CMPR2=150;
EvaRegs.CMPR3=150;
EvaRegs.T2CON.bit.TENABLE=1;//在占空比稳定时启动T2,
interrupt_cap_number=0;//从此刻记录捕获次数;
}
}
interrupt void T2_isr(void)
{
interrupt_T2_number++;
EvaRegs.EVAIFRB.bit.T2PINT=1;
PieCtrlRegs.PIEACK.bit.ACK3=1;
}
interrupt void cap_isr(void)
{
EvaRegs.EVAIFRC.bit.CAP1INT=1;
EvaRegs.EVAIFRC.bit.CAP2INT=1;
EvaRegs.EVAIFRC.bit.CAP3INT=1;
hw=GpioDataRegs.GPADAT.all&0x0700;
EvaRegs.T2CON.bit.TENABLE=1;//启动T2,
if(i==1)zx(); //正转
else fx(); //反转*/
PieCtrlRegs.PIEACK.bit.ACK3=1;//使能下一次中断;
interrupt_cap_number++;
}
void zx(void)
{
if(hw==0x0500) //当前为101(2,5通);
EvaRegs.ACTRA.all=0x0082; //BNA
if(hw==0x0100) //当前为100(4,5通)
EvaRegs.ACTRA.all=0x0280; //BNC
if(hw==0x0300) //当前为110(4,1通)
EvaRegs.ACTRA.all=0x0208; //ANC
if(hw==0x0200) //当前为010(6,1通)
EvaRegs.ACTRA.all=0x0028; //ANB
if(hw==0x0600) //当前为011(6,3通)
EvaRegs.ACTRA.all=0x0820; //CNB
if(hw==0x0400) //当前为001(2,3通)
EvaRegs.ACTRA.all=0x0802; //CNA
}
void fx(void)
{
if(hw==0x0500) //当前为101(2,5通);
EvaRegs.ACTRA.all=0x0028; //ANB;
if(hw==0x0100) //当前为100(4,5通)
EvaRegs.ACTRA.all=0x0820; //CNB
if(hw==0x0300) //当前为110(4,1通)
EvaRegs.ACTRA.all=0x0802; //CNA
if(hw==0x0200) //当前为010(6,1通)
EvaRegs.ACTRA.all=0x0082; //BNA
if(hw==0x0600) //当前为011(6,3通)
EvaRegs.ACTRA.all=0x0280; //BNC
if(hw==0x0400) //当前为001(2,3通)
EvaRegs.ACTRA.all=0x0208; //ANC
}
|