DSP

DSP 脉冲检测CAP

2019-07-13 10:04发布

  • GPIO初始化
  • CAP初始化
  • 中断设置
特点:
  • 150MHZ下,32位时基的分辨率是6.67ns
  • 4级深度
  • 可配置为单通道的APWM模式
/* * This Project is just testing Cap */ #include "DSP2833x_Project.h" Uint32 t1,t2,t3,t4,T1,T2; void InitCap(void); interrupt void CapInt(void); int main(void) { InitSysCtrl(); InitXintf16Gpio(); DINT; InitPieCtrl(); IFR = 0x0000; IER = 0x0000; InitPieVectTable(); InitCap(); //interrupt EALLOW; PieVectTable.ECAP1_INT = &CapInt; EDIS; IER |= M_INT4; PieCtrlRegs.PIEIER4.bit.INTx1 = 1; DINT; ERTM; for(;;); return 0; } void InitCap(void){ EALLOW; GpioCtrlRegs.GPAPUD.bit.GPIO24 = 0; GpioCtrlRegs.GPAQSEL2.bit.GPIO24 = 0; GpioCtrlRegs.GPAMUX2.bit.GPIO24 = 1; ECap1Regs.ECCTL1.all = 0x0155; /*ECap1Regs.ECCTL1.bit.CAP1POL = 0; ECap1Regs.ECCTL1.bit.CAP2POL = 1; ECap1Regs.ECCTL1.bit.CAP3POL = 0; ECap1Regs.ECCTL1.bit.CAP4POL = 1; ECap1Regs.ECCTL1.bit.CTRRST1 = 0; ECap1Regs.ECCTL1.bit.CTRRST2 = 0; ECap1Regs.ECCTL1.bit.CTRRST3 = 0; ECap1Regs.ECCTL1.bit.CTRRST4 = 0; ECap1Regs.ECCTL1.bit.CAPLDEN = 1; ECap1Regs.ECCTL1.bit.PRESCALE = 0;*/ ECap1Regs.ECCTL2.all = 0x80; /*ECap1Regs.ECCTL2.bit.CAP_APWM = 0; ECap1Regs.ECCTL2.bit.SYNCO_SEL = 2; ECap1Regs.ECCTL2.bit.SYNCI_EN = 0; ECap1Regs.ECCTL2.bit.CONT_ONESHT = 0;*/ ECap1Regs.ECEINT.all = 8; ECap1Regs.ECCLR.all = 0xFFFF; ECap1Regs.ECCTL2.bit.TSCTRSTOP = 0; EDIS; } interrupt void CapInt(void){ PieCtrlRegs.PIEACK.all = PIEACK_GROUP4; ECap1Regs.ECCLR.all = 0xFFFF; t1 = ECap1Regs.CAP1; t2 = ECap1Regs.CAP2; t3 = ECap1Regs.CAP3; t4 = ECap1Regs.CAP4; T1 = t2 - t1; T2 = t3 - t1; }