DSP-F2812输入捕捉例程(共3页).doc
精选优质文档-倾情为你奉上/* 由于本开发板的DSP内核的电压为1.8V,故只能运行在最高位135MHZ的时钟频率下 将T1PWM_GPIOA6输出的PWM波与DSP的CAP1Q1_GPIOA8输入捕捉相接来测试输入捕捉功能 将输入捕捉到的定时器的计数值之差,也就是两个上升沿之间的时间通过8个发刚二极管显示出来。 注意:在开发板断电的情况下连接好两个引脚,然后再给开发板上电!*/#include"DSP28_Device.h"interrupt void cap1_isr(void);Uint16 *LED8 = (Uint16 *)0x4100;/这是DSP开发板上的CPLD控制发光二级管的地址Uint16 cap_value2=0;void main(void)InitSysCtrl();DINT;IER = 0x0000;IFR = 0x0000;InitPieCtrl();/*初始化PIE中断矢量表*/InitPieVectTable();EALLOW;PieVectTable.CAPINT1 = &cap1_isr;EDIS;/*通用定时器1设置*/EvaRegs.GPTCONA.bit.T1PIN = 1;/*effective is low*/EvaRegs.GPTCONA.bit.TCOMPOE = 1;/*open compare output*/EvaRegs.T1CON.bit.FREE = 1;/*freely run*/EvaRegs.T1CON.bit.TMODE = 2;EvaRegs.T1CON.bit.TPS = 2;/*prescaler is 4,HSPCLK = 60MHZ,pwm frequency = 150KHZ*/EvaRegs.T1PR = 99;EvaRegs.T1CMPR = 50;EvaRegs.T1CON.bit.TENABLE = 1;EvaRegs.T1CON.bit.TCLD10 = 0;EvaRegs.T1CON.bit.TECMPR = 1;/*通用定时器2设置*/EvaRegs.T2PR = 0xffff;EvaRegs.T2CON.bit.FREE = 1;/*freely run*/EvaRegs.T2CON.bit.TMODE = 2;EvaRegs.T2CON.bit.TPS = 1;/*prescaler is 2,HSPCLK = 60MHZ,frequency is 30MHZ*/EvaRegs.T2CON.bit.TENABLE = 1;EvaRegs.T2CON.bit.TCLD10 = 3;/*保留*/EvaRegs.T2CON.bit.TECMPR = 1;/*捕获单元设置*/EvaRegs.CAPFIFO.bit.CAP1FIFO = 0;EvaRegs.CAPCON.bit.CAP12TSEL = 0; /*choose the general timer2*/EvaRegs.CAPCON.bit.CAP1EDGE = 2;/*detect the falling edge*/EvaRegs.CAPCON.bit.CAPRES = 1;EvaRegs.CAPCON.bit.CAPQEPN = 1;/*enable capture uint 1 and 2*/EvaRegs.EVAIFRC.bit.CAP1INT = 1;/*clear the flag*/EvaRegs.EVAIMRC.bit.CAP1INT = 1;/*enable the interrupt*/EALLOW;GpioMuxRegs.GPAMUX.bit.T1PWM_GPIOA6 = 1;GpioMuxRegs.GPAMUX.bit.CAP1Q1_GPIOA8 = 1;/*second function*/EDIS;PieCtrl.PIEIER3.bit.INTx5 = 1;IER |= M_INT3;EINT;ERTM;*LED8 = 0xff;for(;)interrupt void cap1_isr(void)EvaRegs.EVAIFRC.bit.CAP1INT = 1;EvaRegs.T1CNT = 0;cap_value0 = EvaRegs.CAP1FIFO;cap_value1 = EvaRegs.CAP1FIFO;*LED8 = (char)( cap_value1 - cap_value0 ) ;cap_value0 = 0;cap_value1 = 0;asm(" RPT #1 | NOP");PieCtrl.PIEACK.all = PIEACK_GROUP3;专心-专注-专业